天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

591 lines
23 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using QMAPP.FJC.Entity;
using QMAPP.ServicesAgent;
using QMAPP.WinForm.Common;
using QMAPP.Entity;
using QMAPP.FJC.Entity.ProduceManage;
using QMAPP.FJC.BLL.Dict;
using QMAPP.FJC.Entity.Operation;
using QMAPP.MD.Entity;
namespace QMAPP.WinForm.Forms.Mend
{
/// <summary>
/// 作 用:批量报废
/// 作 者:周晓东
/// 编写日期:2018年02月05日
///</summary>
public partial class MendRecorderWasteForm : Form
{
QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
public List<DefectType> defectTypeList = new List<DefectType>();
#region
public MendRecorderWasteForm()
{
InitializeComponent();
}
#endregion
#region 窗体数据初始化
/// <summary>
/// 窗体数据初始化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_Load(object sender, EventArgs e)
{
#region 绑定下拉列表
BasicData basicData = new BasicData();
//设置焦点
//this.ActiveControl = this.txtMendNumber;
//this.txtMendNumber.Focus();
//物料类别下拉列表
//this.comMaterialType.DataSource = basicData.GetMaterialClassToMendRecorderWasteForm(false);
//this.comMaterialType.DisplayMember = "MATERIAL_TYPE_NAME";
//this.comMaterialType.ValueMember = "MATERIAL_TYPE_CODE";
//返修原因
//DataTable recorder = agent.InvokeServiceFunction<DataTable>(B9IPCService.DefectTypeBLL_GetDefectType.ToString());
//List<QM.Common.ListItem> list = new List<QM.Common.ListItem>();
////list.Add(new QM.Common.ListItem("", ""));
//foreach (DataRow dr in recorder.Rows)
//{
// int keyvalue = Convert.ToInt32(dr["DEFECTKEY"]);
// string defectValue = dr["DEFECTVALUE"].ToString();
// list.Add(new QM.Common.ListItem(keyvalue.ToString(), defectValue));
//}
//this.comMendReason.DataSource = list;
//this.comMendReason.DisplayMember = "value";
//this.comMendReason.ValueMember = "key";
//生产时间
piciNo.ValueX=DateTime.Now;
//加工方法
comHANDLEMETHODBind();
//加载所有工序下拉列表
this.comWorkCell.DataSource = basicData.GetWorkCellList(true);
this.comWorkCell.DisplayMember = "WORKCELL_NAME";
this.comWorkCell.ValueMember = "WORKCELL_CODE";
//加载所有班次下拉列表
List<FJC.Entity.Basic.ProduceShift> shiftList= basicData.GetShiftComboxSource();;
this.comShift.DataSource =shiftList;
this.comShift.DisplayMember = "PRODUCESHIFTNAME";
this.comShift.ValueMember = "PRODUCESHIFTTCODE";
FJC.Entity.Basic.ProduceShift s = shiftList.First(o => o.PRODUCESHIFTNAME == ClientContext.produceShift.PRODUCESHIFTNAME);
int selectIndex = shiftList.IndexOf(s);
comShift.SelectedIndex = selectIndex;
//废品类别
var code = "MENDTYPE";
var CODES = agent.InvokeServiceFunction<List<MendRecorder>>("MendRecorderBLL_GetMFGCODES", code);
this.comMENDTYPE.DataSource = CODES;
this.comMENDTYPE.DisplayMember = "ERP_NAME";
this.comMENDTYPE.ValueMember = "ERP_CODE";
//车型代码
code = "CAR";
CODES = agent.InvokeServiceFunction<List<MendRecorder>>("MendRecorderBLL_GetMFGCODES", code);
this.comCAR.DataSource = CODES;
this.comCAR.DisplayMember = "ERP_NAME";
this.comCAR.ValueMember = "ERP_CODE";
//生产线代码
code = "WORKLINE";
CODES = agent.InvokeServiceFunction<List<MendRecorder>>("MendRecorderBLL_GetMFGCODES", code);
this.comWORKLINE.DataSource = CODES;
this.comWORKLINE.DisplayMember = "ERP_NAME";
this.comWORKLINE.ValueMember = "ERP_CODE";
//班组代码
code = "SHIFT";
CODES = agent.InvokeServiceFunction<List<MendRecorder>>("MendRecorderBLL_GetMFGCODES", code);
this.comERPSHIFT.DataSource = CODES;
this.comERPSHIFT.DisplayMember = "ERP_NAME";
this.comERPSHIFT.ValueMember = "ERP_CODE";
MendRecorder m = CODES.First(o => o.ERP_NAME.Contains(ClientContext.produceShift.PRODUCESHIFTTCODE));
int erpIndex = CODES.IndexOf(m);
comERPSHIFT.SelectedIndex = erpIndex;
//工序代码
code = "WORKCELL";
CODES = agent.InvokeServiceFunction<List<MendRecorder>>("MendRecorderBLL_GetMFGCODES", code);
CODES.RemoveAt(0);
this.comERPWORKCELL.DataSource = CODES;
this.comERPWORKCELL.DisplayMember = "ERP_NAME";
this.comERPWORKCELL.ValueMember = "ERP_CODE";
//缺陷归属
code = "DEFECTTO";
CODES = agent.InvokeServiceFunction<List<MendRecorder>>("MendRecorderBLL_GetMFGCODES", code);
this.comDEFECTTO.DataSource = CODES;
this.comDEFECTTO.DisplayMember = "ERP_NAME";
this.comDEFECTTO.ValueMember = "ERP_CODE";
//产品类别代码
code = "PRODUCTTYPE";
CODES = agent.InvokeServiceFunction<List<MendRecorder>>("MendRecorderBLL_GetMFGCODES", code);
this.comPRODUCTTYPE.DataSource = CODES;
this.comPRODUCTTYPE.DisplayMember = "ERP_NAME";
this.comPRODUCTTYPE.ValueMember = "ERP_CODE";
//缺陷代码
code = "DEFECTCODE";
CODES = agent.InvokeServiceFunction<List<MendRecorder>>("MendRecorderBLL_GetMFGCODES", code);
this.comDEFECTCODE.DataSource = CODES;
this.comDEFECTCODE.DisplayMember = "ERP_NAME";
this.comDEFECTCODE.ValueMember = "ERP_CODE";
//basicData.AdjustComboBoxDropDownListWidth(comDEFECTCODE);
comDEFECTCODE.DropDownWidth = 300;
GetMaterialTree();
#endregion
}
#endregion
#region 事件
#region 物料号-树
public void GetMaterialTree()
{
QMAPP.ServicesAgent.ServiceAgent wcfAgent = ClientContext.GetServiceAgent();
try
{
var materialResult = wcfAgent.InvokeServiceFunction<List<Material>>
("MaterialBLL_GetMaterialList", new Material());
MaterialClass materialclass = new MaterialClass();
materialclass.MaterialAttributes = "(' ','0','1','2','5')";
var classresult = wcfAgent.InvokeServiceFunction<DataResult<List<MaterialClass>>>
("MaterialBLL_GetMaterialClassList", materialclass).Result;
//var classresult = wcfAgent.InvokeServiceFunction<DataResult<List<MaterialClass>>>
// ("MaterialBLL_GetMaterialClassList", new MaterialClass()).Result;
//List<CombotreeItem> trees = new List<CombotreeItem>();
//trees.Add(new CombotreeItem { id = "", text = this.EmptyItemTitle });
foreach (MaterialClass item in classresult.Where(p => string.IsNullOrWhiteSpace(p.UP_MATERIAL_TYPE_CODE)).OrderBy(p => p.SEQ_NUM))
{
var subnode = new TreeNode { Name = item.MATERIAL_TYPE_CODE, Text = item.MATERIAL_TYPE_NAME };
AppendTree(subnode, classresult, materialResult);
if (subnode.Nodes.Count > 0)
{
treeView1.Nodes.Add(subnode);
}
}
//return Json(trees);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 追加树节点
/// </summary>
/// <param name="node"></param>
/// <param name="mclasslist"></param>
/// <param name="materiallist"></param>
private void AppendTree(TreeNode node, List<MaterialClass> mclasslist, List<Material> materiallist)
{
foreach (var mclass in mclasslist.Where(p => string.Equals(node.Name, p.UP_MATERIAL_TYPE_CODE)).OrderBy(p => p.SEQ_NUM))
{
var subnode = new TreeNode { Name = mclass.MATERIAL_TYPE_CODE, Text = mclass.MATERIAL_TYPE_NAME };
AppendTree(subnode, mclasslist, materiallist);
if (subnode.Nodes.Count > 0)
{
node.Nodes.Add(subnode);
}
}
foreach (var material in materiallist.Where(p => string.Equals(node.Name, p.MATERIAL_TYPE_CODE)).OrderBy(p => p.MATERIAL_CODE))
{
var subnode = new TreeNode { Name = material.MATERIAL_CODE, Text = material.MATERIAL_CODE + "/" + material.MATERIAL_NAME };
node.Nodes.Add(subnode);
}
}
#endregion
#region 物料类型-树
public void GetMaterialClassTree()
{
QMAPP.ServicesAgent.ServiceAgent wcfAgent = ClientContext.GetServiceAgent();
try
{
var classresult = wcfAgent.InvokeServiceFunction<DataResult<List<MaterialClass>>>
("MaterialBLL_GetMaterialClassList", new MaterialClass()).Result;
//treeView1.Nodes.Add(new TreeNode { Name = "", Text = " " });
//List<CombotreeItem> trees = new List<CombotreeItem>();
//trees.Add(new CombotreeItem { id = "", text = this.EmptyItemTitle });
foreach (MaterialClass item in classresult.Where(p => string.IsNullOrWhiteSpace(p.UP_MATERIAL_TYPE_CODE)).OrderBy(p => p.SEQ_NUM))
{
var subnode = new TreeNode { Name = item.MATERIAL_TYPE_CODE, Text = item.MATERIAL_TYPE_NAME };
AppendTree(subnode, classresult);
treeView1.Nodes.Add(subnode);
}
//return Json(trees);
}
catch (Exception ex)
{
throw ex;
}
}
private void AppendTree(TreeNode node, List<MaterialClass> mclasslist)
{
foreach (var mclass in mclasslist.Where(p => string.Equals(node.Name, p.UP_MATERIAL_TYPE_CODE)).OrderBy(p => p.SEQ_NUM))
{
var subnode = new TreeNode { Name = mclass.MATERIAL_TYPE_CODE, Text = mclass.MATERIAL_TYPE_NAME };
AppendTree(subnode, mclasslist);
node.Nodes.Add(subnode);
}
}
#endregion
#region 保存事件
/// <summary>
/// 保存事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbSave_Click(object sender, EventArgs e)
{
MendRecorder product = new MendRecorder();
//List<DefectType> defectTypeList=new List<DefectType>();
try
{
#region 保存
if (string.IsNullOrEmpty(txtMaterialCode.Text))
{
MessageBox.Show("请选择物料号!");
return;
}
if (string.IsNullOrEmpty(comHANDLEMETHOD.Text))
{
MessageBox.Show("请选择处理方法!", "提示");
return;
}
if (string.IsNullOrEmpty(comWorkCell.Text))
{
MessageBox.Show("请选择工序!");
return;
}
//if (defectTypeList.Count == 0)
//{
// MessageBox.Show("请选择缺陷类型!", "提示");
// return;
//}
if (string.IsNullOrEmpty(txtMendNumber.Text) )
{
MessageBox.Show("请输入报废数量!");
return;
}
if (string.IsNullOrEmpty(this.piciNo.Text.Trim()))
{
MessageBox.Show("请输入生产时间!");
return;
}
if (string.IsNullOrEmpty(comShift.Text))
{
MessageBox.Show("请选择生产班次!");
return;
}
//erp
if (comMENDTYPE.SelectedIndex < 1)
{
MessageBox.Show("请选择废品类别!");
return;
}
if (comCAR.SelectedIndex < 1)
{
MessageBox.Show("请选择车型代码!");
return;
}
if (comWORKLINE.SelectedIndex < 1)
{
MessageBox.Show("请选择生产线!");
return;
}
if (comERPSHIFT.SelectedIndex < 1)
{
MessageBox.Show("请选择班组代码!");
return;
}
//if (comERPWORKCELL.SelectedIndex < 1)
//{
// MessageBox.Show("请选择工序代码!");
// return;
//}
if (comDEFECTTO.SelectedIndex < 1)
{
MessageBox.Show("请选择缺陷归属!");
return;
}
if (comPRODUCTTYPE.SelectedIndex < 1)
{
MessageBox.Show("请选择产品类别!");
return;
}
if (comDEFECTCODE.SelectedIndex < 1)
{
MessageBox.Show("请选择缺陷代码!");
return;
}
//if (treeView1.SelectedNode.Nodes.Count!=0)
//{
// MessageBox.Show("请选择物料号。");
// return;
//}
product.MATERIAL_TYPE_CODE = txtMaterialType.Text.Trim();
product.MATERIAL_CODE = txtMaterialCode.Text.Trim();
product.WORKCELL_CODE = comWorkCell.SelectedValue.ToString();
product.SHIFT_CODE = comShift.SelectedValue.ToString();
product.BATCH_NO = piciNo.Value.ToString("yyyyMMdd");
//是否测试件
product.MENDTEST = "否";
if (checkBox1.Checked)
{
product.MENDTEST = "是";
}
//处理方法下拉框赋值
if (comHANDLEMETHOD.SelectedValue != null) product.HANDLEMETHOD = comHANDLEMETHOD.SelectedValue.ToString();
int tmp;
if (!int.TryParse(txtMendNumber.Text, out tmp))
{
MessageBox.Show("请正确输入数字");
return;
}
product.MENDNUMBER = tmp;
//工作中心写死-注塑 20180402zxd
//product.WORKCENTER_CODE = "INJECT";
//DefectType defect=new DefectType();
//defect.DEFECTKEY = Int32.Parse(comMendReason.SelectedValue.ToString());
//defect.DEFECTVALUE = comMendReason.Text;
//defectTypeList.Add(defect);
//ERP数据
product.ERP_MFGCODETYPE = comMENDTYPE.SelectedValue.ToString();
product.ERP_CAR = comCAR.SelectedValue.ToString();
product.ERP_WORKLINE = comWORKLINE.SelectedValue.ToString();
product.ERP_SHIFT = comERPSHIFT.SelectedValue.ToString();
product.ERP_WORKCELL = comERPWORKCELL.SelectedValue.ToString();
product.ERP_DEFECTTO = comDEFECTTO.SelectedValue.ToString();
product.ERP_PRODUCTTYPE = comPRODUCTTYPE.SelectedValue.ToString();
product.ERP_DEFECTCODE = comDEFECTCODE.SelectedValue.ToString();
QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent();
DataResult<int> result = agent.InvokeServiceFunction<DataResult<int>>("MendRecorderBLL_InsertMendRecordItemNewNew", product, defectTypeList);
if (result.IsSuccess)
{
//清空窗口上数据
//Clear();
//保存成功
MessageBox.Show("保存成功");
//var f=new MendRecorderForm();
//f.SetSearchModel();
//f.pager1.Init();
//f.BindGirdData();
this.Close();
}
#endregion
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 窗体关闭事件
/// <summary>
/// 窗体关闭事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbClose_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
#endregion
private void txtMendNumber_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar != '\b')//这是允许输入退格键dai
{
if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字
{
e.Handled = true;
}
}
}
private void txtMendNumber_Click(object sender, EventArgs e)
{
//QMAPP.WinForm.Forms.Common.TouchKey key = new Forms.Common.TouchKey((TextBox)sender);
//key.ShowDialog();
}
private void txtMendNumber_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
const string pattern = @"^\d+\.?\d+{1}quot";
string content = ((TextBox)sender).Text;
//if (!(Regex.IsMatch(content, pattern)))
//{
// //errorProvider1.SetError((Control)sender, "只能输入数字!");
// e.Cancel = true;
//}
// else
//errorProvider1.SetError((Control)sender, null);
}
//物料号树
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (treeView1.SelectedNode!=null)
{
if (treeView1.SelectedNode.Nodes.Count==0)
{
txtMaterialCode.Text = treeView1.SelectedNode.Name;
var material = agent.InvokeServiceFunction<MendRecorder>("MendRecorderBLL_GetMaterialTeam", treeView1.SelectedNode.Name);
if (material!=null )
{
//车型代码下拉框定位
if (!string.IsNullOrWhiteSpace(material.PROJECTCODE))
{
comCARBind(material.PROJECTCODE);
}
//班组代码下拉框定位
if (!string.IsNullOrWhiteSpace(material.TEAM_CODE))
{
comERPSHIFTBind(material.TEAM_CODE.Trim());
}
}
txtMaterialType.Text = treeView1.SelectedNode.Parent.Name;
}
//MessageBox.Show(treeView1.SelectedNode.Nodes.Count.ToString());
}
}
//车型代码下拉框定位
private void comCARBind(string ProjectCode)
{
foreach (MendRecorder CAR in comCAR.Items)
{
if (!string.IsNullOrWhiteSpace(CAR.ERP_NAME))
{
var names = CAR.ERP_NAME.Split('/');
if (ProjectCode.Contains(names[1]))
{
comCAR.SelectedValue = CAR.ERP_CODE;
}
}
}
}
//班组代码下拉框定位
private void comERPSHIFTBind(string TeamCode)
{
foreach (MendRecorder Team in comERPSHIFT.Items)
{
if (!string.IsNullOrWhiteSpace(Team.ERP_NAME))
{
//var names = CAR.ERP_NAME.Split('/');
if (TeamCode == Team.ERP_CODE)
{
comERPSHIFT.SelectedValue = Team.ERP_CODE;
}
}
}
}
private void comMFGCODETYPE_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void butDEFECT_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtMaterialCode.Text))
{
MessageBox.Show("请选择物料号!");
return;
}
var mt = txtMaterialType.Text.Trim();
if (string.IsNullOrEmpty(comWorkCell.Text))
{
MessageBox.Show("请选择工序!");
return;
}
var workcell = comWorkCell.SelectedItem as WorkCell;
var workcenter = workcell.WORKCENTER_CODE;
MendRecorderReasonForm form = new MendRecorderReasonForm(this, workcenter);
form.ShowDialog();
}
private void comDEFECTCODE_SelectedIndexChanged(object sender, EventArgs e)
{
var name = comDEFECTCODE.Text;
var code = name.Substring(name.Length - 1, 1);
foreach (MendRecorder DEFECTTO in comDEFECTTO.Items)
{
if (code == DEFECTTO.ERP_CODE)
{
comDEFECTTO.SelectedValue = code;
}
}
}
private void comWorkCell_SelectedIndexChanged(object sender, EventArgs e)
{
var workCell = comWorkCell.SelectedItem as WorkCell;
var material = agent.InvokeServiceFunction<MendRecorder>("MendRecorderBLL_GetWorkLine", workCell.WORKCENTER_CODE);
if (material != null)
{
//生产线下拉框定位
if (!string.IsNullOrWhiteSpace(material.ERP_WORKLINE))
{
comWORKLINE.SelectedValue = material.ERP_WORKLINE;
}
}
}
//处理方法下拉框
private void comHANDLEMETHODBind()
{
BasicData basicData = new BasicData();
//返修结果
this.comHANDLEMETHOD.DataSource = basicData.GetDictionaryList("HANDLEMETHOD");
this.comHANDLEMETHOD.DisplayMember = "value";
this.comHANDLEMETHOD.ValueMember = "key";
this.comHANDLEMETHOD.SelectedIndex = 3;
comHANDLEMETHOD.DropDownWidth = 300;
}
}
}