using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using CoreFS.CA06;using Pur.Entity; using Infragistics.Win.UltraWinGrid; using Infragistics.Win; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm; using Core.Mes.Client.Comm.Tool; using Pur.Entity.configureEntity; using System.Collections; using Pur.Entity.require_planEntiy; using com.hnshituo.pur.vo; using Infragistics.Win.UltraWinEditors; using CoreFS.SA06; namespace Pur.require_plan { public partial class FrmPurRePlanChangeNew: FrmPmsBase { private string tips1="0"; ArrayList list = new ArrayList();//待编制的需求行 ArrayList listItemAttr = new ArrayList();//待编制的物料属性 DataTable dtAttr = new DataTable(); DataTable dtUom = new DataTable(); DataTable dtStandards = new DataTable(); public string Tips //是否需要刷新界面 { get { return tips1; } set { tips1 = value; } } public FrmPurRePlanChangeNew() { InitializeComponent(); } public FrmPurRePlanChangeNew(OpeBase ob, ArrayList str) { this.ob = ob; this.list = str; InitializeComponent(); } private void FrmPurRePlanChangeNew_Load(object sender, EventArgs e) { dtAttr.Columns.AddRange(new DataColumn[] { new DataColumn("Code"), new DataColumn("Desc") }); dtAttr.PrimaryKey = new DataColumn[] { dtAttr.Columns["Code"] }; dtUom.Columns.AddRange(new DataColumn[] { new DataColumn("Code"), new DataColumn("Desc") }); dtUom.PrimaryKey = new DataColumn[] { dtUom.Columns["Code"] }; dtStandards.Columns.AddRange(new DataColumn[] { new DataColumn("Code"), new DataColumn("Desc") }); dtStandards.PrimaryKey = new DataColumn[] { dtStandards.Columns["Code"] }; //ultraPanel2.Visible = false; ck_ftime.Checked = false; txt_ForcasTimeEnd.Enabled = false; txt_ForcasTimeStart.Enabled = false; txt_ForcasTimeEnd.Value = DateTime.Now.AddMonths(-2); txt_ForcasTimeStart.Value = DateTime.Now.AddDays(1); txt_UrgencyType.SelectedIndex = 0; //data_MrPeriodEnd.Enabled = false; if (DateTime.Now.Month == 2) { data_MrPeriodEnd.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/28")) ? DateTime.Parse(DateTime.Now.ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM")); } else { data_MrPeriodEnd.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/30")) ? DateTime.Parse(DateTime.Now.ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM")); } GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] { "newitemUom", "newitemattr", "newitemStandardsCode", "CHECK", "LASTDELIVERYDATE" }); GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[1], new string[] { }); GridHelper.SetExcludeColumnsActive(ultraGrid2.DisplayLayout.Bands[0], new string[] { "UseQty","CHK" }); GridHelper.SetExcludeColumnsActive(ultraGrid3.DisplayLayout.Bands[0], new string[] { "CHK" }); ultraExpandableGroupBox1.Expanded = false; ck_hasOrderQty.Checked = true; initM(); } #region 初始化区域 //重新组合数据 private void reConfig(DataTable dt) { try { dataSet1.Clear(); dataSet2.Clear(); dataSet3.Clear(); DataTable dttest = dt.Copy(); DataTable dt1 = dt.Copy(); //删除父表中没有的需求订单行 for (int i = 0; i < dttest.Rows.Count; i++) { String StrItemUnique = dttest.Rows[i]["newItemUnique"].ToString().Trim(); int cou = 0; for (int j = dt.Rows.Count - 1; j >= 0; j--) { //DataRow rowt = dt.Rows[j]; if (dt.Rows[j]["newItemUnique"].ToString().Trim() == StrItemUnique) { cou = cou + 1; if (cou == 1) { //rowt = dt.Rows[j]; } if (cou >= 2) { //rowt["SQTYPUR"] = Convert.ToDouble(rowt["SQTYPUR"])+ Convert.ToDouble(dt.Rows[j]["SQTYPUR"]); //rowt["Num"] = Convert.ToDouble(rowt["Num"]) + Convert.ToDouble(dt.Rows[j]["Num"]); dt.Rows.RemoveAt(j); } } } } GridHelper.CopyDataToDatatable(dt, dataTable1, true); foreach (DataRow rows in dt1.Rows) { rows["qtypur"]=rows["qty"]; } GridHelper.CopyDataToDatatable(dt1, dataTable2, true); foreach (UltraGridRow rowg in ultraGrid1.Rows) { if (rowg.HasChild()) { double numall = 0; //double SQTYPURall = 0; foreach (UltraGridRow rowc in rowg.ChildBands[0].Rows) { numall = numall + Convert.ToDouble(rowc.GetCellValue("Qty")); //SQTYPURall = Convert.ToDouble(rowc.GetCellValue("SQTYPUR")); } rowg.Cells["Num"].Value = numall; rowg.Cells["SQTYPUR"].Value = numall; } } GridHelper.RefreshAndAutoSize(ultraGrid1); } catch (Exception ex) { MessageUtil.ShowTips("初始化或刷新界面失败:" + ex); } } #endregion #region 界面事件 private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { if (ultraGrid1.ActiveRow != null && !ultraGrid1.ActiveRow.HasParent()) { UltraGridRow row = ultraGrid1.ActiveRow; //非激活本行 foreach (UltraGridRow rows in ultraGrid1.DisplayLayout.Bands[0].GetRowEnumerator(GridRowType.DataRow)) { if (rows.GetCellValue("id").ToString() != row.GetCellValue("id").ToString()) { rows.Cells["newitemStandardsCode"].Value = rows.Cells["newitemStandardsCode"].Text; rows.Cells["newitemAttr"].Value = rows.Cells["newitemAttr"].Text; rows.Cells["newItemUom"].Value = rows.Cells["newItemUom"].Text; } } //更具子行调整填写dt dtAttr.Clear(); dtStandards.Clear(); dtUom.Clear(); foreach (UltraGridRow rowc in row.ChildBands[0].Rows) { //填充dropDownlist源数据 if (!dtAttr.Rows.Contains(rowc.GetCellValue("itemAttrId")) && rowc.GetCellValue("itemAttrId").ToString().Trim() != "") { dtAttr.Rows.Add(rowc.GetCellValue("itemAttrId"), rowc.GetCellValue("itemAttr")); } if (!dtUom.Rows.Contains(rowc.GetCellValue("itemUomId")) && rowc.GetCellValue("itemUomId").ToString().Trim() != "") { dtUom.Rows.Add(rowc.GetCellValue("itemUomId"), rowc.GetCellValue("itemUom")); } if (!dtStandards.Rows.Contains(rowc.GetCellValue("itemStandardsId")) && rowc.GetCellValue("itemStandardsId").ToString().Trim() != "") { dtStandards.Rows.Add(rowc.GetCellValue("itemStandardsId"), rowc.GetCellValue("itemStandardsCode")); } } //激活本行 String strItemCode = row.GetCellValue("itemCode").ToString().Trim(); String strnewitemAttr = row.GetCellValue("newitemAttr").ToString().Trim(); String strnewitemStandardsCode = row.GetCellValue("newitemStandardsCode").ToString().Trim(); String strnewItemUom = row.GetCellValue("newItemUom").ToString().Trim(); String strnewitemStandardsId = row.GetCellValue("newitemStandardsId").ToString().Trim(); String strnewitemAttrId = row.GetCellValue("newitemAttrId").ToString().Trim(); String strnewitemUomId = row.GetCellValue("newitemUomId").ToString().Trim(); getDropDownListData(strItemCode); //row.Cells["newitemStandardsCode"].Value = row.GetCellValue("newitemStandardsId").ToString().Trim(); //row.Cells["newitemAttr"].Value = row.GetCellValue("newitemAttrId").ToString().Trim(); //row.Cells["newItemUom"].Value = row.GetCellValue("newitemUomId").ToString().Trim(); row.Cells["newitemStandardsCode"].Value = strnewitemStandardsCode; row.Cells["newitemAttr"].Value = strnewitemAttr; row.Cells["newItemUom"].Value = strnewItemUom; ultraGrid1.UpdateData(); } } // 数量输入 private void ultraGrid1_CellChange(object sender, CellEventArgs e) { if (e.Cell.Column.Key.Equals("newItemAttr") && !e.Cell.Row.HasParent()) { itemAttrValueChange(); } if (e.Cell.Column.Key.Equals("newItemUom") && !e.Cell.Row.HasParent()) { itemUomValueChange(); } if (e.Cell.Column.Key.Equals("newItemStandardsCode") && !e.Cell.Row.HasParent()) { standardsValueChange(); } //采购数据计算 double qt = 0; if (e.Cell.Column.Key.Equals("qtyPur") && e.Cell.Row.HasParent()) { object oldv = e.Cell.Row.Cells["qtyPur"].Value; ultraGrid1.UpdateData(); object newv = e.Cell.Row.Cells["qtyPur"].Value; double reqty = Convert.ToDouble(e.Cell.Row.Cells["qty"].Value); if (newv != DBNull.Value) { if (Convert.ToDouble(newv) > reqty) { e.Cell.Row.Cells["qtyPur"].Value = oldv; return; } } string str = e.Cell.Row.Cells["newItemUnique"].Value.ToString(); foreach (UltraGridRow cRow in e.Cell.Row.ParentRow.ChildBands[0].Rows) { if (cRow.Cells["qtyPur"].Value != DBNull.Value) { qt = qt + Convert.ToDouble(cRow.Cells["qtyPur"].Value); } } qt = qt + (e.Cell.Row.ParentRow.Cells["qtyYc"].Value == DBNull.Value ? 0 : Convert.ToDouble(e.Cell.Row.ParentRow.Cells["qtyYc"].Value)); e.Cell.Row.ParentRow.Cells["SQTYPUR"].Value = qt; return; } ////利库计算 //if (e.Cell.Column.Key.Equals("qtyLk") && !e.Cell.Row.HasParent()) //{ // object oldv = e.Cell.Row.Cells["qtyLk"].Value; // ultraGrid1.UpdateData(); // object newlk = e.Cell.Row.Cells["qtyLk"].Value; // object newYc = e.Cell.Row.Cells["qtyYc"].Value; // foreach (UltraGridRow cRow in e.Cell.Row.ChildBands[0].Rows) // { // if (cRow.Cells["qtyPur"].Value != DBNull.Value) // { // qt = qt + Convert.ToDouble(cRow.Cells["qtyPur"].Value); // } // } // // object purqty = e.Cell.Row.Cells["SQTYPUR"].Value; // qt = qt - (newlk == DBNull.Value ? 0 : Convert.ToDouble(newlk)) + (newYc == DBNull.Value ? 0 : Convert.ToDouble(newYc)); // if (qt < 0) // { // e.Cell.Row.Cells["qtyLk"].Value = oldv; // return; // } // e.Cell.Row.Cells["SQTYPUR"].Value = qt; // return; //} if (e.Cell.Column.Key.Equals("qtyYc") && !e.Cell.Row.HasParent()) { ultraGrid1.UpdateData(); //object newlk = e.Cell.Row.Cells["qtyLk"].Value; object newYc = e.Cell.Row.Cells["qtyYc"].Value; foreach (UltraGridRow cRow in e.Cell.Row.ChildBands[0].Rows) { if (cRow.Cells["qtyPur"].Value != DBNull.Value) { qt = qt + Convert.ToDouble(cRow.Cells["qtyPur"].Value); } } // object purqty = e.Cell.Row.Cells["SQTYPUR"].Value; qt = qt + (newYc == DBNull.Value ? 0 : Convert.ToDouble(newYc)); e.Cell.Row.Cells["SQTYPUR"].Value = qt; return; } } // 数量输入 //private void ultraGrid1_CellChange(object sender, CellEventArgs e) //{ // ultraGrid1.UpdateData(); // if (e.Cell.Column.Key.Equals("qtyPur")) // { // double qt = 0; // string str = e.Cell.Row.Cells["ITEMCODE"].Value.ToString(); // foreach (UltraGridRow uRows in ultraGrid1.Rows) // { // if (uRows.Cells["ITEMCODE"].Value.ToString() == str) // { // foreach (UltraGridRow cRow in uRows.ChildBands[0].Rows) // { // if (cRow.Cells["qtyPur"].Value.ToString() != "") // { // qt = qt + Convert.ToDouble(cRow.Cells["qtyPur"].Value); // } // } // uRows.Cells["SQTYPUR"].Value = qt; // return; // } // } // } //} // 物料属性选择事件 private void cmb_itemAttr_ValueChanged(object sender, EventArgs e) { itemAttrValueChange(); } private void itemAttrValueChange() { //根据获取来得改变新属性编码 if (ultraGrid1.ActiveRow != null && !ultraGrid1.ActiveRow.HasParent()) { ultraGrid1.UpdateData(); UltraGridRow uge = ultraGrid1.ActiveRow; string strnewItemAttrId = uge.GetCellValue("newItemAttr").ToString().Trim(); uge.Cells["newItemAttrId"].Value = strnewItemAttrId; //生成新unique //uge.Cells["newItemStandardsId"].Value = uge.GetCellValue("newItemStandardsCode").ToString().Trim(); uge.Cells["newItemUnique"].Value = uge.GetCellValue("itemCode").ToString().Trim() + "@" + strnewItemAttrId + "@" + uge.GetCellValue("newItemStandardsId").ToString().Trim() + "@" + uge.GetCellValue("newItemUomId").ToString().Trim(); ultraGrid1.UpdateData(); } } // 物料采购单位选择事件 private void cmb_Uom_ValueChanged(object sender, EventArgs e) { itemUomValueChange(); } private void itemUomValueChange() { //根据获取来得改变新单位编码,库存单位,转化系数 if (ultraGrid1.ActiveRow != null && !ultraGrid1.ActiveRow.HasParent()) { UltraGridRow uge = ultraGrid1.ActiveRow; //获取改变之前的转化系数 double oldCon = Convert.ToDouble(uge.GetCellValue("ItemUomConefficient").ToString().Trim()); ultraGrid1.UpdateData(); String strnewItemUomId = uge.GetCellValue("newItemUom").ToString().Trim(); //需改变数量 PurMatUomsEntity dt_matUOM = this.execute("com.hnshituo.pur.configure.service.MatUomsService", "findById", new object[] { strnewItemUomId }); if (dt_matUOM == null) { return; } double newCon = (double)dt_matUOM.ItemUomConefficient; double oldQtyPur = Convert.ToDouble(uge.GetCellValue("QtyPur").ToString().Trim()); double newQtyPur=0; if (oldCon != newCon) { newQtyPur = oldQtyPur * oldCon / newCon; uge.Cells["QtyPur"].Value = newQtyPur; uge.Cells["ItemUomConefficient"].Value = newCon; } uge.Cells["newItemUomId"].Value = strnewItemUomId;//记录新的单位换算ID //uge.Cells["newItemStandardsId"].Value = uge.GetCellValue("newItemStandardsCode").ToString().Trim(); uge.Cells["newItemUnique"].Value = uge.GetCellValue("itemCode").ToString().Trim() + "@" + uge.GetCellValue("newItemAttrId").ToString().Trim() + "@" + uge.GetCellValue("newItemStandardsId").ToString().Trim() + "@" + strnewItemUomId; ultraGrid1.UpdateData(); } } // 物料标准值选择事件 private void cmb_standard_ValueChanged(object sender, EventArgs e) { standardsValueChange(); } private void standardsValueChange() { //根据获取来得改变新编制编码 if (ultraGrid1.ActiveRow != null && !ultraGrid1.ActiveRow.HasParent()) { ultraGrid1.UpdateData(); UltraGridRow uge = ultraGrid1.ActiveRow; String strnewItemStandardsId = uge.GetCellValue("newItemStandardsCode").ToString().Trim(); uge.Cells["newItemStandardsId"].Value = strnewItemStandardsId; uge.Cells["newItemUnique"].Value = uge.GetCellValue("itemCode").ToString().Trim() + "@" + uge.GetCellValue("newItemAttrId").ToString().Trim() + "@" + strnewItemStandardsId + "@" + uge.GetCellValue("newItemUomId").ToString().Trim(); ultraGrid1.UpdateData(); } } #endregion #region 工具栏事件 //展开 private void btn_doExit_Click(object sender, EventArgs e) { ultraGrid1.Rows.ExpandAll(true); } //刷新界面 private void btn_doRefash_Click(object sender, EventArgs e) { initM(); } //初始化 private void initM() { DataTable dt = this.execute("com.hnshituo.pur.requireplan.service.RequireReceiveService", "getReceivedReqByList", new object[] { list }); foreach (DataRow row in dt.Rows) { row["itemDescE"] = Convert.ToDateTime(row["itemDescE"]).ToString("yyyy/MM"); } dt.Columns.Add("newItemUom", Type.GetType("System.String")); dt.Columns.Add("newWeightUnit", Type.GetType("System.String")); dt.Columns.Add("newITEMUOMCONEFFICIENT", Type.GetType("System.String")); dt.Columns.Add("newItemUomId", Type.GetType("System.String")); dt.Columns.Add("newItemStandardsCode", Type.GetType("System.String")); dt.Columns.Add("newItemStandardsId", Type.GetType("System.String")); dt.Columns.Add("newItemAttrId", Type.GetType("System.String")); dt.Columns.Add("newItemAttr", Type.GetType("System.String")); dt.Columns.Add("newItemUnique", Type.GetType("System.String")); foreach (DataRow rows in dt.Rows) { rows["newItemUnique"] = rows["itemUnique"]; rows["newItemUomId"] = rows["itemUomId"]; rows["newItemUom"] = rows["itemUom"]; rows["newWeightUnit"] = rows["weightUnit"]; rows["newITEMUOMCONEFFICIENT"] = rows["ITEMUOMCONEFFICIENT"]; rows["newItemStandardsCode"] = rows["itemStandardsCode"]; rows["newItemStandardsId"] = rows["itemStandardsId"]; rows["newItemAttrId"] = rows["itemAttrId"]; rows["newItemAttr"] = rows["itemAttr"]; } reConfig(dt); } //确定按钮 private void btn_doSaveChange_Click(object sender, EventArgs e) { ultraGrid1.UpdateData(); doChange(); } //调整 private void doChange() { if (ultraGrid1.Rows.Count > 0) { try { //调整前数据判定 int i = 0; string strItemCode = ""; foreach (UltraGridRow rows in ultraGrid1.Rows) { if (Convert.ToBoolean(rows.GetCellValue("CHECK"))) { i = i + 1; if (i != 1) { if (rows.GetCellValue("itemCode").ToString().Trim() != strItemCode) { MessageUtil.ShowTips("只能合并相同物料!"); rows.Activate(); return; } } else { strItemCode = rows.GetCellValue("itemCode").ToString().Trim(); } } } if (i == 0) { MessageUtil.ShowTips("请选择需调整的需求行"); return; } //保存调整数据 DataTable dtC = dataTable2.Copy(); //调整数据 int j = 0; String strnewitemAttr = ""; String strnewitemStandardsCode = ""; String strnewItemUom = ""; String strnewWeightUnit = ""; String strnewITEMUOMCONEFFICIENT = ""; String strnewitemStandardsId = ""; String strnewitemAttrId = ""; String strnewitemUomId = ""; String strnewItemUnique = ""; foreach (UltraGridRow row in ultraGrid1.Rows) { if (Convert.ToBoolean(row.GetCellValue("CHECK"))) { j = j + 1; if (j == 1) { strnewitemStandardsId = row.GetCellValue("newitemStandardsId").ToString().Trim(); strnewitemStandardsCode = row.GetCellValue("newitemStandardsCode").ToString().Trim(); strnewItemUom = row.GetCellValue("newItemUom").ToString().Trim(); strnewWeightUnit = row.GetCellValue("newWeightUnit").ToString().Trim(); strnewITEMUOMCONEFFICIENT = row.GetCellValue("newITEMUOMCONEFFICIENT").ToString().Trim(); strnewitemUomId = row.GetCellValue("newitemUomId").ToString().Trim(); strnewitemStandardsId = row.GetCellValue("newitemStandardsId").ToString().Trim(); strnewitemAttrId = row.GetCellValue("newitemAttrId").ToString().Trim(); strnewitemAttr = row.GetCellValue("newitemAttr").ToString().Trim(); strnewitemUomId = row.GetCellValue("newitemUomId").ToString().Trim(); strnewItemUnique = row.GetCellValue("newItemUnique").ToString().Trim(); } //开始调整操作---对所有的子行进行调整 foreach (UltraGridRow rowChild in row.ChildBands[0].Rows) { String strId = rowChild.GetCellValue("id").ToString().Trim(); //DataRow[] rows = dt_Purmatclass.Select("PID='" + Tnode.Key + "'"); DataRow[] roww = dtC.Select("id='" + strId + "'"); if (roww.Count() != 1) { MessageUtil.ShowTips("发现" + roww.Count()+"条" + strId + "接收需求计划行,数据异常!"); } roww[0]["newitemStandardsId"] = strnewitemStandardsId; roww[0]["newitemStandardsCode"] = strnewitemStandardsCode; roww[0]["newItemUom"] = strnewItemUom; roww[0]["newWeightUnit"] = strnewWeightUnit; roww[0]["newITEMUOMCONEFFICIENT"] = strnewITEMUOMCONEFFICIENT; roww[0]["newitemUomId"] = strnewitemUomId; roww[0]["newitemStandardsId"] = strnewitemStandardsId; roww[0]["newitemAttrId"] = strnewitemAttrId; roww[0]["newitemAttr"] = strnewitemAttr; roww[0]["newitemUomId"] = strnewitemUomId; roww[0]["newItemUnique"] = strnewItemUnique; roww[0]["itemUnique"] = strnewItemUnique; } } } //重组数据 if (MessageUtil.ShowYesNoAndQuestion("确定调整?") != DialogResult.Yes) { return; } reConfig(dtC); ultraGrid1.Refresh(); } catch (Exception ex) { MessageUtil.ShowTips("调整失败:" + ex); } } } //编制采购计划 private void doCreate() { //校验月份 if (data_MrPeriodEnd.Text == "") { MessageUtil.ShowTips("计划月份不能为空"); data_MrPeriodEnd.Focus(); return; } if (txt_UrgencyType.SelectedIndex == -1) { MessageUtil.ShowTips("请选择采购计划紧急程度类型!"); txt_UrgencyType.Focus(); return; } DataTable dt = this.execute("com.hnshituo.pur.requireplan.service.RequireReceiveService", "getReceivedReqByList", new object[] { list }); if (txt_UrgencyType.Value.ToString().Trim() != "1") { foreach (DataRow rr in dt.Rows) { if (Convert.ToDateTime(rr["itemDescE"]) > Convert.ToDateTime(data_MrPeriodEnd.Value)) { MessageUtil.ShowTips("需求计划行:" + rr["mrLineId"] + "的计划月份需小于待生成采购计划的计划月份!"); data_MrPeriodEnd.Focus(); return; } } } string strPurId = "";//采购单号 string strYcMrId = "";//预采需求单号 int tips = 0; //生成预采需求单行号 try { strPurId = this.execute("com.hnshituo.pur.utils.service.UtilsService", "genMrId", new object[] { 2 }); EntityPurPlanM PPM_Entity = new EntityPurPlanM(); PPM_Entity.MrId = strPurId; PPM_Entity.CreateName = UserInfo.GetUserName(); PPM_Entity.CreateTime = DateTime.Now; PPM_Entity.CreateUserid = UserInfo.GetUserID(); PPM_Entity.Validflag = "1"; PPM_Entity.Status = "1"; PPM_Entity.PlanType = "2"; PPM_Entity.MrPeriodEnd = DateTime.Parse(Convert.ToDateTime(data_MrPeriodEnd.Value).ToString("yyyy/MM")); //PPM_Entity.MrPeriodEnd = Convert.ToDateTime(data_MrPeriodEnd.Value); PPM_Entity.ReqOrgName = UserInfo.GetDepartment(); PPM_Entity.ReqOrgId = UserInfo.GetDeptid(); PPM_Entity.UrgencyType = txt_UrgencyType.Value.ToString().Trim(); PPM_Entity.PurType = "2";//采购类型,1预采,2普采 IQueryable uge = ultraGrid1.Rows.AsQueryable().Where("itemUnique != null"); int i = 1; int j = 1; ArrayList listRpD = new ArrayList();//需求计划行 ArrayList listReceiveRpD = new ArrayList();//接收需求计划行 ArrayList listPpd = new ArrayList();//采购计划行 //ArrayList ListYcReq = new ArrayList();//预采需求计划行 //RequirePlanM rem = new RequirePlanM();//预采需求计划头 foreach (UltraGridRow uRows in uge) { double b = 0; string mu = ""; string u = i.ToString(); while (u.Length < 3) { u = "0" + u; } mu += u; i++; //string mid = this.execute("com.hnshituo.pur.utils.service.UtilsService", "getOddNumber", new object[] { "PUR_PUR_PLAN_D", "MR_LINE_ID", str+"-", "3" }); MatEntity Mat = new MatEntity(); EntityPurPlanD EppD = new EntityPurPlanD(); EppD.MrId = strPurId; EppD.MrLineId = strPurId + "-" + mu; EppD.CreateName = UserInfo.GetUserName(); EppD.CreateUserid = UserInfo.GetUserID(); EppD.Validflag = "1"; EppD.CreateTime = DateTime.Now; EppD.QtyYc = uRows.Cells["QtyYc"].Value == DBNull.Value ? b : (Convert.ToDouble(uRows.Cells["QtyYc"].Value)); EppD.QtyYcUseable = EppD.QtyYc;//可分配数量 EppD.QtyYcUsed = 0;//已分配数量 EppD.PaymentCode = "110402";//默认付款方式 EppD.PackageType = "110702";//默认包装方式 EppD.ItemCode = uRows.Cells["ItemCode"].Value.ToString(); EppD.ItemName = uRows.Cells["ItemName"].Value.ToString(); EppD.ItemUom = uRows.Cells["newItemUom"].Text.ToString(); EppD.ItemAttrId = uRows.Cells["newITEMATTRID"].Value.ToString();//物料属性编码 EppD.ItemAttr = uRows.Cells["newITEMATTR"].Text.ToString();//物料属性名称 EppD.ItemUomConefficient = Convert.ToDouble(uRows.Cells["newItemUomConefficient"].Value); EppD.WeightUnit = uRows.Cells["newWeightUnit"].Value.ToString(); EppD.BugPrice = uRows.Cells["BugPrice"].Value == DBNull.Value ? b : Convert.ToDouble(uRows.Cells["BugPrice"].Value); EppD.Qty = uRows.Cells["SQTYPUR"].Value == DBNull.Value ? b : (Convert.ToDouble(uRows.Cells["SQTYPUR"].Value)); EppD.QtyPur = EppD.Qty; EppD.BudgetAmt = EppD.BugPrice * EppD.Qty * EppD.ItemUomConefficient; EppD.AskDeliverDate = Convert.ToDateTime(uRows.Cells["LASTDELIVERYDATE"].Value.ToString().Trim()); //2016年3月1号的新增leitao EppD.ItemStandardsCode =uRows.Cells["newItemStandardsCode"].Text.ToString().Trim(); EppD.ItemStandardsId = uRows.Cells["newItemStandardsId"].Value.ToString().Trim(); EppD.ItemUnique = uRows.Cells["newItemUnique"].Value.ToString().Trim(); EppD.ItemUomId = uRows.Cells["newItemUomId"].Value.ToString().Trim(); if ((EppD.Qty) > 0) { listPpd.Add(EppD); } //关系表和更新接收需求计划行 //IQueryable checkRow = uRows.ChildBands[0].Rows.AsQueryable().Where("itemUnique != null "); foreach (UltraGridRow cRow in uRows.ChildBands[0].Rows) { double db=cRow.Cells["qtyPur"].Value == DBNull.Value ? 0 : Convert.ToDouble(cRow.Cells["qtyPur"].Value); if (db > 0) { ////插入关系表 //ReqPurPlanR ReqR = new ReqPurPlanR(); //ReqR.PurLineId = EppD.MrLineId; //ReqR.CreateTime = DateTime.Now; //ReqR.RequireLineId = cRow.Cells["Id"].Value.ToString();//接收需求计划行信息 //ReqR.ID = cRow.Cells["Id"].Value.ToString() + EppD.MrLineId; //listRr.Add(ReqR); //更新接收需求表 RequireReceive ReqRev = new RequireReceive(); ReqRev.MrLineId = cRow.Cells["MrLineId"].Value.ToString(); ReqRev.Id = cRow.Cells["id"].Value.ToString(); ReqRev.QtyPur = cRow.Cells["qtyPur"].Value == DBNull.Value ? 0 : Convert.ToDouble(cRow.Cells["qtyPur"].Value);//默认的需求数量 ReqRev.Status = "2";//已编制 ReqRev.PurLineId = EppD.MrLineId;//绑定采购计划行 ReqRev.LjhTime = DateTime.Now; listReceiveRpD.Add(ReqRev); //更新需求计划 RequirePlanD ReqD = new RequirePlanD(); ReqD.MrLineId = cRow.Cells["MrLineId"].Value.ToString(); ReqD.FlagGeneratedPurPlan = "4"; listRpD.Add(ReqD); //校验接收需求计划行 //校验需求计划行 } } //生成预采需求计划 //if (EppD.QtyYc > 0) //{ // if (tips == 0) // { // //生成需求单号 // strYcMrId = this.execute("com.hnshituo.pur.utils.service.UtilsService", "genMrId", new object[] { 1 }); // rem.CreateName = UserInfo.GetUserName(); // rem.CreateUserid = UserInfo.GetUserID(); // rem.CreateTime = DateTime.Now; // rem.Status = "1"; // //ReqM.ReqOrgId = txt_REQ_ORG_ID.Text; // //ReqM.ReqOrgName = txt_REQORGNAME.Text; // //rem.MrPeriodEnd = Convert.ToDateTime(txt_MRPERIODEND.Text).Date; // //rem.MrPeriodStart = Convert.ToDateTime(txt_MRPERIODSTART.Text).Date; // rem.UrgencyType = "1"; // rem.ReqOrgName = UserInfo.GetDepartment();//申请者机构名称 // rem.ReqOrgId = UserInfo.GetDeptid();//申请者机构ID // rem.Validflag = "1"; // rem.RequireType = "122102";//生产性物料预采,系统自动生成 // rem.MrId = strYcMrId; // } // tips = tips + 1; // RequirePlanD ReqD = new RequirePlanD(); // string mu1 = ""; // string u1 = j.ToString(); // while (u1.Length < 3) // { // u1 = "0" + u1; // } // mu1 += u1; // j++; // //ReqD.MrLineId = this.execute("com.hnshituo.pur.requireplan.service.RequirePlanDService", "ReqMrLineId", new object[] { strYcMrId + "-" });//需求单行号//getCodeId(ultraGrid1.ActiveRow.Cells["mrId"].Value.ToString()); // ReqD.MrLineId = strYcMrId + "-" + mu1; // ReqD.MrId = strYcMrId; // ReqD.ItemCode = EppD.ItemCode; // ReqD.ItemName = EppD.ItemName; // ReqD.Remark = "由预采补充需求计划行信息"; // ReqD.BugPrice = EppD.BugPrice; // ReqD.ItemAttr = EppD.ItemAttr;//属性名称 // ReqD.ItemUom = EppD.ItemUom; // ReqD.WeightUnit = EppD.WeightUnit; // ReqD.ItemUomConefficient = EppD.ItemUomConefficient; // ReqD.BuyerDeptCode = ""; // ReqD.BuyerDeptDesc = ""; // ReqD.BuyerUnitCode = ""; // ReqD.BuyerUnitDesc = ""; // ReqD.Validflag = "1"; // ReqD.Qty = EppD.QtyYc; // ReqD.QtyPur = EppD.QtyYc; // ReqD.BudgetAmt = EppD.QtyYc * (ReqD.BugPrice == null ? 0 : ReqD.BugPrice); // ReqD.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName(); // ReqD.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID(); // ReqD.CreateTime = DateTime.Now; // ReqD.FlagGeneratedPurPlan = "1"; // //ReqD.LastDeliveryDate = EppD.; // //2016年2月28新增leitao // ReqD.DeliveryLocationFlag = "0"; // ReqD.DeliveryLocation = ""; // ReqD.DeliveryLocationCode = ""; // ReqD.ItemStandardsCode = EppD.ItemStandardsCode; // ReqD.ItemStandardsId = EppD.ItemStandardsId; // ReqD.ItemUomId = EppD.ItemUomId; // ReqD.ItemAttrId = EppD.ItemAttrId; // ReqD.ItemUnique = EppD.ItemUnique; // ReqD.AuditFlag = "1"; // ReqD.AuditMsg = "默认审批通过"; // ListYcReq.Add(ReqD); // //插入关系表 // ReqPurPlanR ReqR = new ReqPurPlanR(); // ReqR.PurLineId = EppD.MrLineId; // ReqR.CreateTime = DateTime.Now; // ReqR.RequireLineId = ReqD.MrLineId; // ReqR.ID = ReqD.MrLineId + EppD.MrLineId; // listRr.Add(ReqR); //} } if (MessageUtil.ShowYesNoAndQuestion("确定生成采购计划?") != DialogResult.Yes) { return; } CoreResult rt = this.execute("com.hnshituo.pur.purplan.service.PurPlanDService", "insert_four_New", new object[] { PPM_Entity, listRpD, listPpd,listReceiveRpD }); if (rt.Resultcode != 0) { Core.Mes.Client.Comm.Tool.MessageUtil.ShowWarning("生成采购计划失败! " + rt.Resultmsg); return; } if (tips > 0) { Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("成功,已生成采购计划: " + strPurId + " 和需求计划(预采-系统):" + strYcMrId + ""); tips1 = "1"; this.Close(); } else { Core.Mes.Client.Comm.Tool.MessageUtil.ShowTips("操作成功,已生成采购计划: " + strPurId + " "); tips1 = "1"; this.Close(); } } catch (Exception e1) { Core.Mes.Client.Comm.Tool.MessageUtil.ShowWarning("制单失败!" + e1); return; } } #endregion #region 公共函数 // 填充物料属性、标准值、单位dropDownList数据 private void getDropDownListData(String strItemCode) { getItemAttr(strItemCode); getMatStandard(strItemCode); getMatUOM(strItemCode); } // 获取物料属性 private void getItemAttr(String strItemCode) { if (!string.IsNullOrEmpty(strItemCode)) { cmb_itemAttr.DataSource = dtAttr; cmb_itemAttr.ValueMember = "Code"; cmb_itemAttr.DisplayMember = "Desc"; } } // 获取物料标准编号 private void getMatStandard(String strItemCode) { if (!string.IsNullOrEmpty(strItemCode)) { cmb_standard.DataSource = dtStandards; cmb_standard.ValueMember = "Code"; cmb_standard.DisplayMember = "Desc"; } } // 获取单位转换 private void getMatUOM(String strItemCode) { if (!string.IsNullOrEmpty(strItemCode)) { cmb_Uom.DataSource = dtUom; cmb_Uom.ValueMember = "Code"; cmb_Uom.DisplayMember = "Desc"; } } private string createUnique(UltraGridRow uge) { String ItemUnique = uge.GetCellValue("itemCode").ToString().Trim() + uge.GetCellValue("newItemAttrId").ToString().Trim() + uge.GetCellValue("newItemStandardsId").ToString().Trim() + uge.GetCellValue("newItemUomId").ToString().Trim(); return ItemUnique; } #endregion private void btn_Create_Click(object sender, EventArgs e) { doCreate(); } private void ck_ftime_CheckedChanged(object sender, EventArgs e) { txt_ForcasTimeEnd.Enabled = ck_ftime.Checked; txt_ForcasTimeStart.Enabled = ck_ftime.Checked; } private void ultraGrid1_ClickCell(object sender, ClickCellEventArgs e) { UltraGridRow row = e.Cell.Row; string strMrLineId = row.GetCellValue("mrlineid").ToString().Trim(); string strItemCode = row.GetCellValue("itemCode").ToString().Trim(); //string strItemUniuqe = row.GetCellValue("ItemUnique").ToString().Trim(); //String strNewItemUniuqe=row.GetCellValue("newItemUnique").ToString().Trim(); //if (row.HasParent())//子行查询可利资源 //{ // getCanUsePlan(strMrLineId, strItemUniuqe); //} //else//调整后数据查询 //{ // getCanUsePlan(strMrLineId, strNewItemUniuqe); //} getCanUsePlan(strMrLineId, strItemCode); } private void getCanUsePlan(String strMrLineId, String strItemCode) { dataTable3.Clear(); dataTable4.Clear(); if (string.IsNullOrEmpty(strMrLineId) || string.IsNullOrEmpty(strItemCode)) { return; } //查询可利计划资源 Dictionary param = new Dictionary(); param.Add("itemCode", strItemCode); if (ck_ftime.Checked) { if (txt_ForcasTimeStart.Text != "") { param.Add("forcastTimeStart", Convert.ToDateTime(txt_ForcasTimeStart.Value)); } if (txt_ForcasTimeEnd.Text != "") { param.Add("forcastTimeEnd", Convert.ToDateTime(txt_ForcasTimeEnd.Value)); } } if (ck_hasOrderQty.Checked) { param.Add("hasOrderQty", "1"); } param.Add("orderLineSqe",txt_orderNo.Text.Trim()); DataTable dt5 = this.execute("com.hnshituo.pur.requireplan.service.RequireReceiveService", "findcanUseBenefitReceivePlan", new object[] { param }); GridHelper.CopyDataToDatatable(dt5, dataTable3, true); foreach(UltraGridRow rows in ultraGrid2.Rows) { double orderCanUse=0; double planCanUse=0; double.TryParse(rows.Cells["qtyOrderRemain"].Value.ToString(), out orderCanUse); double.TryParse(rows.Cells["qtyCanUsePlan"].Value.ToString(), out planCanUse); rows.Cells["useQty"].Value = Math.Min(orderCanUse, planCanUse); rows.Cells["canUseQty"].Value = Math.Min(orderCanUse, planCanUse); //rows.Cells["CHK"].Value = true; } GridHelper.RefreshAndAutoSize(ultraGrid2); //查询已利计划资源 Dictionary ReqPnew = new Dictionary(); ReqPnew["mrLineId"] = strMrLineId; ReqPnew["style"] = "1";//有效数据 ReqPnew["dStatus"] = "2";//已编制数据 ReqPnew["lineSeq"] = "2";//走利计划类型 DataTable dt3 = this.execute("com.hnshituo.pur.requireplan.service.RequireReceiveService", "get_canUse", new object[] { ReqPnew }); GridHelper.CopyDataToDatatable(dt3, dataTable4, true); GridHelper.RefreshAndAutoSize(ultraGrid3); } private void btn_QueryLi_Click(object sender, EventArgs e) { UltraGridRow row = ultraGrid1.ActiveRow; if (row == null) { MessageUtil.ShowTips("请选择需要利计划的行信息!"); return; } string strMrLineId = row.GetCellValue("mrlineid").ToString().Trim(); string strItemCode = row.GetCellValue("itemCode").ToString().Trim(); //string strItemUniuqe = row.GetCellValue("ItemUnique").ToString().Trim(); //String strNewItemUniuqe = row.GetCellValue("newItemUnique").ToString().Trim(); //if (row.HasParent())//子行查询可利资源 //{ // getCanUsePlan(strMrLineId, strItemUniuqe); //} //else//调整后数据查询 //{ // getCanUsePlan(strMrLineId, strItemUniuqe); //} getCanUsePlan(strMrLineId, strItemCode); } private void btn_CreateLi_Click(object sender, EventArgs e) { try { if (ultraGrid1.ActiveRow == null||ultraGrid1.ActiveRow.HasChild()) { MessageUtil.ShowTips("需选择利计划的需求计划行!"); return; } UltraGridRow rowP = ultraGrid1.ActiveRow; String strMrLineId = rowP.GetCellValue("mrlineid").ToString().Trim(); String strItemUnique = rowP.GetCellValue("itemUnique").ToString().Trim(); String strItemCode = rowP.GetCellValue("itemCode").ToString().Trim(); String strId = rowP.GetCellValue("Id").ToString().Trim(); Double canLiQty=Convert.ToDouble(rowP.GetCellValue("Qty")); if (testStatus(strMrLineId, 2) == false) { return; } ultraGrid2.UpdateData(); IQueryable checkRows = ultraGrid2.Rows.AsQueryable().Where(a => a.GetValue("CHK") == "True" && a.GetValue("UseQty") != "" && double.Parse(a.GetValue("UseQty")) > 0); //("CHK = 'True' and QTYLJHTemp='0'"); if (checkRows.Count() == 0) { MessageUtil.ShowWarning("无可利对象,请选择可利计划资源!"); return; } ArrayList list = new ArrayList(); double liQty=0; foreach (UltraGridRow uRows in checkRows) { //减少接收表数据 //插入接收表数据 //更新需求计划行行状态 RequireReceive rr = new RequireReceive(); rr.Id = strId; rr.IdOld = uRows.GetCellValue("id").ToString().Trim(); rr.Qty = Convert.ToDouble(uRows.GetCellValue("UseQty")); liQty=liQty+(double)rr.Qty; rr.CreateUserid = UserInfo.GetUserID(); rr.CreateTime = DateTime.Now; rr.CreateName = UserInfo.GetUserName(); list.Add(rr); } if (liQty > canLiQty) { MessageUtil.ShowTips("需求计划行:" + strMrLineId + "最大可利计划量为:" + canLiQty); return; } if (MessageUtil.ShowYesNoAndQuestion("确定对需求计划行:" + strMrLineId + "进行利计划操作?") != DialogResult.Yes) { return; } CoreResult re = this.execute("com.hnshituo.pur.requireplan.service.RequireReceiveService", "doBenefit", new object[] { list, "1" }); if (re.Resultcode == 0) { MessageUtil.ShowTips("利计划成功!"); getCanUsePlan(strMrLineId, strItemUnique); rowP.Cells["qtyPur"].Value=Convert.ToDouble(rowP.GetCellValue("qtyPur")) - liQty; //更新到dateTable DataRow[] roww = dataTable2.Select("id='" + strId + "'"); if (roww.Count() != 1) { MessageUtil.ShowTips("发现" + roww.Count() + "条" + strId + "接收需求计划行,数据异常!"); } roww[0]["qty"] = Convert.ToDouble(roww[0]["qty"]) - liQty; rowP.Cells["Qty"].Value = Convert.ToDouble(rowP.GetCellValue("Qty")); rowP.ParentRow.Cells["SQTYPUR"].Value = Convert.ToDouble(rowP.ParentRow.Cells["SQTYPUR"].Value) - liQty; rowP.ParentRow.Cells["Num"].Value = Convert.ToDouble(rowP.ParentRow.Cells["Num"].Value) - liQty; return; } else { MessageUtil.ShowTips("操作失败:" + re.Resultmsg + "!"); return; } } catch (Exception ex) { MessageUtil.ShowTips("操作失败:" + ex.Message + "!"); } } private void btn_cancelLi_Click(object sender, EventArgs e) { try { if (ultraGrid1.ActiveRow == null || ultraGrid1.ActiveRow.HasChild()) { MessageUtil.ShowTips("请选择撤销利计划的需求计划行!"); return; } UltraGridRow rowP = ultraGrid1.ActiveRow; String strMrLineId = rowP.GetCellValue("mrlineid").ToString().Trim(); String strItemUnique = rowP.GetCellValue("itemUnique").ToString().Trim(); string strId = rowP.GetCellValue("id").ToString().Trim(); if (testStatus(strMrLineId, 3) == false) { return; } ultraGrid3.UpdateData(); IQueryable checkRows = ultraGrid3.Rows.AsQueryable().Where(a => a.GetValue("CHK") == "True"); //("CHK = 'True' and QTYLJHTemp='0'"); if (checkRows.Count() == 0) { MessageUtil.ShowWarning("未勾选需撤销利计划的计划行!"); return; } double cancelLiQty = 0; ArrayList list = new ArrayList(); foreach (UltraGridRow uRows in checkRows) { //减少接收表数据 //插入接收表数据 //更新需求计划行行状态 RequireReceive rr = new RequireReceive(); rr.Id = uRows.GetCellValue("id").ToString().Trim(); rr.MrLineId = strMrLineId; rr.PurLineId = uRows.GetCellValue("mrLineId").ToString().Trim(); cancelLiQty = cancelLiQty + Convert.ToDouble(uRows.GetCellValue("qty")); //rr.Qty = Convert.ToDouble(uRows.GetCellValue("QTYLJHTemp")); rr.CreateUserid = UserInfo.GetUserID(); rr.CreateTime = DateTime.Now; rr.CreateName = UserInfo.GetUserName(); list.Add(rr); } if (MessageUtil.ShowYesNoAndQuestion("确定对需求计划行:" + strMrLineId + "进行撤销利计划操作?") != DialogResult.Yes) { return; } CoreResult re = this.execute("com.hnshituo.pur.requireplan.service.RequireReceiveService", "doBenefit", new object[] { list, "2" }); if (re.Resultcode == 0) { MessageUtil.ShowTips("撤销成功!"); getCanUsePlan(strMrLineId, strItemUnique); rowP.Cells["qtyPur"].Value = Convert.ToDouble(rowP.GetCellValue("qtyPur")) + cancelLiQty; //更新到dateTable DataRow[] roww = dataTable2.Select("id='" + strId + "'"); if (roww.Count() != 1) { MessageUtil.ShowTips("发现" + roww.Count() + "条" + strId + "接收需求计划行,数据异常!"); } roww[0]["qty"] = Convert.ToDouble(roww[0]["qty"]) + cancelLiQty; rowP.Cells["Qty"].Value = Convert.ToDouble(rowP.GetCellValue("Qty")); rowP.ParentRow.Cells["SQTYPUR"].Value = Convert.ToDouble(rowP.ParentRow.Cells["SQTYPUR"].Value) + cancelLiQty; rowP.ParentRow.Cells["Num"].Value = Convert.ToDouble(rowP.ParentRow.Cells["Num"].Value) + cancelLiQty; return; } else { MessageUtil.ShowTips("操作失败:" + re.Resultmsg + "!"); return; } } catch (Exception ex) { MessageUtil.ShowTips("操作失败:" + ex.Message + "!"); } } private void ultraGrid2_CellChange(object sender, CellEventArgs e) { if (e.Cell.Column.Key == "UseQty") { double oldQty = e.Cell.Row.GetCellValue("UseQty") == DBNull.Value ? 0 : Convert.ToDouble(e.Cell.Row.GetCellValue("UseQty")); ultraGrid2.UpdateData(); double newQty = e.Cell.Row.GetCellValue("UseQty") == DBNull.Value ? 0 : Convert.ToDouble(e.Cell.Row.GetCellValue("UseQty")); if (!ultraGrid1.ActiveRow.HasParent()||ultraGrid1.ActiveRow==null) { MessageUtil.ShowTips("请选择需求计划行利计划!"); e.Cell.Row.Cells["UseQty"].Value = oldQty; return; } double canmaxLi = 0; double canUseLi = e.Cell.Row.GetCellValue("canUseQty") == DBNull.Value ? 0 : Convert.ToDouble(e.Cell.Row.GetCellValue("canUseQty")); canmaxLi = ultraGrid1.ActiveRow.GetCellValue("Qty") == DBNull.Value ? 0 : Convert.ToDouble(ultraGrid1.ActiveRow.GetCellValue("Qty")); if (newQty > canUseLi || newQty > canmaxLi) { e.Cell.Row.Cells["UseQty"].Value = oldQty; } } } private bool testStatus(string mrlineId, int p2)//校验状态 { if (String.IsNullOrEmpty(mrlineId)) { MessageUtil.ShowTips("为获取到需求计划行号!"); return false; } if (p2 == 1) { RequireReceive rr = new RequireReceive(); rr.MrLineId = mrlineId; rr.Validflag = "1"; DataTable dt2 = this.execute("com.hnshituo.pur.requireplan.service.RequireReceiveService", "find", new object[] { rr, 0, 0 }); if (dt2.Rows.Count == 0) { MessageUtil.ShowTips("需求计划行:" + mrlineId + "已退回或已删除!"); comm.doActiveSelRow(ultraGrid2, "mrlineId", mrlineId); return false; } if (dt2.Rows.Count > 1) { MessageUtil.ShowTips("需求计划行:" + mrlineId + "已利计划,请先撤销利计划再操作!"); comm.doActiveSelRow(ultraGrid2, "mrlineId", mrlineId); return false; } if (dt2.Rows[0]["status"].ToString().Trim() == "2") { MessageUtil.ShowTips("需求计划行:" + mrlineId + "已编制汇总,请先撤销编制汇总再操作!"); comm.doActiveSelRow(ultraGrid2, "mrlineId", mrlineId); return false; } } //是否可以利计划判断 else if (p2 == 2) { RequireReceive rr = new RequireReceive(); rr.MrLineId = mrlineId; rr.Purtype = "1";//编制类型 rr.Validflag = "1";//有效数据 List listR = this.execute>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "find", new object[] { rr, 0, 0 }); if (listR.Count() == 0) { MessageUtil.ShowTips("未发现接收需求计划行:" + mrlineId + "信息记录,可能已被删除或退回,或请刷新重新操作!"); return false; } else if (listR.Count() > 1) { MessageUtil.ShowTips("接收需求计划行:" + mrlineId + "数据异常,或请刷新重新操作!"); return false; } else { rr = listR[0]; if (rr.Status == "2") { MessageUtil.ShowTips("该接收需求计划行:" + mrlineId + "已编制汇总!"); return false; } if (rr.Qty <= 0) { MessageUtil.ShowTips("该接收需求计划行:" + mrlineId + "剩余最大可利计划量【" + rr.Qty + rr.ItemUom + "】!"); return false; } } } //是否可以利计划判断 else if (p2 == 3) { RequireReceive rr = new RequireReceive(); rr.MrLineId = mrlineId; rr.Purtype = "1";//编制类型 rr.Validflag = "1";//有效数据 List listR = this.execute>("com.hnshituo.pur.requireplan.service.RequireReceiveService", "find", new object[] { rr, 0, 0 }); if (listR.Count() == 0) { MessageUtil.ShowTips("未发现接收需求计划行:" + mrlineId + "信息记录,可能已被删除或退回,或请刷新重新操作!"); return false; } else if (listR.Count() > 1) { MessageUtil.ShowTips("接收需求计划行:" + mrlineId + "数据异常,或请刷新重新操作!"); return false; } else { rr = listR[0]; if (rr.Status == "2") { MessageUtil.ShowTips("该接收需求计划行:" + mrlineId + "已编制汇总!"); return false; } } } else { MessageUtil.ShowTips("未知验证参数!"); return false; } return true; } private void txt_UrgencyType_ValueChanged(object sender, EventArgs e) { if (txt_UrgencyType.SelectedIndex == 1) { //data_MrPeriodEnd.Enabled = true; } else { //data_MrPeriodEnd.Enabled = false; if (DateTime.Now.Month == 2) { data_MrPeriodEnd.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/28")) ? DateTime.Now : DateTime.Now.AddMonths(1); } else { data_MrPeriodEnd.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/30")) ? DateTime.Now : DateTime.Now.AddMonths(1); } } } private void doExcel_Click(object sender, EventArgs e) { try { //获取导出的采购计划行表 ultraGrid1.DisplayLayout.Bands[0].Columns["CHECK"].Hidden = true; ultraGrid1.DisplayLayout.Bands[1].Hidden = true; ArrayList alUltraGrid = new ArrayList(); alUltraGrid.Add(ultraGrid1); ArrayList alSheeft = new ArrayList(); alSheeft.Add("需求计划合计"); if (ultraGrid1.Rows.Count > 0) { GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "采购计划编制");//导出excel } } catch (Exception ex) { MessageUtil.ShowTips("导出失败" + ex.Message); } finally { ultraGrid1.DisplayLayout.Bands[0].Columns["CHECK"].Hidden = false;//显示复选框 ultraGrid1.DisplayLayout.Bands[1].Hidden = false; } } } }