using Core.Mes.Client.Comm.Format; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.YdmStuffManage.Entity; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Core.StlMes.Client.YdmStuffManage { public partial class FrmSubContractAffrim : FrmBase { public FrmSubContractAffrim() { InitializeComponent(); } private void FrmSubContractAffrim_Load(object sender, EventArgs e) { DateTime now = DateTime.Now; DateTime dt1 = new DateTime(now.Year, now.Month, 1);//当月第一天 DateTime dt2 = dt1.AddMonths(1).AddDays(-1);//当月最后一天 this.StartTime.Value = DateTime.Parse(dt1.ToString("yyyy-MM-dd") + " 00:00:00"); this.EndTime.Value = DateTime.Parse(dt2.ToString("yyyy-MM-dd") + " 23:59:59"); EntityHelper.ShowGridCaption(ultraGrid1.DisplayLayout.Bands[0]); EntityHelper.ShowGridCaption(ultraGrid2.DisplayLayout.Bands[0]); } /// /// 重写基类方法 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case"Query": doQueryEntrustBill(); break; case "subcontractComplete": subcontractComplete(); break; case "cancelSubcontractComplete": cancelSubcontractComplete(); break; case"doAffrim": doAffrim(); break; case"cancelDoAffrim": cancelDoAffrim(); break; case "Close": this.Close(); break; } } /// /// 确认实绩 /// private void doAffrim() { this.ultraGrid1.UpdateData(); UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (uRow == null) return; if (uRow.Cells["SubcontractFlag"].Value.Equals("未完成")) { MessageUtil.ShowTips("请先回报实绩,完成委托!"); return; } StlLgEntrustBillEntity stlLgEntity = (StlLgEntrustBillEntity)uRow.ListObject; string stlLgTity = JSONFormat.Format(stlLgEntity); if (MessageUtil.ShowYesNoAndQuestion("是否确认该委托实绩?") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim"; ccp.MethodName = "doAffrim"; ccp.ServerParams = new object[] { stlLgTity,UserInfo.GetUserName() }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("确认成功!")) { doQueryEntrustBill(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 撤销确认 /// private void cancelDoAffrim() { this.ultraGrid1.UpdateData(); UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (uRow == null) return; StlLgEntrustBillEntity stlLgEntity = (StlLgEntrustBillEntity)uRow.ListObject; string stlLgTity = JSONFormat.Format(stlLgEntity); if (MessageUtil.ShowYesNoAndQuestion("是否撤销确认?") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim"; ccp.MethodName = "cancelDoAffrim"; ccp.ServerParams = new object[] { stlLgTity,this.UserInfo.GetUserName() }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("撤销成功!")) { doQueryEntrustBill(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 委外完成 /// private void subcontractComplete() { this.ultraGrid2.UpdateData(); int toalNum = 0; string dbWgt = "";//单倍尺重量 decimal quailToalWgt = 0;//合格总重量 UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (uRow == null) { MessageUtil.ShowTips("请选择对应委托回报实绩信息!"); return; } IQueryable checkMags = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'"); if(checkMags.Count() == 0) { MessageUtil.ShowTips("请勾选所回报实绩!"); return; } if (!CheckQuerySub()) return; StlLgEntrustBillEntity stlEntrust = (StlLgEntrustBillEntity)uRow.ListObject; string stlLgEntrustTity = JSONFormat.Format(stlEntrust); DataTable ds = ServerHelper.GetData("Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim.doQueryDbWgt", new object[] { stlLgEntrustTity }, ob); if(ds.Rows.Count>0) { dbWgt = ds.Rows[0]["WEIGHT_GP_ONE"].ToString(); } ArrayList parm = new ArrayList(); foreach (UltraGridRow row in checkMags) { StlLgEntrustBillDetialEntity stlLgEntrustDetial = (StlLgEntrustBillDetialEntity)row.ListObject; if (int.Parse(stlLgEntrustDetial.ComFixNum.ToString3()) > int.Parse(uRow.Cells["FixNum"].Text)) { MessageUtil.ShowTips("回报的倍尺数不允许比原倍尺大"); return; } if (stlLgEntrustDetial.SubcontractcompleteNum * stlLgEntrustDetial.ComFixNum == stlEntrust.FixNum * stlEntrust.SubcontractNum) { stlLgEntrustDetial.SubcontractCompleteWgt = stlEntrust.SubcontractWgt; } else { stlLgEntrustDetial.SubcontractCompleteWgt = int.Parse(stlLgEntrustDetial.ComFixNum.ToString()) * int.Parse(stlLgEntrustDetial.SubcontractcompleteNum.ToString()) * decimal.Parse(dbWgt); } stlLgEntrustDetial.ComLength = int.Parse(stlEntrust.Length.ToString()) * int.Parse(stlLgEntrustDetial.ComFixNum.ToString()) / int.Parse(stlEntrust.FixNum.ToString()); string stlLgEntrustDetialTity = JSONFormat.Format(stlLgEntrustDetial); parm.Add(stlLgEntrustDetialTity); toalNum = toalNum + int.Parse(row.Cells["SubcontractcompleteNum"].Text.Trim().ToString3()) * int.Parse(row.Cells["ComFixNum"].Text.Trim().ToString3()) + int.Parse(row.Cells["SubcontractscrapNum"].Text.Trim().ToString3()) * int.Parse(row.Cells["ComFixNum"].Text.Trim().ToString3()); quailToalWgt = quailToalWgt + decimal.Parse(stlLgEntrustDetial.SubcontractCompleteWgt.ToString()); } //int subToalNum = int.Parse(stlEntrust.SubcontractNum.ToString())*int.Parse(stlEntrust.FixNum.ToString());//委托单倍坯支数 DataTable subToalNumDs = ServerHelper.GetData("Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim.doQueryDbTrust", new object[] { stlLgEntrustTity }, ob); int subToalNum = int.Parse(subToalNumDs.Rows[0][0].ToString3()); if (subToalNum >= toalNum) { StlLgEntrustBillDetialEntity stlLgEntrustDetialScrap = new StlLgEntrustBillDetialEntity(); stlLgEntrustDetialScrap.SubcontractscrapNum = subToalNum - toalNum; stlLgEntrustDetialScrap.SubcontractscrapWgt = decimal.Parse(stlEntrust.SubcontractWgt.ToString()) - quailToalWgt; stlLgEntrustDetialScrap.ComFixNum = 1; stlLgEntrustDetialScrap.ComLength = stlEntrust.FixLen; string stlLgDetialScrap = JSONFormat.Format(stlLgEntrustDetialScrap); parm.Add(stlLgDetialScrap); } else { MessageUtil.ShowTips("回报的单倍尺支数不能比原单倍尺支数多!"); return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim"; ccp.MethodName = "subcontractComplete"; ccp.ServerParams = new object[] { stlLgEntrustTity,parm }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("回报成功!")) { doQueryEntrustBill(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 撤销委外完成 /// private void cancelSubcontractComplete() { this.ultraGrid1.UpdateData(); UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (uRow == null) { MessageUtil.ShowTips("请选择需要撤销回报实绩的委托信息!"); return; } StlLgEntrustBillEntity stlEntrust = (StlLgEntrustBillEntity)uRow.ListObject; string stlLgEntrustTity = JSONFormat.Format(stlEntrust); if (MessageUtil.ShowYesNoAndQuestion("是否确认撤销?") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim"; ccp.MethodName = "cancelSubcontractComplete"; ccp.ServerParams = new object[] { stlLgEntrustTity }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) { if (ccp.ReturnInfo.Equals("撤销成功!")) { doQueryEntrustBill(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } /// /// 查询委托 /// private void doQueryEntrustBill() { string startTim = ""; string endTim = ""; string judgeNo = ""; string subContractNo = ""; string[] arr = BaseMethod.InitLgPermissions(this.ValidDataPurviewIds,"B", this.ob); if (!CheckQuery()) return; if (this.chkTim2.Checked) { startTim = this.StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); endTim = this.EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss"); } if (this.chkJugeNo.Checked) { judgeNo = this.txtJugeNo.Text.Trim(); } if (this.chkSubContractNo.Checked) { subContractNo = this.txtSubContractNo.Text.Trim(); } ArrayList parm = new ArrayList(); parm.Add(subContractNo); parm.Add(judgeNo); List listSource = EntityHelper.GetData( "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim.doQueryEntrustBill", new object[] { parm, startTim, endTim, arr }, this.ob); StlLgEntrustBillEntitybindingSource.DataSource = listSource; } /// /// 数据验证 /// /// private bool CheckQuery() { if (this.chkSubContractNo.Checked && string.IsNullOrEmpty(this.txtSubContractNo.Text.Trim())) { MessageUtil.ShowWarning("请输入委托单号!"); return false; } if (this.chkJugeNo.Checked && string.IsNullOrEmpty(this.txtJugeNo.Text.Trim())) { MessageUtil.ShowWarning("请输入判定炉号!"); return false; } return true; } /// /// 对录入数据验证 /// /// private bool CheckQuerySub() { this.ultraGrid2.UpdateData(); UltraGridRow uRow = this.ultraGrid1.ActiveRow; var checkMags = this.ultraGrid2.Rows.Where(a=>a.GetValue("CHK") == "True"); int groupCnt = checkMags.GroupBy(a => a.GetValue("ComFixNum")).Count(); if (groupCnt != checkMags.Count()) { MessageUtil.ShowTips("同样倍尺数的需回报在一行!"); return false; } int toalNum = 0;//回报的总单倍支数 foreach (UltraGridRow row in checkMags) { if(!StringUtil.IsInt(row.Cells["ComFixNum"].Text.Trim())) { MessageUtil.ShowTips("倍尺请输入整数!"); return false; } //if (!StringUtil.IsInt(row.Cells["ComLength"].Text.Trim())) //{ // MessageUtil.ShowTips("坯长度请输整数!"); // return false; //} //if (row.Cells["SubcontractcompleteNum"].Text.Trim() != ""&& row.Cells["SubcontractcompleteNum"].Text.Trim() !="0") //{ // if (row.Cells["SubcontractCompleteWgt"].Text.Trim() == "" || row.Cells["SubcontractCompleteWgt"].Text.Trim() == "0") // { // MessageUtil.ShowTips("合格支数有时,不允许无合格重量!"); // return false; // } //} //if (row.Cells["SubcontractCompleteWgt"].Text.Trim() != "" && row.Cells["SubcontractCompleteWgt"].Text.Trim() != "0") //{ // if (row.Cells["SubcontractcompleteNum"].Text.Trim() == "" || row.Cells["SubcontractcompleteNum"].Text.Trim() == "0") // { // MessageUtil.ShowTips("合格重量有时,不允许无合格支数!"); // return false; // } //} //if (row.Cells["SubcontractscrapNum"].Text.Trim() != "" && row.Cells["SubcontractscrapNum"].Text.Trim() != "0") //{ // if (row.Cells["SubcontractscrapWgt"].Text.Trim() == "" || row.Cells["SubcontractscrapWgt"].Text.Trim() == "0") // { // MessageUtil.ShowTips("废品支数有时,不允许无废品重量!"); // return false; // } //} //if (row.Cells["SubcontractscrapWgt"].Text.Trim() != "" && row.Cells["SubcontractscrapWgt"].Text.Trim() != "0") //{ // if (row.Cells["SubcontractscrapNum"].Text.Trim() == "" || row.Cells["SubcontractscrapNum"].Text.Trim() == "0") // { // MessageUtil.ShowTips("废品重量有时,不允许无废品支数!"); // return false; // } //} if (row.Cells["SubcontractcompleteNum"].Text.Trim() != "") { if (!StringUtil.IsInt(row.Cells["SubcontractcompleteNum"].Text.Trim())) { MessageUtil.ShowTips("合格支数请输入整数!"); return false; } } //if (row.Cells["SubcontractCompleteWgt"].Text.Trim() != "") //{ // if (!StringUtil.IsDouble(row.Cells["SubcontractCompleteWgt"].Text.Trim())) // { // MessageUtil.ShowTips("合格重量请输入小数或者整数!"); // return false; // } //} //if (row.Cells["SubcontractscrapNum"].Text.Trim() != "") //{ // if (!StringUtil.IsInt(row.Cells["SubcontractscrapNum"].Text.Trim())) // { // MessageUtil.ShowTips("废品支数请输入整数!"); // return false; // } //} //if (row.Cells["SubcontractscrapWgt"].Text.Trim() != "") //{ // if (!StringUtil.IsDouble(row.Cells["SubcontractscrapWgt"].Text.Trim())) // { // MessageUtil.ShowTips("废品重量请输入小数或者整数!"); // return false; // } //} toalNum = toalNum + int.Parse(row.Cells["SubcontractcompleteNum"].Text.Trim().ToString3()) * int.Parse(row.Cells["ComFixNum"].Text.Trim().ToString3()) + int.Parse(row.Cells["SubcontractscrapNum"].Text.Trim().ToString3()) * int.Parse(row.Cells["ComFixNum"].Text.Trim().ToString3()); } //if (int.Parse(uRow.Cells["SubcontractNum"].Text.Trim()) * int.Parse(uRow.Cells["FixNum"].Text.Trim()) != toalNum) //{ // MessageUtil.ShowTips("委外加工支数与回报实绩支数不符!"); // return false; //} return true; } private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { UltraGridRow uRow = this.ultraGrid1.ActiveRow; if (uRow == null) return; ArrayList list = new ArrayList(); list.Add(uRow.Cells["SubcontractNo"].Text); list.Add(uRow.Cells["StoveNo"].Text); list.Add(uRow.Cells["JudgeStoveNoSeq"].Text); list.Add(uRow.Cells["SubcontractNoSeq"].Text); StlLgEntrustBillDetialEntitybindingSource.Clear(); List listSource = EntityHelper.GetData( "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim.doQueryEntrustBillDetial", new object[] { list }, this.ob); StlLgEntrustBillDetialEntitybindingSource.DataSource = listSource; } private void chkTim2_CheckedChanged(object sender, EventArgs e) { this.StartTime.Enabled = this.EndTime.Enabled = this.chkTim2.Checked; } private void chkJugeNo_CheckedChanged(object sender, EventArgs e) { this.txtJugeNo.Enabled = this.chkJugeNo.Checked; } private void chkSubContractNo_CheckedChanged(object sender, EventArgs e) { this.txtSubContractNo.Enabled = this.chkSubContractNo.Checked; } private void txtJugeNo_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13) { doQueryEntrustBill(); } } } }