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 { /// /// CheckUserWin.xaml 的交互逻辑 /// 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 = ""; 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(); 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(); this.comboBoxBatch.Text = selectedRow["batch_code"].ToString(); _siteCode = siteCode; } private void btnCancel_Click(object sender, RoutedEventArgs e) { 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) { this.DialogResult = true; } } else { CustomMessageBoxResult result = CustomMessageBox.Show("您确定要按批次报工么?当前批次号:"+ batchCode + " 最终报工:" + (_isEndReport == true ? "是" : "否"), CustomMessageBoxButton.OKCancel, CustomMessageBoxIcon.Warning); if (result == CustomMessageBoxResult.OK) { this.DialogResult = true; } } //获取报工编码 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(); } } string isEndReport = _isEndReport == true ? "1" : "0"; bool issucc = formingMachineService.ExecuteReportWork(selectedRow, _workQuntity, newReportCode, _workTime, _useMan, _costCenter, batchCode, isEndReport, _deviceCode); if (issucc) { //调用报工接口 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(await restClient.PostAsync(apiUrl, jsonContent)); if (result.code == 200) { AddConsumInfo(newReportCode); } else { CustomMessageBox.Show("调用报工接口失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); } } else { CustomMessageBox.Show("报工失败", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error); } } private void AddConsumInfo(string newReportCode) { try { //报工消耗数量 // 获取第二列的值 int columnIndex = 1; // 列索引,这里假设为第一列 foreach (var row in dgConsumeInfo.Items) { // 获取 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); if (cellQtyContent != null) { // 获取单元格的值 var qty = (cellQtyContent as TextBlock)?.Text; var remark = (cellRemarkContent as TextBlock)?.Text; // 插入表 if (qty != null) { // 处理 cellValue formingMachineService.InsertConsumeInfo(qty,remark,selectedRow, newReportCode, _siteCode); } else continue; } } } } catch (Exception ex) { CustomMessageBox.Show("报工失败:生成消耗数据发生异常:"+ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error); } } 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 listCostCenter = Utils.ToDataList(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 strings =new List(); strings.Add(""); foreach (System.Data.DataRow row in dt.Rows) { strings.Add(row[0].ToString()); } //List listCostCenter = Utils.ToDataList(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(); } } public class CostCenter { public string factory_code { get; set; } public string factory_name { get; set; } } }