You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

471 lines
19 KiB
C#

using CommonFunc;
using CommonFunc.Tools;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Xceed.Wpf.DataGrid;
using XGL.Data;
using XGL.Data.DBService;
using XGL.Dats.DBServiceFinishProd;
using XGL.Models.Model.OrderPrepare;
namespace XGLFinishPro.Views
{
/// <summary>
/// CheckUserWin.xaml 的交互逻辑
/// </summary>
public partial class ExecReportWorkWin : Window
{
FinishProdDBService userDbWareHouse = new FinishProdDBService();
FormingMachineService formingMachineService = new FormingMachineService();
public bool loginFlag;
public string _workTime = "";
public string _useMan = "";
public string _costCenter = "";
public string _workQuntity = "";
2 years ago
public string _orderQuntity = "";
public string _workOrdercode = "";
public string _workOrderId = "";
public string batchCode = "";
public bool? _isEndReport = false;
public string _deviceCode = "";
public string _siteCode = "";
DataRowView selectedRow = null;
public ExecReportWorkWin()
{
InitializeComponent();
}
public ExecReportWorkWin(string workOrder, string quantity,string workOrdercode, string batch_code, string siteCode)
{
InitializeComponent();
this._workOrdercode = workOrdercode;
this.lbCurrOrderNo.Content = workOrder;
this.txtQuantity.Text = quantity;
this.comboBoxBatch.Text = batch_code;
_siteCode = siteCode;
}
public ExecReportWorkWin(DataRowView _selectedRow,string deviceCode, string siteCode)
{
InitializeComponent();
2 years ago
//if (_selectedRow["parent_order"].ToString() == "0")
//{
// this.txtUserCount.Text = "0";
// this.txtUserCount.IsEnabled = false;
// this.txtWorkTime.Text = "0";
// this.txtWorkTime.IsEnabled = false;
//}
//else
//{
// this.txtUserCount.IsEnabled = true;
// this.txtWorkTime.IsEnabled = true;
//}
selectedRow = _selectedRow;
_deviceCode = deviceCode;
this._workOrdercode = selectedRow["workorder_code"].ToString();
this.lbCurrOrderNo.Content = selectedRow["workorder_code"].ToString();
this._workOrderId = selectedRow["workorder_id"].ToString();
this.txtQuantity.Text = selectedRow["quantity_split"].ToString();
2 years ago
_orderQuntity = selectedRow["quantity_split"].ToString();
this.comboBoxBatch.Text = selectedRow["batch_code"].ToString();
_siteCode = siteCode;
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
2 years ago
{
this.DialogResult = false;
this.Close();
}
private async void btnOK_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(this.txtQuantity.Text))
{
this.tbMsg.Content = "报工数量不能为空";
this.txtQuantity.Focus();
return;
}
if (string.IsNullOrEmpty(this.txtWorkTime.Text))
{
this.tbMsg.Content = "工时数量不能为空";
this.txtWorkTime.Focus();
return;
}
if (string.IsNullOrEmpty(this.txtUserCount.Text))
{
this.tbMsg.Content = "人数数量不能为空";
this.txtUserCount.Focus();
return;
}
if (string.IsNullOrEmpty(this.comboBoxCostCenter.SelectedValue.ToString()))
{
this.tbMsg.Content = "成本中心不能为空";
this.comboBoxCostCenter.Focus();
return;
}
if (!Regex.IsMatch(this.txtQuantity.Text, @"^\d+(\.\d+)?$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "报工数量非法字符!";
this.txtQuantity.Focus();
return;
}
if (!Regex.IsMatch(this.txtWorkTime.Text, @"^\d+(\.\d+)?$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "工时含有非法字符!";
this.txtWorkTime.Focus();
return;
}
if (!Regex.IsMatch(this.txtUserCount.Text, @"^\d+$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "人数含有非法字符!";
this.txtUserCount.Focus();
return;
}
_useMan = this.txtUserCount.Text;
_workTime = this.txtWorkTime.Text;
_costCenter = this.comboBoxCostCenter.SelectedValue.ToString();
_workQuntity = this.txtQuantity.Text;
batchCode = this.comboBoxBatch.Text;
_isEndReport = this.xuanze9.IsChecked;
if (string.IsNullOrEmpty(batchCode))
{
CustomMessageBoxResult result = CustomMessageBox.Show("您确定要按整单报工么?最终报工:" + (_isEndReport == true ? "是" : "否"), CustomMessageBoxButton.OKCancel, CustomMessageBoxIcon.Warning);
if (result == CustomMessageBoxResult.OK)
{
2 years ago
try
{
bool isSuccess = ReportWork();
if (isSuccess)
{
CustomMessageBox.Show("报工成功", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Success);
LogHelper.instance.log.Error("报工成功:" + selectedRow["workorder_code"]);
this.DialogResult = true;
}
else
{
CustomMessageBox.Show("报工失败", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
LogHelper.instance.log.Error("报工失败:" +selectedRow["workorder_code"]);
}
}
catch (Exception ex)
{
LogHelper.instance.log.Error("报工失败:" + ex.Message + selectedRow["workorder_code"]);
}
}
}
else
{
2 years ago
CustomMessageBoxResult result = CustomMessageBox.Show("您确定要按批次报工么?当前批次号:" + batchCode + " 最终报工:" + (_isEndReport == true ? "是" : "否"), CustomMessageBoxButton.OKCancel, CustomMessageBoxIcon.Warning);
if (result == CustomMessageBoxResult.OK)
{
2 years ago
try
{
bool isSuccess = ReportWork();
if (isSuccess)
{
CustomMessageBox.Show("报工成功", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Success);
this.DialogResult = true;
}
else
{
CustomMessageBox.Show("报工失败", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
}
}
catch (Exception ex)
{
LogHelper.instance.log.Error("报工失败:" + ex.Message);
}
}
}
2 years ago
}
private bool ReportWork()
{
//获取报工编码
string newReportCode = "";
DataTable dtNewReportCode = formingMachineService.GetReportCode();
if (dtNewReportCode == null || dtNewReportCode.Rows.Count == 0)
{
newReportCode = DateTime.Now.ToString("yyyyMMdd") + "0001";
}
else
{
if (string.IsNullOrEmpty(dtNewReportCode.Rows[0]["report_code"].ToString()))
{
newReportCode = DateTime.Now.ToString("yyyyMMdd") + "0001";
}
else
{
newReportCode = (Convert.ToInt64(dtNewReportCode.Rows[0]["report_code"].ToString()) + 1).ToString();
}
}
2 years ago
string isEndReport = _isEndReport == true ? "1" : "0";
2 years ago
//bool issucc = formingMachineService.ExecuteReportWork(selectedRow, _orderQuntity, _workQuntity, newReportCode, _workTime, _useMan, _costCenter, batchCode, isEndReport, _deviceCode);
List<string> reportWorkSqlList = formingMachineService.GetExecuteReportWorkSql(selectedRow, _orderQuntity, _workQuntity, newReportCode, _workTime, _useMan, _costCenter, batchCode, isEndReport, _deviceCode);
if (reportWorkSqlList.Count > 0)
{
2 years ago
//报工接口不用调了
////调用报工接口
//string apiUrl = formingMachineService.InterfaceUrl("reportWork");
//ReportWork reportWork = new ReportWork();
//reportWork.factoryCode = Utils.GetAppSetting("SiteCode");
//reportWork.reportCode = newReportCode;
//// 将要发送的数据序列化为JSON格式
//var jsonContent = JsonConvert.SerializeObject(reportWork);
//LogHelper.instance.log.Info("开始报工>>" + jsonContent);
//RestHelper restClient = new RestHelper();
////var response =;
//Rootobjectresu result = Utils.DeJson<Rootobjectresu>(await restClient.PostAsync(apiUrl, jsonContent));
//if (result.code == 200)
//{
return AddConsumInfo(reportWorkSqlList, newReportCode);
//}
//else
//{
// CustomMessageBox.Show("调用报工接口失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
//}
}
else
{
CustomMessageBox.Show("报工失败", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
2 years ago
return false;
}
}
2 years ago
private bool AddConsumInfo(List<string> reportWorkSqlList ,string newReportCode)
{
try
{
//报工消耗数量
// 获取第二列的值
int columnIndex = 1; // 列索引,这里假设为第一列
2 years ago
if (_isEndReport.Value == true)
{
2 years ago
foreach (var row in dgConsumeInfo.Items)
{
2 years ago
var selectedConsumeRow = (row as DataRowView);
var qty = selectedConsumeRow["qty"].ToString();
var remark = selectedConsumeRow["remark"].ToString();
//处理
formingMachineService.InsertConsumeInfo(selectedConsumeRow, newReportCode, _siteCode);
string insertConsumeSql = formingMachineService.GetInsertConsumeInfoSql(selectedConsumeRow, newReportCode, _siteCode);
reportWorkSqlList.Add(insertConsumeSql);
//// 获取 DataGridRow
//var dataGridRow = dgConsumeInfo.ItemContainerGenerator.ContainerFromItem(row) as DataGridRow;
//if (dataGridRow != null)
//{
// // 获取该行的单元格内容
// var cellQtyContent = dgConsumeInfo.Columns[columnIndex].GetCellContent(dataGridRow);
// var cellRemarkContent = dgConsumeInfo.Columns[columnIndex+1].GetCellContent(dataGridRow);
// var cellRecoilContent = dgConsumeInfo.Columns[columnIndex + 6].GetCellContent(dataGridRow);
// var cellparentOrderContent = dgConsumeInfo.Columns[columnIndex + 7].GetCellContent(dataGridRow);
// if (cellQtyContent != null)
// {
// // 获取单元格的值
// var qty = (cellQtyContent as TextBlock)?.Text;
// var remark = (cellRemarkContent as TextBlock)?.Text;
// var recoil = (cellRecoilContent as TextBlock)?.Text;
// var parentOrder = (cellparentOrderContent as TextBlock)?.Text;
// // 插入表
// if (qty != null)
// {
// // 处理 cellValue
// formingMachineService.InsertConsumeInfo(qty,remark,selectedRow, newReportCode, _siteCode, recoil,parentOrder);
// }
// else
// continue;
// }
//}
}
}
2 years ago
bool isReportSuccess = formingMachineService.GetExecuteReportWorkSql(reportWorkSqlList);
return isReportSuccess; ;
}
catch (Exception ex)
{
2 years ago
LogHelper.instance.log.Error("报工失败:生成消耗数据发生异常:" + ex.Message);
CustomMessageBox.Show("报工失败:生成消耗数据发生异常:"+ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
2 years ago
return false;
throw ex;
}
}
private void pw_PasswordChanged(object sender, RoutedEventArgs e)
{
tbMsg.Content = "";
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
InitComBoboxData();
piciInitComBoboxData();
InitConsumeData();
}
private void InitConsumeData()
{
DataTable dt = userDbWareHouse.GetCosumeData(_workOrdercode);
if (dt == null)
{
this.tbMsg.Content = "没有找到该工单的消耗信息";
//CustomMessageBox.Show("没有维护成本中心,请联系管理员!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
//绑定
dgConsumeInfo.ItemsSource = dt.DefaultView;
}
private void txtQuantity_TextChanged(object sender, TextChangedEventArgs e)
{
if (!Regex.IsMatch(this.txtQuantity.Text, @"^\d+(\.\d+)?$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "报工数量非法字符!";
this.txtQuantity.Focus();
return;
}
else
{
this.tbMsg.Content = "";
}
}
private void txtWorkTime_TextChanged(object sender, TextChangedEventArgs e)
{
if (!Regex.IsMatch(this.txtWorkTime.Text, @"^\d+(\.\d+)?$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "工时含有非法字符!";
this.txtWorkTime.Focus();
return;
}
else
{
this.tbMsg.Content = "";
}
}
private void txtUserCount_TextChanged(object sender, TextChangedEventArgs e)
{
if (!Regex.IsMatch(this.txtUserCount.Text, @"^\d+$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "人数含有非法字符!";
this.txtUserCount.Focus();
return;
}
else
{
this.tbMsg.Content = "";
}
}
private void InitComBoboxData()
{
DataTable dt = userDbWareHouse.GetCostCenter();
if (dt == null)
{
CustomMessageBox.Show("没有维护成本中心,请联系管理员!",CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
List<CostCenter> listCostCenter = Utils.ToDataList<CostCenter>(dt);
//comboDryRoomInfo.SelectedValuePath = "quipName";
//comboDryRoomInfo.DisplayMemberPath = "quipCode";
//comboDryRoomInfo.ItemsSource = listEquip;
//绑定
comboBoxCostCenter.ItemsSource = listCostCenter;
comboBoxCostCenter.SelectedValuePath = "factory_code";
comboBoxCostCenter.DisplayMemberPath = "factory_name";
comboBoxCostCenter.SelectedIndex = 0;
}
private void piciInitComBoboxData()
{
DataTable dt = userDbWareHouse.piciGetCostCenter(this._workOrderId);
if (dt == null)
{
CustomMessageBox.Show("没有找到批次号,请联系管理员!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
List<string> strings =new List<string>();
2 years ago
strings.Add("");
foreach (System.Data.DataRow row in dt.Rows)
{
strings.Add(row[0].ToString());
}
//List<CostCenter> listCostCenter = Utils.ToDataList<CostCenter>(dt);
//comboDryRoomInfo.SelectedValuePath = "quipName";
//comboDryRoomInfo.DisplayMemberPath = "quipCode";
//comboDryRoomInfo.ItemsSource = listEquip;
//绑定
comboBoxBatch.ItemsSource = strings;
}
private void comboBoxCostCenter_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void dgConsumeInfo_LoadingRow(object sender, DataGridRowEventArgs e)
{
e.Row.Header = (e.Row.GetIndex() + 1).ToString();
}
private void dgConsumeInfo_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
//dgConsumeInfo.CommitEdit();
}
2 years ago
private void xuanze9_Checked(object sender, RoutedEventArgs e)
{
_isEndReport = true;
}
}
public class CostCenter
{
public string factory_code { get; set; }
public string factory_name { get; set; }
}
}