using System; using System.Text; using System.Collections.Generic; using System.Windows.Forms; using QM.Common; using QMAPP.FJC.Entity; using QMAPP.FJC.Entity.Basic; using QMAPP.FJC.Entity.Operation; using QMAPP.ServicesAgent; using QMAPP.WinForm.Common; using QMAPP.Entity; using QMAPP.FJC.BLL.Basic; using QMFrameWork.Data; using QMFrameWork.Common.Serialization; using System.Linq; using QMAPP.WinForm.Forms.Operation; namespace QMAPP.WinForm.Forms.Injection { /// /// 模块编号:M11-2 /// 作 用:搪塑条码打印 /// 作 者:王庆男 /// 编写日期:2015年05月28日 /// public partial class SlushMoldingPrintForOldForm : Form { /// /// 车型,A:B9车型,B:Q5车型 /// public string CarType { set; get; } List moldConfigList; /// /// 新建 /// public SlushMoldingPrintForOldForm() { InitializeComponent(); moldConfigList = new List(); } /// /// 窗体初始化 /// private void InitForm() { //预留方法,用于B9\Q5功能差异 } /// /// 窗体加载 /// /// /// private void Form_Load(object sender, EventArgs e) { InitForm(); QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent(); DataPage dataPage = new DataPage(); //获取前台分页设置信息 dataPage.PageIndex = 1; dataPage.PageSize = 100; //获取可用的配置信息 MoldConfig searchModel = new MoldConfig() { STATUS = 1 }; dataPage = agent.InvokeServiceFunction(B9BasicService.MoldConfigBLL_GetList.ToString(), searchModel); List recorders = null; recorders = JsonConvertHelper.GetDeserialize>(dataPage.Result.ToString()); recorders = recorders.OrderBy(o => o.INDEXVALUE).ToList(); moldConfigList = recorders; #region 绑定下拉列表 BasicData basicData = new BasicData(); //加载搪塑设备列表 //this.comMachineCode.DataSource = basicData.GetMachineInfoList(new string[] { EnumGeter.ProcessType.tangsu.GetHashCode().ToString() }, true); //this.comMachineCode.DisplayMember = "MACHINENAME"; //this.comMachineCode.ValueMember = "MACHINECODDE"; //this.comMachineCode.SelectedIndex = 1; //this.comMachineCode.Enabled = false; var machinelist = basicData.GetMachineInfoAndModelList(new string[] { }, true); this.comMachineCode.DataSource = machinelist; this.comMachineCode.DisplayMember = "MACHINENAME"; this.comMachineCode.ValueMember = "MACHINECODDE"; if (ClientContext.MachineInfo != null && !string.IsNullOrEmpty(ClientContext.MachineInfo.PID)) { this.comMachineCode.SelectedValue = ClientContext.MachineInfo.MACHINECODDE; //this.lblLock.Visible = false; this.LockType(false); } else { //this.lblLock.Visible = false; this.LockType(false); } //颜色 this.comColor.DataSource = basicData.GetDictionaryList(EnumGeter.DictKind.COLOR.ToString()); this.comColor.DisplayMember = "VALUE"; this.comColor.ValueMember = "KEY"; this.comColor.SelectedValue = "1"; //this.comColor.Enabled = false; ////AB腔 this.comPosition.DataSource = basicData.GetDictionaryList(EnumGeter.DictKind.CAVITYTYPE.ToString()); this.comPosition.DisplayMember = "VALUE"; this.comPosition.ValueMember = "KEY"; //this.comPosition.SelectedIndex = 0; //this.comPosition.Enabled = false; #endregion //加工日期 if (string.IsNullOrEmpty(this.dtpDate.Text)) { this.dtpDate.Text = DateTime.Now.ToString(); } SetMouldStation(); #region 打印模板拷贝 PrintTempleCopyClass printClass = new PrintTempleCopyClass(); printClass.CopyPrintTemple("SlushMoldingPrintForOldForm"); #endregion } #region 设置模架号 /// /// /// private void SetMouldStation() { this.cBoxModelCode.DisplayMember = "VALUE"; this.cBoxModelCode.ValueMember = "KEY"; List cBoxModelCodeList = new List(); foreach (var m in moldConfigList) { cBoxModelCodeList.Add(new { VALUE = m.MOLDVALUE, KEY = m.MOLDVALUE }); } this.cBoxModelCode.DataSource = cBoxModelCodeList; this.cBoxModelCode.SelectedIndex = 0; cBoxModelCode.Enabled = false; this.comMouldNumber.DisplayMember = "VALUE"; this.comMouldNumber.ValueMember = "KEY"; List comMouldNumberList = new List(); foreach (var m in moldConfigList) { comMouldNumberList.Add(new { VALUE = m.MOLDSTATION, KEY = m.MOLDSTATION }); } this.comMouldNumber.DataSource = comMouldNumberList; this.comMouldNumber.SelectedIndex = 0; //判断是否有正在使用的模腔配置信息 if (moldConfigList.Count(o => o.USED == 1) > 0) { //获取该对象 MoldConfig m = moldConfigList.First(o => o.USED == 1); //设置模架选择项 comMouldNumber.SelectedValue = m.MOLDSTATION; //设置模腔选择项 cBoxModelCode.SelectedValue = m.MOLDVALUE; } } #endregion #region 窗体保存事件 /// /// 窗体保存事件 /// /// /// private void tsbSave_Click(object sender, EventArgs e) { string message = this.ErrorCheck(); if (!string.IsNullOrEmpty(message)) { this.ErrorMessage.Text = message; return; } List listRecorder = new List(); //窗体数据校验 //老搪塑只出黑色表皮,模腔号2 为高配B腔 模腔号3 为低配A腔,老搪塑只有一套模具,固定即可 //搪塑机 MachineInfo machineInfo = this.comMachineCode.SelectedItem as MachineInfo; #region 加载保存信息 //for (int i = 0; i < 2; i++)//一次出2个码 //{ //零件属性 Product recorder = new Product(); ProductAttribute productAttribute = new ProductAttribute(); //搪塑机编号 productAttribute.VAL1 = machineInfo.MACHINENUM; //产品类型(车型)成都固定 productAttribute.VAL2 = "V"; //高低配 成都无,且固定 productAttribute.VAL3 = "B"; //颜色 productAttribute.VAL4 = this.comColor.SelectedValue.ToString(); string[] cb = new string[] { }; if (!string.IsNullOrEmpty(this.cBoxModelCode.Text)) { cb = this.cBoxModelCode.Text.Split('+'); } if (cb.Length <= 0) { MessageBox.Show("模腔出错!"); return; } //腔 //if (i == 0)//第一个为模腔号2 //{ // //腔 // productAttribute.VAL5 = "B"; // //模腔 // productAttribute.VAL6 = cb[0].PadLeft(2,'0'); //} //else //{ // //腔 // productAttribute.VAL5 = "A"; // //模腔 // productAttribute.VAL6 = cb[1].PadLeft(2, '0'); //} if (this.comPosition.Text == "搪塑B腔")//第一个为模腔号2 { //腔 productAttribute.VAL5 = "B"; //模腔 productAttribute.VAL6 = cb[0].PadLeft(2, '0'); } else if (this.comPosition.Text == "搪塑A腔") { //腔 productAttribute.VAL5 = "A"; //模腔 productAttribute.VAL6 = cb[1].PadLeft(2, '0'); } //加工日期 if (string.IsNullOrEmpty(this.dtpDate.Text.Trim())) { productAttribute.VAL7 = Convert.ToDateTime(DateTime.Now).ToString("yyyy-MM-dd HH:mm:ss"); } else { productAttribute.VAL7 = Convert.ToDateTime(this.dtpDate.Text.Trim()).ToString("yyyy-MM-dd HH:mm:ss"); } recorder.MACHINECODDE = machineInfo.MACHINECODDE; recorder.MACHINENAME = machineInfo.MACHINENAME; recorder.PRODUCTSOURCE = EnumGeter.PRODUCTSOURCE.SELFMADE.GetHashCode().ToString(); recorder.PRODUCTTYPE = EnumGeter.ProductType.biaopi.GetHashCode().ToString(); ////添加加物料号 //QMAPP.ServicesAgent.ServiceAgent agents = ClientContext.GetServiceAgent(); //DataResult materialcode = agents.InvokeServiceFunction>(B9BasicService.MaterialCodeBLL_GetMaterialCode.ToString(), productAttribute.VAL2); //recorder.MATERIAL_CODE = materialcode.Result.ToString(); recorder.STATUS = EnumGeter.PRODUCTSTAUTS.QUALIFIED.GetHashCode().ToString(); recorder.CURRENTPROCESS = EnumGeter.ProcessType.lengdaoruohua.GetHashCode().ToString(); //ToDo:选择生产线 //成都固定生产线 recorder.PRODUCELINE = "IPVW371"; recorder.OUTFLAG = EnumGeter.PRODUCTOUTFLAG.INLIBRARY.GetHashCode().ToString(); recorder.USINGSTATE = EnumGeter.PRODUCTUSESTATE.UNUSED.GetHashCode().ToString(); recorder.PRODUCESHIFTTCODE = ClientContext.produceShift.PRODUCESHIFTTCODE; recorder.PRODUCESHIFTNAME = ClientContext.produceShift.PRODUCESHIFTNAME; recorder.CAPACITY = 1; recorder.USINGCOUNT = 0; recorder.PRODUCTATTRIBUTE = productAttribute; recorder.AddM = this.cbM.Checked; listRecorder.Add(recorder); //} #region 保存 QMAPP.ServicesAgent.ServiceAgent agent = ClientContext.GetServiceAgent(); DataResult> result = agent.InvokeServiceFunction>>(B9BasicService.ProductBLL_InsertListEpidermis.ToString(), listRecorder); //保存成功 if (result.IsSuccess) { #region 打印条码 this.DialogResult = System.Windows.Forms.DialogResult.OK; string barCode = result.Result.ToString(); foreach (PrintCode item in result.Result) { QM.Assist.LabelInfo ll = new QM.Assist.LabelInfo(); ll.BarCode = item.MAINCODE + ",*" + item.PRODUCTCODE + "*" + "," + item.COLOR_CODE; QM.Assist.PrintUtil.LabelList2.Add(ll); //创建新行 var row = new DataGridViewRow(); if (DGView.Rows.Count == 0) { var index = this.DGView.Rows.Add(); row = DGView.Rows[index]; } else { this.DGView.Rows.InsertCopy(0, 0); row = DGView.Rows[0]; } //对datagridview赋值 row.Cells["MAINCODE"].Value = item.MAINCODE; row.Cells["PRODUCTCODE"].Value = item.PRODUCTCODE; row.Cells["COLOR"].Value = item.COLOR_CODE; row.Cells["CREATETIME"].Value = DateTime.Now; if (DGView.Rows.Count > 200) { DGView.Rows.RemoveAt(200); } } QM.Assist.PrintUtil pu = new QM.Assist.PrintUtil(); pu.PrintLabel2(System.Configuration.ConfigurationManager.AppSettings["proPath"].ToString (), System.Configuration.ConfigurationManager.AppSettings[EnumGeter.ProductType.biaopi.GetHashCode().ToString() + "temPath"].ToString (), System.Configuration.ConfigurationManager.AppSettings[EnumGeter.ProductType.biaopi.GetHashCode().ToString() + "dataPath"].ToString ()); #endregion #region 重新设置当前使用和列表信息 var Station = comMouldNumber.SelectedItem; string moldStation = GetPropertyValue(Station, "KEY").ToString(); #region 重新设置当前使用 DataResult updateresult = agent.InvokeServiceFunction(B9BasicService.MoldConfigBLL_UpdateNextUsed.ToString(), new MoldConfig() { MOLDSTATION = moldStation }); #endregion #region 绑定下拉列表 DataPage dataPage = new DataPage(); //获取前台分页设置信息 dataPage.PageIndex = 1; dataPage.PageSize = 100; //获取可用的配置信息 MoldConfig searchModel = new MoldConfig() { STATUS = 1 }; dataPage = agent.InvokeServiceFunction(B9BasicService.MoldConfigBLL_GetList.ToString(), searchModel); moldConfigList = JsonConvertHelper.GetDeserialize>(dataPage.Result.ToString()); moldConfigList = moldConfigList.OrderBy(o => o.INDEXVALUE).ToList(); SetMouldStation(); #endregion #endregion //MessageBox.Show("打印成功!"); this.ErrorMessage.Text = ""; } else { MessageBox.Show(result.Msg); } #endregion #endregion } #endregion #region 窗体关闭 /// /// 窗体关闭 /// /// /// private void tsbClose_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 错误检测 /// ///错误检测 /// /// private string ErrorCheck() { #region string strMessage = ""; //判断条码是否为空 ////搪塑设备 if (this.comMachineCode.SelectedValue == null || this.comMachineCode.SelectedValue == string.Empty) { strMessage += Resource1.SlushMachineNullValidate + "\r\n"; } ////产品类别 //if (this.comProType.SelectedValue == null || this.comProType.SelectedValue == string.Empty) //{ // strMessage += Resource1.ProductTypeNullValidate + "\r\n"; //} //颜色 if (this.comColor.SelectedValue == null || this.comColor.SelectedValue == string.Empty) { strMessage += Resource1.ColorNullValidate + "\r\n"; } ////高低配 //if (this.comHOrL.SelectedValue == null || this.comHOrL.SelectedValue == string.Empty) //{ // strMessage += Resource1.HLNullValidate + "\r\n"; //} //腔 if (this.comPosition.SelectedValue == null || this.comPosition.SelectedValue == string.Empty) { strMessage += Resource1.PositionNullValidate + "\r\n"; } ////模腔号 //if (this.cBoxModelCode.Text == null || this.cBoxModelCode.Text == string.Empty) //{ // strMessage += Resource1.ModelCodeNullValidate + "\r\n"; //} return strMessage; #endregion } #endregion /// /// /// /// /// private void comMouldNumber_SelectedIndexChanged(object sender, EventArgs e) { var Station = comMouldNumber.SelectedItem; string moldStation = GetPropertyValue(Station, "KEY").ToString(); MoldConfig m = moldConfigList.First(o => o.MOLDSTATION == moldStation); //设置模腔选择项 cBoxModelCode.SelectedValue = m.MOLDVALUE; } /// /// /// /// /// /// public object GetPropertyValue(object info, string field) { if (info == null) return null; Type t = info.GetType(); IEnumerable property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi; return property.First().GetValue(info, null); } #region 锁定解锁 /// /// 锁定解锁 /// /// /// private void lblLock_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (this.lblLock.Tag.ToString().Equals("0")) { LockType(false); } else { LockType(true); } } #endregion #region 设备和类别锁定 /// /// 设备和类别锁定 /// /// private void LockType(bool lockFlag) { this.comMachineCode.Enabled = lockFlag; //this.comProductType.Enabled = lockFlag; if (lockFlag) { this.lblLock.Text = "锁定工位"; this.lblLock.Tag = "0"; } else { string locationfile = System.Configuration.ConfigurationManager.AppSettings["loactionfile"]; System.IO.File.WriteAllText(locationfile, this.comMachineCode.SelectedValue.ToString()); this.lblLock.Text = "解锁工位"; this.lblLock.Tag = "1"; } } #endregion } }