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.

1165 lines
49 KiB
C#

using CommonFunc;
using CommonFunc.Tools;
using HandyControl.Tools.Extension;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Net.Http;
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;
using XGLFinishPro.Tools;
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 = "";
2 weeks ago
public string _lossCode = "";
DataRowView selectedRow = null;
2 years ago
int sortNo = 0; //定义一个整数,记录子集级数
Dictionary<int, TextBox> dynamicWorkTimeTextBoxes = new Dictionary<int, TextBox>();
Dictionary<int, TextBox> dynamicUserCountTextBoxes = new Dictionary<int, TextBox>();
Dictionary<int, string> dicWorkTime = new Dictionary<int, string>();
Dictionary<int, string> dicUserCount = new Dictionary<int, string>();
DataTable dtCosumeData = 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();
string orderNumber = selectedRow["workorder_code_sap"].ToString();
this.lbCurrOrderNo.Content = orderNumber.TrimStart('0');
this._workOrderId = selectedRow["workorder_id"].ToString();
2 years ago
object obi = selectedRow["batch_quantity"];
12 months ago
2 years ago
_orderQuntity = selectedRow["quantity_split"].ToString();
2 years ago
this.txtQuantity.Text = selectedRow["batch_quantity"].ToString();
this.comboBoxBatch.Text = selectedRow["batch_code"].ToString();
_siteCode = siteCode;
DataTable dtCount = userDbWareHouse.GetBatcxiaolvCount();
12 months ago
if (dtCount != null && dtCount.Rows.Count > 0)
{
if (dtCount != null && dtCount.Rows.Count > 0)
{
foreach (System.Data.DataRow row in dtCount.Rows)
{
xiaolv.Items.Add(row["dict_label"].ToString());
}
}
}
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
btnOK.IsEnabled = true;
this.DialogResult = false;
this.Close();
}
private async void btnOK_Click(object sender, RoutedEventArgs e)
{
try
{
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;
}
2 years ago
if (dynamicWorkTimeTextBoxes.Count > 0)
{
2 years ago
if (!CheckWorkTimeDynamicTextBox())
{
return;
}
}
2 years ago
if (dynamicWorkTimeTextBoxes.Count > 0)
{
2 years ago
if (!CheckUserCountDynamicTextBox())
{
return;
}
}
2 years ago
if (comboBoxBatch.Items.Count <= 2)//小于等于2的时候代表只有一个批次必须最终报工
{
if (_isEndReport == false)
{
2 years ago
CustomMessageBoxResult result = CustomMessageBox.Show("该批次为最后一个批次,如果需要最终报工请点【取消】按钮!!!", CustomMessageBoxButton.OKCancel, CustomMessageBoxIcon.Warning);
if (result == CustomMessageBoxResult.Cancel)
return;
//this.tbMsg.Content = "该工单只有一个批次,必须勾选最终报工!";
// return;
}
}
12 months ago
else
2 years ago
{
//判断是否为最后一个批次,如果是最后一个批次,则必须最终报工
DataTable dtCount = userDbWareHouse.GetBatchReportedCount(_workOrdercode);
if (dtCount != null && dtCount.Rows.Count > 0)
{
int reportedCount = Convert.ToInt32(dtCount.Rows[0][0].ToString());
//下拉框里有一个空行判断报工数量比批次号少1的时候证明是最后一次报工
if (reportedCount >= comboBoxBatch.Items.Count - 2)
{
//判断当前批次是不是已报工,针对一个批次多次报工实际不是最后一个批次的时候触发的提示,false 代表不是此批次最后一个批次
bool isLastBatch = userDbWareHouse.IsLastBatchReport(this.comboBoxBatch.Text);
if (_isEndReport == false && isLastBatch)
{
CustomMessageBoxResult result = CustomMessageBox.Show("该批次为最后一个批次,如果需要最终报工请点【取消】按钮!!!", CustomMessageBoxButton.OKCancel, CustomMessageBoxIcon.Warning);
if (result == CustomMessageBoxResult.Cancel)
return;
//this.tbMsg.Content = "该批次为最后一个批次,必须勾选最终报工!";
//return;
}
}
}
}
12 months ago
}
catch (Exception ex)
{
CustomMessageBox.Show("报工检验数据有效性时发生了异常:" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
LogHelper.instance.log.Error("报工检验数据有效性时发生了异常:" + ex.Message);
btnOK.IsEnabled = true;
return;
12 months ago
}
btnOK.IsEnabled = false;
_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);
2 years ago
LogHelper.instance.log.Error("报工失败1" + selectedRow["workorder_code"]);
2 years ago
}
}
catch (Exception ex)
{
2 years ago
LogHelper.instance.log.Error("报工失败2" + ex.Message + selectedRow["workorder_code"]);
2 years ago
}
}
}
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);
}
2 years ago
}
catch (Exception ex)
{
12 months ago
CustomMessageBox.Show("报工失败" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
2 years ago
LogHelper.instance.log.Error("报工失败3" + ex.Message);
}
}
}
btnOK.IsEnabled = true;
}
private bool CheckUserCountDynamicTextBox()
{
dicUserCount.Clear();
bool isScucc = false;
for (int i = 0; i < dynamicUserCountTextBoxes.Count; i++)
12 months ago
{
if (!Regex.IsMatch(dynamicUserCountTextBoxes[i + 1].Text, @"^\d+$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "人员数量含有非法字符!";
2 years ago
dynamicUserCountTextBoxes[i + 1].Focus();
isScucc = false;
}
else
{
dicUserCount.Add(i, dynamicUserCountTextBoxes[i + 1].Text);
this.tbMsg.Content = "";
isScucc = true;
}
}
return isScucc;
}
private bool CheckWorkTimeDynamicTextBox()
{
dicWorkTime.Clear();
bool isScucc = false;
for (int i = 0; i < dynamicWorkTimeTextBoxes.Count; i++)
{
12 months ago
if (!Regex.IsMatch(dynamicWorkTimeTextBoxes[i + 1].Text, @"^\d+(\.\d+)?$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "工时含有非法字符!";
2 years ago
dynamicWorkTimeTextBoxes[i + 1].Focus();
isScucc = false;
}
else
{
12 months ago
dicWorkTime.Add(i, dynamicWorkTimeTextBoxes[i + 1].Text);
this.tbMsg.Content = "";
isScucc = true;
}
}
return isScucc;
2 years ago
}
private bool ReportWork()
12 months ago
{
//获取报工编码
string newReportCode = "";
2 years ago
try
{
2 years ago
DataTable dtNewReportCode = formingMachineService.GetReportCode();
if (dtNewReportCode == null || dtNewReportCode.Rows.Count == 0)
{
newReportCode = DateTime.Now.ToString("yyyyMMdd") + "0001";
}
else
{
2 years ago
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
catch (Exception ex)
{
LogHelper.instance.log.Error("报工失败:获取报工编码时发生异常:" + ex.Message);
CustomMessageBox.Show("报工失败:获取报工编码时发生异常:" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
return false;
}
2 years ago
string isEndReport = _isEndReport == true ? "1" : "0";
string xiaolv1 = "";
string shijian = "";
12 months ago
if (xiaolv.SelectedIndex == -1)
{
12 months ago
xiaolv1 = null;
}
else
{
12 months ago
xiaolv1 = xiaolv.SelectedItem.ToString();
}
if (txtWorkTime2.Text.IsNullOrEmpty())
{
shijian = null;
}
else
{
shijian = txtWorkTime2.Text;
}
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, dicWorkTime, dicUserCount, xiaolv1, shijian);
2 years ago
if (reportWorkSqlList.Count > 0)
{
if (AddConsumInfo(reportWorkSqlList, newReportCode))
{
if (comboBoxBatch.SelectedIndex != 0)
{
try
{
var getorder = formingMachineService.Getorderworkorder(selectedRow["workorder_code"].ToString());
var eqment = formingMachineService.GetWorkShop(Utils.GetAppSetting("DeviceCode"));
createCheckProductTask createCheckProductTask = new createCheckProductTask();
createCheckProductTask.factoryCode = Utils.GetAppSetting("SiteCode");//工厂编码
createCheckProductTask.incomeBatchNo = comboBoxBatch.Text.ToString();//批次号
createCheckProductTask.orderNo = selectedRow["workorder_code"].ToString();//订单号
if (getorder != null && getorder.Rows.Count > 0)
{
createCheckProductTask.materialCode = getorder.Rows[0]["product_code"].ToString(); ;//物料编码
createCheckProductTask.materialName = getorder.Rows[0]["product_name"].ToString();//物料名称
createCheckProductTask.unit = getorder.Rows[0]["unit"].ToString();//单位,(字典表)
}
createCheckProductTask.checkType = "checkTypeCPPC";//批次成品检验固定值
createCheckProductTask.typeCode = "product";//product
createCheckProductTask.quality = txtQuantity.Text;//数量
if (eqment != null && eqment.Rows.Count > 0)
{
createCheckProductTask.carName = eqment.Rows[0]["workshop_name"].ToString();//车间名称
createCheckProductTask.carCode = eqment.Rows[0]["workshop_code"].ToString();//车间编码
}
createCheckProductTask.produceDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//生产时间格式yyyy-MM-dd HH:mm:ss
createCheckProductTask.checkLoc = Utils.GetAppSetting("DeviceCode");//检测地点
// 接口地址
string apiUrl = formingMachineService.InterfaceUrl("BatcInspection");
// 将请求参数序列化为 JSON 格式
string requestBodyJson = Newtonsoft.Json.JsonConvert.SerializeObject(createCheckProductTask);
LogHelper.instance.log.Info("requestBodyJson批次检验任务日志" + requestBodyJson);
// 发送 HTTP POST 请求
using (var httpClient = new HttpClient())
{
var content = new StringContent(requestBodyJson, Encoding.UTF8, "application/json");
var response = httpClient.PostAsync(apiUrl, content).Result; // 或者 .Wait();
// 判断响应状态码是否为成功
if (response.IsSuccessStatusCode)
{
// 获取响应内容
string responseBody = response.Content.ReadAsStringAsync().Result; // 或者 .Wait();
CustomMessageBox.Show("批次成品检验任务创建成功!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning, 2000);
LogHelper.instance.log.Error("批次成品检验任务创建成功~即将准备更改工单状态");
return true;
}
else
{
// 输出失败信息
CustomMessageBox.Show("批次成品入库检验任务创建接口调用失败,请咨询开发人员", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning, 3000);
LogHelper.instance.log.Error("批次成品入库检验任务创建接口返回失败!");
return false;
}
}
}
catch (Exception ex)
{
LogHelper.instance.log.Error("批次成品入库检验任务创建接口调用失败>>" + ex.Message);
CustomMessageBox.Show("批次成品入库检验任务创建接口调用失败:" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
return false;
}
}
}
2 years ago
//报工接口不用调了
////调用报工接口
2 years ago
//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));
//批次成品入库检验任务创建
//createCheckProductTask createCheckProductTask = new createCheckProductTask();
//createCheckProductTask.checkLoc = deviceCode;
//createCheckProductTask.factoryCode = Utils.GetAppSetting("SiteCode");
12 months ago
return false;
2 years ago
//if (result.code == 200)
//{
2 years ago
//}
//else
//{
// CustomMessageBox.Show("调用报工接口失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
//}
}
else
{
CustomMessageBox.Show("报工失败", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
2 years ago
return false;
}
}
private bool AddConsumInfo(List<string> reportWorkSqlList, string newReportCode)
{
try
{
//报工消耗数量
//获取第二列的值
int columnIndex = 1; // 列索引,这里假设为第一列
2 years ago
if (_isEndReport.Value == true || selectedRow["status"].ToString().Equals("w4"))//20240424添加预报工功能暂停状态下添加消耗数据录入功能
{
2 years ago
CreateBaseQty();//将=0的根据公式填充进去
2 weeks ago
//CreateBaseWastage();//将=0的根据公式填充进去/
2 years ago
foreach (var row in dgConsumeInfo.Items)
{
2 years ago
var selectedConsumeRow = (row as DataRowView);
12 months ago
var qty = selectedConsumeRow["qty"].ToString() == "" ? "0" : selectedConsumeRow["qty"].ToString();
12 months ago
2 weeks ago
var wastage = selectedConsumeRow["wastage"].ToString() == "" ? "0" : selectedConsumeRow["wastage"].ToString();
2 years ago
var remark = selectedConsumeRow["remark"].ToString();
2 weeks ago
string insertConsumeSql = formingMachineService.GetMergeConsumeInfoSql(selectedConsumeRow, newReportCode, _siteCode);
2 years ago
reportWorkSqlList.Add(insertConsumeSql);
12 months ago
LogHelper.instance.log.Error("报工SQL生成" + insertConsumeSql);
1 year ago
#region
2 years ago
//// 获取 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;
// }
//}
1 year ago
#endregion
}
}
12 months ago
LogHelper.instance.log.Error("准备执行插入SQL" + reportWorkSqlList.Count + "条");
2 years ago
bool isReportSuccess = formingMachineService.GetExecuteReportWorkSql(reportWorkSqlList);
if (isReportSuccess)
{
LogHelper.instance.log.Error("完成插入!");
}
2 years ago
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)
{
GetFatherOrderUserCount();
InitComBoboxData();
piciInitComBoboxData();
InitConsumeData();
}
private void GetFatherOrderUserCount()
{
//2024-06-17处理报工界面工单号问题
//string workOrder = this.lbCurrOrderNo.Content.ToString();
//DataTable dt = formingMachineService.GetSubOrderCount(workOrder);
//if (dt == null)
//{
// this.txtFOUserCount.Visibility = Visibility.Collapsed;
// this.txtFOUserCount.IsEnabled = true;
//}
//else
//{
// this.txtFOUserCount.Text = "4";
// this.txtFOUserCount.IsEnabled = false;
//}
GetSubOrder(this._workOrdercode);
//string workOrder = this.lbCurrOrderNo.Content.ToString();
//DataTable dt = formingMachineService.GetFatherOrderUserCount(workOrder);
//if (dt == null)
//{
// this.txtFOUserCount.IsEnabled = true;
//}
//else
//{
// this.txtFOUserCount.Text = dt.Rows[0][0].ToString();
// this.txtFOUserCount.IsEnabled = false;
//}
}
2 years ago
private bool GetSubOrder(string workorderID)
{
try
{
sortNo++;
DataTable dtSubOrders = userDbWareHouse.GetSubOrderInfo(workorderID);
if (dtSubOrders != null)
{
2 years ago
this.txtUserCount.Text = "4";
string sort = "";
switch (sortNo)
{
case 1:
sort = "一"; break;
case 2:
sort = "二"; break;
case 3:
sort = "三"; break;
case 4:
sort = "四"; break;
case 5:
sort = "五"; break;
case 6:
sort = "六"; break;
case 7:
sort = "七"; break;
case 8:
sort = "八"; break;
case 9:
sort = "九"; break;
case 10:
sort = "10"; break;
case 11:
sort = "11"; break;
case 12:
sort = "12"; break;
default:
sortNo.ToString();
break;
}
//if (sortNo == 2)
//{
// StackPanel myStackPanelWorkTime = new StackPanel(); // 假设已经有一个StackPanel实例
// myStackPanelWorkTime.Orientation = Orientation.Horizontal;
// Label lbl = new Label();
// lbl.FontSize = 24;
// lbl.VerticalAlignment = VerticalAlignment.Center;
// lbl.HorizontalAlignment = HorizontalAlignment.Left;
// lbl.Content = "第" + sortNo + "工时:";
// TextBox textBox = new TextBox();
// textBox.FontSize = 24;
// textBox.Width = 260;
// textBox.VerticalAlignment = VerticalAlignment.Center;
// textBox.HorizontalAlignment = HorizontalAlignment.Left;
// textBox.TextChanged += TextBox_TextChanged;
// myStackPanelWorkTime.Children.Add(lbl);
// myStackPanelWorkTime.Children.Add(textBox);
// Grid.SetRow(myStackPanelWorkTime,3+sortNo);
// Grid.SetColumn(myStackPanelWorkTime, 1);
// MyGrid.Children.Add(myStackPanelWorkTime);
//}
//else
//{
Grid myGrid = (Grid)scrollViewer.Content;
StackPanel myStackPanelWorkTime = new StackPanel(); // 假设已经有一个StackPanel实例
myStackPanelWorkTime.Orientation = Orientation.Horizontal;
//添加工时
Label lbl = new Label();
lbl.FontSize = 24;
lbl.VerticalAlignment = VerticalAlignment.Center;
lbl.HorizontalAlignment = HorizontalAlignment.Left;
12 months ago
if (sort == "一")
1 year ago
{
lbl.Content = "半品工单工时:";
12 months ago
}
else if (sort == "二")
1 year ago
{
lbl.Content = "子半品工单工时:";
}
12 months ago
TextBox textBox = new TextBox();
textBox.FontSize = 24;
textBox.Width = 260;
textBox.TextChanged += TextBox_TextChanged;
textBox.VerticalAlignment = VerticalAlignment.Center;
textBox.HorizontalAlignment = HorizontalAlignment.Left;
//添加人数
Label lblUserCount = new Label();
lblUserCount.FontSize = 24;
lblUserCount.VerticalAlignment = VerticalAlignment.Center;
lblUserCount.HorizontalAlignment = HorizontalAlignment.Left;
1 year ago
if (sort == "一")
{
lblUserCount.Content = "半品工单人数:";
}
else if (sort == "二")
{
lblUserCount.Content = "子半品工单工时人数:";
}
12 months ago
myStackPanelWorkTime.Children.Add(lbl);
myStackPanelWorkTime.Children.Add(textBox);
Grid.SetRow(myStackPanelWorkTime, 3 + sortNo);
Grid.SetColumn(myStackPanelWorkTime, 0);
myGrid.Children.Add(myStackPanelWorkTime);
//将工时文本框存储到数据字典中
dynamicWorkTimeTextBoxes.Add(sortNo, textBox);
StackPanel myStackPanelWorkTime2 = new StackPanel(); // 假设已经有一个StackPanel实例
myStackPanelWorkTime2.Orientation = Orientation.Horizontal;
TextBox textBoxUserCount = new TextBox();
textBoxUserCount.TextChanged += UserCount_TextChanged;
textBoxUserCount.FontSize = 24;
textBoxUserCount.Width = 260;
textBoxUserCount.VerticalAlignment = VerticalAlignment.Center;
textBoxUserCount.HorizontalAlignment = HorizontalAlignment.Left;
myStackPanelWorkTime2.Children.Add(lblUserCount);
myStackPanelWorkTime2.Children.Add(textBoxUserCount);
Grid.SetRow(myStackPanelWorkTime2, 3 + sortNo);
Grid.SetColumn(myStackPanelWorkTime2, 1);
myGrid.Children.Add(myStackPanelWorkTime2);
//将人数文本框存储到数据字典中
2 years ago
dynamicUserCountTextBoxes.Add(sortNo, textBoxUserCount);
//stackPanelFather.Children.Add(myStackPanelWorkTime);
//}
// 递归添加控件
GetSubOrder(dtSubOrders.Rows[0]["workorder_code"].ToString());
//// 递归添加控件
//foreach (DataRow subOrder in dtSubOrders.Rows)
//{
// GetSubOrder(subOrder["workorder_code"].ToString());
//}
}
return true;
}
catch (Exception ex)
{
LogHelper.instance.log.Error(ex.Message);
return false;
}
}
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox box = sender as TextBox;
if (!Regex.IsMatch(box.Text, @"^\d+(\.\d+)?$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "工时含有非法字符!";
box.Focus();
return;
}
else
{
this.tbMsg.Content = "";
}
}
private void UserCount_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox box = sender as TextBox;
if (!Regex.IsMatch(box.Text, @"^\d+$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "人数含有非法字符!";
box.Focus();
return;
}
else
{
this.tbMsg.Content = "";
}
}
private void InitConsumeData()
{
2 years ago
dtCosumeData = userDbWareHouse.GetCosumeData(_workOrdercode);
if (dtCosumeData == null || dtCosumeData.Rows.Count == 0)
{
this.tbMsg.Content = "没有找到该工单的消耗信息";
//CustomMessageBox.Show("没有维护成本中心,请联系管理员!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
//绑定
12 months ago
dgConsumeInfo.ItemsSource = dtCosumeData.DefaultView;
2 years ago
}
2 years ago
private void CreateBaseQty()
{
if (_siteCode == "")
return;
//生成推荐实际消耗量
double rate = GetOrderRate();
if (rate == 0)
return;
foreach (System.Data.DataRow item in dtCosumeData.Rows)
{
//变更为只有等于0的时候才填值
if (item["qty"].ToString().Equals("0"))
item["qty"] = Math.Round(Convert.ToDouble(item["quantity"]) * rate, 2);
}
}
2 weeks ago
//private void CreateBaseWastage()
//{
// if (_siteCode == "")
// return;
// //生成推荐实际消耗量
// double rate = GetOrderRate();
// if (rate == 0)
// return;
// foreach (System.Data.DataRow item in dtCosumeData.Rows)
// {
// //变更为只有等于0的时候才填值
// if (item["wastage"].ToString().Equals("0"))
// item["wastage"] = Math.Round(Convert.ToDouble(item["wastage"]) * rate, 2);
// }
//}
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(_deviceCode);
if (dt == null || dt.Rows.Count == 0)
{
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();
if (e.EditAction == DataGridEditAction.Commit)
{
if (e.Column is DataGridTextColumn textColumn && e.EditingElement is TextBox textBox)
{
// 获取当前编辑的单元格的行和列索引
int rowIndex = e.Row.GetIndex();
int colIndex = dgConsumeInfo.Columns.IndexOf(textColumn);
2 years ago
//只限制用量的那一列,其余的不加限制
if (colIndex == 7)
{
2 years ago
// 获取输入的值
string newValue = textBox.Text;
// 执行你的验证逻辑,这里以整数为例
if (!Regex.IsMatch(newValue, @"^\d+(\.\d+)?$"))
{
// 输入的不是整数,可以执行相应的操作,例如还原之前的值或显示错误消息等
2 years ago
CustomMessageBox.Show("请输入整数或者小数!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
2 years ago
// 还原之前的值
dgConsumeInfo.CancelEdit();
2 years ago
// 或者清除输入的值
textBox.Text = string.Empty;
}
}
12 months ago
}
}
}
2 years ago
private void xuanze9_Checked(object sender, RoutedEventArgs e)
{
_isEndReport = true;
}
private void xuanze9_Click(object sender, RoutedEventArgs e)
{
if (xuanze9.IsChecked == true)
{
_isEndReport = true;
12 months ago
2 years ago
//dgConsumeInfo
}
else
{
_isEndReport = false;
}
}
2 years ago
private double GetOrderRate()
{
if (string.IsNullOrEmpty(this.txtQuantity.Text))
{
this.tbMsg.Content = "报工数量不能为空";
this.txtQuantity.Focus();
return 0;
}
if (!Regex.IsMatch(this.txtQuantity.Text, @"^\d+(\.\d+)?$"))
{
// 输入是一个有效的数字,包括小数
this.tbMsg.Content = "报工数量非法字符!";
this.txtQuantity.Focus();
return 0;
}
double rate = 0;
//string workOrder = this.lbCurrOrderNo.Content.ToString();
DataTable dt = formingMachineService.GetOrderReportSumQty(this._workOrdercode);
2 years ago
//如果没报过工,按照只有一个批次处理
if (dt == null || dt.Rows.Count == 0)
12 months ago
{
2 years ago
double qty = Convert.ToDouble(this.txtQuantity.Text);
rate = qty / Convert.ToDouble(_orderQuntity);
}
else
{
12 months ago
double qty = Convert.ToDouble(dt.Rows[0][0]) + Convert.ToDouble(this.txtQuantity.Text);
2 years ago
rate = qty / Convert.ToDouble(_orderQuntity);
}
return rate;
}
//private void txtFOUserCount_TextChanged(object sender, TextChangedEventArgs e)
//{
// if (!Regex.IsMatch(this.txtFOUserCount.Text, @"^\d+$"))
// {
// // 输入是一个有效的数字,包括小数
// this.tbMsg.Content = "母单人数含有非法字符!";
// this.txtFOUserCount.Focus();
// return;
// }
// else
// {
// this.tbMsg.Content = "";
// }
//}
private void dgConsumeInfo_CurrentCellChanged(object sender, EventArgs e)
{
}
11 months ago
private bool IsReading = false;
12 months ago
private void ReadOrder_Click(object sender, RoutedEventArgs e)
{
11 months ago
try
12 months ago
{
11 months ago
if (IsReading)
12 months ago
{
11 months ago
return;
12 months ago
}
11 months ago
IsReading = true;
LanJu_Operator.plc.Connection(LanJu_Operator.PlcIp);
int number = int.Parse(_deviceCode.Substring(2));
DataTable dataTable = formingMachineService.GetWcsPlcPointBoxCount("BoxCount" + number);
if (dataTable != null && dataTable.Rows.Count > 0)
12 months ago
{
11 months ago
string address = dataTable.Rows[0]["plc_point_address"].ToString();
var boxCount = LanJu_Operator.plc.Read(new CentralControl.BaseData.PlcSetting
{
PlcAddress = address,
PlcDataType = 1,
PlcValueLength = "2"
});
if (boxCount != null && int.TryParse(boxCount.ToString(), out int count))
{
txtQuantity.Text = boxCount.ToString();
}
else
{
CustomMessageBox.Show("读取失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
}
}
else
{
CustomMessageBox.Show("获取点位信息失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
12 months ago
}
}
11 months ago
catch
12 months ago
{
11 months ago
CustomMessageBox.Show("Plc连接失败", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
}
finally
{
IsReading = false;
12 months ago
}
}
}
public class CostCenter
{
public string factory_code { get; set; }
public string factory_name { get; set; }
}
12 months ago
public class createCheckProductTask
{
/// <summary>
/// 工厂编码
/// </summary>
public string factoryCode { get; set; }
/// <summary>
/// 批次号
/// </summary>
public string incomeBatchNo { get; set; }
/// <summary>
/// orderNo订单号
/// </summary>
public string orderNo { get; set; }
/// <summary>
/// 物料名称
/// </summary>
public string materialName { get; set; }
/// <summary>
/// 物料编码
/// </summary>
public string materialCode { get; set; }
/// <summary>
/// 检测类型固定 checkTypeSC首次检验 checkTypeHF烘房检验
/// </summary>
public string checkType { get; set; }
/// <summary>
/// product
/// </summary>
public string typeCode { get; set; }
/// <summary>
/// 收货数量
/// </summary>
public string quality { get; set; }
/// <summary>
/// 单位
/// </summary>
public string unit { get; set; }
/// <summary>
/// 车间名称
/// </summary>
public string carName { get; set; }
/// <summary>
/// 车间编码
/// </summary>
public string carCode { get; set; }
/// <summary>
/// 生产时间 格式yyyy-MM-dd HH:mm:ss
/// </summary>
public string produceDate { get; set; }
/// <summary>
/// 检测地点
/// </summary>
public string checkLoc { get; set; }
}
12 months ago
}