using com.steering.mes.mcp.entity; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Format; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.Mcp.Control; using Core.StlMes.Client.Mcp.Entity; using CoreFS.CA06; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinGrid; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Windows.Forms; namespace Core.StlMes.Client.Mcp.CollarLibrary { public partial class FrmJGPurchasePlan : FrmBase { public FrmJGPurchasePlan() { InitializeComponent(); this.IsLoadUserView = true; } private void FrmCollarInventory_Load(object sender, EventArgs e) { RegStartTime.Value = DateTime.Parse(DateTime.Today.ToString("yyyy-MM-dd") + " 00:00:00"); RegEndTime.Value = DateTime.Parse(DateTime.Today.AddDays(1).AddSeconds(-1).ToString("yyyy-MM-dd") + " 23:59:59"); EntityHelper.ShowGridCaption(ultraGrid2.DisplayLayout.Bands[0]); PipeManageClass.setUltraGridColumnInput(ultraGrid2, new string[] { "DealNum" });//支数 PipeManageClass.setUltraGridColumnMaxInput(ultraGrid2, new string[] { "DealWt" });//重量 InitGrade(TxtGrade,ob); InitSpec(TxtSpcName, ob); InitModel(TxtModel, ob); InitSteel(TxtSteelCode, ob); InitStdName(TxtStdName, ob); } /// /// 初始化下拉框钢种 /// /// /// public static void InitGrade(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.CollarLibrary.FrmCollarInventory.getGrade", new object[] { }, ob); InitComboEditor(uce, dt, "GRADENAME", "GRADECODE"); } /// /// 获取规格 /// /// /// public static void InitSpec(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.ydm.bc.BaseOperations.getSpc", new object[] { }, ob); InitComboEditor(uce, dt, "SPEC_NAME", "SPEC_CODE"); } /// /// 获取扣型 /// /// /// public static void InitModel(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.ydm.bc.BaseOperations.getModel", new object[] { }, ob); InitComboEditor(uce, dt, "MODEL_DESC", "MODEL_CODE"); } /// /// 获取钢级 /// /// /// public static void InitSteel(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.ydm.bc.BaseOperations.getSteel", new object[] { }, ob); InitComboEditor(uce, dt, "STEELNAME", "STEELCODE"); } /// /// 获取标准名称 /// public static void InitStdName(UltraComboEditor uce, OpeBase ob) { DataTable dt = ServerHelper.GetData("com.steering.ydm.bc.BaseOperations.getStdName", new object[] { }, ob); InitComboEditor(uce, dt, "STD_NAME", "STD_CODE"); } /// /// 初始下拉框 /// /// /// /// /// public static void InitComboEditor(UltraComboEditor uce, DataTable dt, String showName, String hideValue) { uce.DataSource = dt; uce.DisplayMember = showName; uce.ValueMember = hideValue; } /// /// 重写基类方法 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": doQuery(); break; case "Add": doAdd(); break; case "Delete": doDelete(); break; case "Export": GridHelper.ulGridToExcel(ultraGrid2, "接箍采购计划"); break; case "Close": this.Close(); break; } } private void doQuery() { // 创建查询参数对象 var queryParams = new JgPurchasePlanQueryParams(); if (chkRegTime.Checked) { // 添加日期区间查询 if (chkRegTime.Checked) { queryParams.CreateTimeStart = RegStartTime.Value.ToString("yyyy-MM-dd"); queryParams.CreateTimeEnd = RegEndTime.Value.ToString("yyyy-MM-dd"); } } if (!CheckQuery()) return; // 设置查询条件 if (chkPlanNo.Checked) { queryParams.Planno = txtPlanNo.Text.Trim(); } /* if (chkStatus.Checked) { queryParams.Status = Convert.ToInt32(cmbStatus.SelectedValue); } if (chkContractNo.Checked) { queryParams.ContractNo = txtContractNo.Text.Trim(); } if (chkSgSign.Checked) { queryParams.SgSign = txtSgSign.Text.Trim(); }*/ // 配置 JSON 序列化设置 var jsonSettings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; // 序列化查询参数 string conditionJson = JsonConvert.SerializeObject(queryParams, jsonSettings); List listSource = EntityHelper.GetData ("com.steering.mes.mcp.CollarLibrary.FrmCollarInventory.queryPurchasePlan", new object[] { conditionJson }, this.ob); couplingMatDealEntityBindingSource.DataSource = listSource; GridHelper.RefreshAndAutoSize(ultraGrid2); } ///查询时验证必填项 private bool CheckQuery() { if (DataTimeUtil.JudgeTime(DateTime.Parse(RegStartTime.Value.ToString()), DateTime.Parse(RegEndTime.Value.ToString())) == 0) { MessageUtil.ShowTips("开始时间不能大于结束时间!"); return false; } return true; } /// /// 验证Checked是否勾选,显示控件可编辑 打勾表示可编辑,不打勾表示不可编辑 /// /// /// private void chk_CheckedChanged(object sender, EventArgs e) { if (chkPlanNo.Checked) { txtPlanNo.Enabled = true; } else { txtPlanNo.Enabled = false; } if (chkRegTime.Checked) { RegStartTime.Enabled = true; RegEndTime.Enabled = true; } else { RegStartTime.Enabled = false; RegEndTime.Enabled = false; } } //新增时验证必填项 private string CheckAdd() { if (TxtNum.Value == null || string.IsNullOrEmpty(TxtNum.Value.ToString()) || Convert.ToDouble(TxtNum.Value.ToString()) <= 0) { return "请输入个数!"; } if (TxtSpcName.Value == null || string.IsNullOrEmpty(TxtSpcName.Value.ToString())) { return "请选择规格!"; } if (TxtSteelCode.Value == null || string.IsNullOrEmpty(TxtSteelCode.Value.ToString())) { return "请选择钢级!"; } if (TxtModel.Value == null || string.IsNullOrEmpty(TxtModel.Value.ToString())) { return "请选择扣型!"; } if (TxtStdName.Value == null || string.IsNullOrEmpty(TxtStdName.Value.ToString())) { return "请选择标准!"; } if (TxtGrade.Value == null || string.IsNullOrEmpty(TxtGrade.Value.ToString())) { return "请选择钢种!"; } return ""; } private JgPurchasePlanEntity GetAddData() { JgPurchasePlanEntity entity = new JgPurchasePlanEntity(); // 基础信息 entity.Quantity = TxtNum.Value?.ToString()??"0"; entity.Spec = TxtSpcName.Text?.Trim() ?? ""; entity.SpecNo = TxtSpcName.Value?.ToString() ?? ""; entity.SgSign = TxtSteelCode.Text?.Trim() ?? ""; entity.SgSignCode = TxtSteelCode.Value?.ToString() ?? ""; entity.BuckleType = TxtModel.Text?.Trim() ?? ""; entity.BuckleTypeCode = TxtModel.Value?.ToString() ?? ""; entity.SgStd = TxtStdName.Text?.Trim() ?? ""; entity.SgStdCode = TxtStdName.Value?.ToString() ?? ""; entity.SteelType = TxtGrade.Text?.Trim() ?? ""; entity.Length = TxtLength.Value?.ToString() ??""; // 从规格获取外径和壁厚 if (!string.IsNullOrEmpty(TxtDimater.Text)) { entity.OuterDiameter = TxtDimater.Text; } if (!string.IsNullOrEmpty(TxtHeight.Text)) { entity.WallThickness = TxtDimater.Text; } // 系统字段 entity.Creator = UserInfo.GetUserName(); return entity; } /// /// 新增 /// private void doAdd() { string errMessage = CheckAdd(); if (errMessage.Length > 0) { MessageUtil.ShowWarning(errMessage); return; } JgPurchasePlanEntity entity = GetAddData(); if (MessageUtil.ShowYesNoAndQuestion("是否新增接箍采购计划信息?") == DialogResult.No) { return; } CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "com.steering.mes.mcp.CollarLibrary.FrmCollarInventory"; ccp.MethodName = "addPurchasePlan"; ccp.ServerParams = new object[] { JSONFormat.Format(entity) }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode == -1) return; MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Equals("新增成功!")) { doQuery(); //clean(); } } /// /// 删除 /// private void doDelete() { UltraGridRow row = ultraGrid2.ActiveRow; if (row == null) return; int count = 0; ArrayList list = new ArrayList(); foreach (UltraGridRow uRow in ultraGrid2.Rows) { if (Convert.ToBoolean(uRow.Cells["CHOOSE"].Text) == true) { count += 1; list.Add(uRow.Cells["id"].Text.Trim()); } } if (count == 0) { MessageUtil.ShowTips("请选择要撤销的数据"); return; } if (MessageUtil.ShowYesNoAndQuestion("是否确认撤销?") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); try { this.Cursor = Cursors.WaitCursor; //控制鼠标的样式为等待 if (Constant.WaitingForm == null) { Constant.WaitingForm = new WaitingForm(); } Constant.WaitingForm.ShowToUser = true; Constant.WaitingForm.Show(); Constant.WaitingForm.Update(); ccp.ServerName = "com.steering.mes.mcp.CollarLibrary.FrmCollarInventory"; ccp.MethodName = "deletePurchasePlan"; ccp.ServerParams = new object[] { list }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); this.Cursor = Cursors.Default; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); Constant.WaitingForm = null; } catch (Exception ex) { this.Cursor = Cursors.Default; Constant.WaitingForm.ShowToUser = false; Constant.WaitingForm.Close(); Constant.WaitingForm = null; } if (ccp.ReturnCode == -1) return; MessageUtil.ShowTips(ccp.ReturnInfo); if (ccp.ReturnInfo.Equals("撤销成功!")) { doQuery(); } } private void ultraGrid2_AfterSelectChange(object sender, AfterSelectChangeEventArgs e) { try { ultraGrid2.UpdateData(); foreach (UltraGridRow r in ultraGrid2.Rows) { r.Cells["CHOOSE"].Value = r.Selected; } } catch { } } private void TxtNum_ValueChanged(object sender, EventArgs e) { string count = "0"; if (!TxtNum.Value.Equals("")) { count = TxtNum.Value.ToString(); } } private void clean() { // 清空输入控件 TxtSteelCode.Text = ""; TxtSteelCode.Value = null; TxtModel.Text = ""; TxtModel.Value = null; TxtNum.Value = "0"; TxtSpcName.Text = ""; TxtSpcName.Value = null; TxtStdName.Text = ""; TxtStdName.Value = null; TxtGrade.Text = ""; TxtGrade.Value = null; TxtDimater.Text = ""; TxtHeight.Text = ""; } ArrayList pram = new ArrayList(); private void TxtSpcName_TextChanged(object sender, EventArgs e) { string strSpec = ""; if (this.TxtSpcName.Value == null) { return; } else { strSpec = TxtSpcName.Value.ToString(); } pram.Clear(); pram.Add(strSpec); DataTable dt = ServerHelper.GetData("com.steering.mes.mcp.CollarLibrary.FrmCollarInventory.getDimHeig", new object[] { pram }, this.ob); if (dt.Rows.Count > 0) { if (dt.Rows[0]["DIMATER"].ToString() != "") { TxtDimater.Text = string.Format("{0:F2}", Convert.ToDouble(dt.Rows[0]["DIMATER"].ToString())); if (!dt.Rows[0]["HEIGHT"].ToString().Equals("")) { TxtHeight.Text = string.Format("{0:F2}", Convert.ToDouble(dt.Rows[0]["HEIGHT"].ToString())); } else { TxtHeight.Text = ""; } } else { TxtDimater.Text = "0.00"; TxtHeight.Text = "0.00"; } } } } }