FrmPurRequirePlanSummmary.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using com.hnshituo.pur.vo;
  11. using Core.Mes.Client.Comm.Control;
  12. using Core.Mes.Client.Comm.Server;
  13. using Core.Mes.Client.Comm.Tool;
  14. using CoreFS.CA06;
  15. using Infragistics.Win;
  16. using Infragistics.Win.UltraWinGrid;
  17. using Pur.Entity;
  18. using Pur.Entity.require_planEntiy;
  19. namespace Pur.require_plan
  20. {
  21. public partial class FrmPurRequirePlanSummmary : FrmPmsBase
  22. {
  23. String strCustom = "";
  24. private ArrayList list;
  25. private string tips;
  26. private int loadStyle=0;//0 list为需求行,1 list为需求头
  27. public string Tips
  28. {
  29. get { return tips; }
  30. set { tips = value; }
  31. }
  32. public FrmPurRequirePlanSummmary()
  33. {
  34. InitializeComponent();
  35. }
  36. public FrmPurRequirePlanSummmary(OpeBase opeBase, ArrayList list,int style,String Custom)
  37. {
  38. // TODO: Complete member initialization
  39. this.ob = opeBase;
  40. this.list = list;
  41. this.loadStyle = style;
  42. this.strCustom = Custom;
  43. InitializeComponent();
  44. }
  45. private void FrmPurRequirePlanSummmary_Load(object sender, EventArgs e)//load
  46. {
  47. this.tips = "0";
  48. getRequireType();
  49. init();
  50. GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] { "LASTDELIVERYDATE" });
  51. ultraGrid1.DisplayLayout.Bands[1].Override.AllowUpdate = DefaultableBoolean.False;
  52. //GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[0], new string[] { "LASTDELIVERYDATE" });
  53. //GridHelper.SetExcludeColumnsActive(ultraGrid1.DisplayLayout.Bands[1], new string[] { });
  54. }
  55. #region 按钮方法
  56. /// <summary>
  57. /// 汇总编制
  58. /// </summary>
  59. /// <param name="sender"></param>
  60. /// <param name="e"></param>
  61. private void btn_create_Click(object sender, EventArgs e)// 汇总编制
  62. {
  63. try
  64. {
  65. this.Cursor = Cursors.WaitCursor;
  66. ultraGrid1.UpdateData();
  67. ArrayList list1 = new ArrayList();
  68. foreach (UltraGridRow row in ultraGrid1.Rows)
  69. {
  70. if (row != null)
  71. {
  72. String strOldMrLineId = row.GetCellValue("mrLineId").ToString().Trim();
  73. RequirePlanD pd = this.execute<RequirePlanD>("com.hnshituo.pur.requireplan.service.RequirePlanDService", "findById", new object[] { strOldMrLineId });
  74. if (pd == null)
  75. {
  76. MessageUtil.ShowTips("无需求计划行:" + strOldMrLineId+"信息记录,或请刷新界面重新操作!");
  77. return;
  78. }
  79. if (pd.FlagGeneratedPurPlan != "1")
  80. {
  81. MessageUtil.ShowTips("需求计划行:" + strOldMrLineId + "已编制,或请刷新界面重新操作!");
  82. return;
  83. }
  84. RequirePlanD ReqD = new RequirePlanD();
  85. ReqD.LastDeliveryDate = Convert.ToDateTime(row.GetCellValue("LASTDELIVERYDATE"));
  86. ReqD.Qty = Convert.ToDouble(row.GetCellValue("qty"));
  87. ReqD.QtyPur = Convert.ToDouble(row.GetCellValue("qty"));
  88. ReqD.Validflag = "1";
  89. ReqD.ItemUnique = pd.ItemUnique;
  90. ReqD.DeliveryLocationFlag = pd.DeliveryLocationFlag;
  91. ReqD.DeliveryLocation = pd.DeliveryLocation;
  92. ReqD.DeliveryLocationCode = pd.DeliveryLocationCode;
  93. ReqD.ItemCode = pd.ItemCode;//物料编码
  94. ReqD.ItemName = pd.ItemName;//物料名称
  95. ReqD.Remark = pd.Remark;//备注
  96. ReqD.BugPrice = pd.BugPrice;//预算价
  97. ReqD.ItemAttr = pd.ItemAttr;//属性名称
  98. ReqD.ItemUom = pd.ItemUom;//采购单位
  99. ReqD.WeightUnit = pd.WeightUnit;//库存单位
  100. ReqD.ItemUomConefficient = pd.ItemUomConefficient;//转化系数
  101. ReqD.BudgetAmt = ReqD.BugPrice * ReqD.Qty * ReqD.ItemUomConefficient;//消耗预算
  102. ReqD.CreateName = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName();
  103. ReqD.CreateUserid = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID();
  104. ReqD.CreateTime = DateTime.Now;
  105. ReqD.FlagGeneratedPurPlan = "1";//默认未接受
  106. ReqD.ItemStandardsCode = pd.ItemStandardsCode;
  107. ReqD.ItemStandardsId = pd.ItemStandardsId;
  108. ReqD.ItemUomId = pd.ItemUomId;
  109. ReqD.ItemAttrId = pd.ItemAttrId;
  110. ReqD.AuditFlag = "";
  111. List<System.String> list2 = new List<System.String>();
  112. foreach (UltraGridRow rowd in row.ChildBands[0].Rows)
  113. {
  114. if (rowd.HasParent())
  115. {
  116. list2.Add(rowd.GetValue("mrLIneId").ToString().Trim());
  117. }
  118. }
  119. if(list2.Count<=0)
  120. {
  121. MessageUtil.ShowTips("数据异常!没有拿到第:"+row.Index+"条行信息的关联的源需求计划号!");
  122. return;
  123. }
  124. ReqD.ValidDataPurviewIds=list2.ToArray();
  125. //ReqD.DeleteUserid = UserInfo.GetDeptid();//部门ID
  126. list1.Add(ReqD);
  127. }
  128. }
  129. RequirePlanM ReqM = new RequirePlanM();
  130. ReqM.CreateName = UserInfo.GetUserName();
  131. ReqM.CreateUserid = UserInfo.GetUserID();
  132. ReqM.CreateTime = DateTime.Now;
  133. if (txt_MRPERIODEND.Text == "")
  134. {
  135. MessageUtil.ShowTips("请输入有效的计划月份");
  136. txt_MRPERIODEND.Focus();
  137. return;
  138. }
  139. if (txt_MRPERIODEND.Enabled == false)
  140. {
  141. if (DateTime.Now > DateTime.Parse(DateTime.Now.ToString("yyyy/MM/26")))
  142. {
  143. if (MessageUtil.ShowYesNoAndQuestion("需求提报截止日期为每月25号,若提交将默认为下月需求计划。确定新增?") != DialogResult.Yes)
  144. {
  145. txt_MRPERIODEND.Focus();
  146. return;
  147. }
  148. }
  149. ReqM.MrPeriodEnd = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/26")) ? DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(2).ToString("yyyy/MM"));
  150. }
  151. else
  152. {
  153. ReqM.MrPeriodEnd = Convert.ToDateTime(txt_MRPERIODEND.Value);
  154. }
  155. ReqM.UrgencyType = txt_URGENCYTYPE.Value.ToString();
  156. ReqM.ReqOrgName = UserInfo.GetDepartment();//申请者机构名称
  157. ReqM.ReqOrgId = UserInfo.GetDeptid();//申请者机构ID
  158. ReqM.Validflag = "1";
  159. ReqM.TenantName = txt_auditName.Text.Trim();
  160. ReqM.TenantId = txt_auditId.Text.Trim();
  161. if (txt_RequeType.SelectedIndex == -1)
  162. {
  163. MessageUtil.ShowTips("需指定需求计划类型");
  164. txt_RequeType.Focus();
  165. return;
  166. }
  167. ReqM.RequireType = txt_RequeType.Value.ToString().Trim();
  168. ReqM.Status = "1";
  169. if (MessageUtil.ShowYesNoAndQuestion("确定编制汇总?") != DialogResult.Yes)
  170. {
  171. return;
  172. }
  173. CoreResult re = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.RequirePlanMService", "SummaryReqPlan", new object[] { ReqM, list1, list,strCustom});
  174. if (re.Resultcode != 0)
  175. {
  176. MessageUtil.ShowTips("操作失败:" + re.Resultmsg);
  177. }
  178. else
  179. {
  180. MessageUtil.ShowTips("操作成功:生成需求计划【" + re.Resultmsg + "】");
  181. setTips();
  182. this.Close();
  183. }
  184. }
  185. catch (Exception ex)
  186. {
  187. MessageUtil.ShowTips("操作失败:" + ex);
  188. }
  189. finally
  190. {
  191. this.Cursor = Cursors.Default;
  192. }
  193. }
  194. /// <summary>
  195. /// 刷新
  196. /// </summary>
  197. /// <param name="sender"></param>
  198. /// <param name="e"></param>
  199. private void btn_refresh_Click(object sender, EventArgs e)// 刷新
  200. {
  201. getRequireType();
  202. init();
  203. }
  204. /// <summary>
  205. /// 关闭
  206. /// </summary>
  207. /// <param name="sender"></param>
  208. /// <param name="e"></param>
  209. private void btn_Close_Click(object sender, EventArgs e)// 关闭
  210. {
  211. ultraGrid1.Rows.ExpandAll(true);
  212. }
  213. #endregion
  214. #region 界面方法
  215. /// <summary>
  216. /// 初始化
  217. /// </summary>
  218. private void init()// 初始化
  219. {
  220. try
  221. {
  222. this.Cursor=Cursors.WaitCursor;
  223. dataSet1.Clear();
  224. DataTable dt = null;
  225. dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.RequirePlanDService", "getJoinedByIds", new object[] { list,loadStyle});
  226. dt.Columns.Add("itemModel", typeof(string));
  227. foreach (DataRow dr in dt.Rows)
  228. {
  229. //String StritemUnique = dr["itemUnique"].ToString().Trim();
  230. //string strJit = dr["deliveryLocationFlag"].ToString().Trim();
  231. //string strdeliveryCode = dr["deliveryLocationCode"].ToString().Trim();
  232. //String uniqueId = StritemUnique + "@" + strJit + "@" + strdeliveryCode;
  233. StringBuilder uniqueId = new StringBuilder(dr["itemUnique"].ToString().Trim());
  234. uniqueId.Append("@").Append(dr["deliveryLocationFlag"].ToString().Trim()).Append("@").Append(dr["deliveryLocationCode"].ToString().Trim());
  235. dr["itemModel"] = uniqueId.ToString();
  236. }
  237. DataTable dttest = dt.Copy();
  238. //删除父表中没有的需求订单行
  239. for (int i = 0; i < dttest.Rows.Count; i++)
  240. {
  241. String strItemModel = dttest.Rows[i]["itemModel"].ToString().Trim();
  242. int cou = 0;
  243. for (int j = dt.Rows.Count - 1; j >= 0; j--)
  244. {
  245. String tempItemModel = dt.Rows[j]["itemModel"].ToString().Trim();
  246. if (tempItemModel == strItemModel)
  247. {
  248. cou = cou + 1;
  249. if (cou == 1)
  250. {
  251. //rowt = dt.Rows[j];
  252. }
  253. if (cou >= 2)
  254. {
  255. dt.Rows.RemoveAt(j);
  256. }
  257. }
  258. }
  259. }
  260. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  261. //行信息
  262. DataTable dt1 = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.RequirePlanDService", "getJoinedByIds", new object[] { list,loadStyle});
  263. dt1.Columns.Add("itemModel", typeof(string));
  264. foreach (DataRow dr1 in dt1.Rows)
  265. {
  266. String StritemUnique = dr1["itemUnique"].ToString().Trim();
  267. string strJit = dr1["deliveryLocationFlag"].ToString().Trim();
  268. string strdeliveryCode = dr1["deliveryLocationCode"].ToString().Trim();
  269. String uniqueId = StritemUnique + "@" + strJit + "@" + strdeliveryCode;
  270. dr1["itemModel"] = uniqueId;
  271. }
  272. GridHelper.CopyDataToDatatable(dt1, dataTable2, true);
  273. RequirePlanM RPM = this.execute<RequirePlanM>("com.hnshituo.pur.requireplan.service.RequirePlanMService", "findById", new object[] {list[0]});
  274. txt_URGENCYTYPE.SelectedIndex = 0;//常规类型
  275. txt_RequeType.Value = "122101";//普采主计划
  276. txt_RequeType.ReadOnly = true;
  277. txt_REQORGNAME.Text = UserInfo.GetDepartment();
  278. txt_REQORGId.Text= UserInfo.GetDeptid();
  279. txt_MRPERIODEND.Enabled = false;
  280. txt_MRPERIODEND.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/26")) ? DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(2).ToString("yyyy/MM"));
  281. txt_auditId.Text = RPM.TenantId;
  282. txt_auditName.Text = RPM.TenantName;
  283. foreach (UltraGridRow rowg in ultraGrid1.Rows)
  284. {
  285. if (rowg.HasChild())
  286. {
  287. DateTime date=DateTime.Now;
  288. int i=0;
  289. double numall = 0;
  290. foreach (UltraGridRow rowc in rowg.ChildBands[0].Rows)
  291. {
  292. DateTime dateLine = DateTime.Parse(rowc.GetCellValue("LASTDELIVERYDATE").ToString());
  293. if (i == 0)
  294. {
  295. date = dateLine;
  296. }
  297. else
  298. {
  299. date = date > dateLine ? dateLine : date;
  300. }
  301. i = i + 1;
  302. numall = numall + Convert.ToDouble(rowc.GetCellValue("Qty"));
  303. //SQTYPURall = Convert.ToDouble(rowc.GetCellValue("SQTYPUR"));
  304. }
  305. rowg.Cells["Qty"].Value = numall;
  306. rowg.Cells["LASTDELIVERYDATE"].Value = date;
  307. }
  308. }
  309. }
  310. catch (Exception ex)
  311. {
  312. MessageUtil.ShowTips("初始化或刷新界面失败:" + ex);
  313. }
  314. finally
  315. {
  316. this.Cursor=Cursors.Default;
  317. }
  318. }
  319. /// <summary>
  320. /// 加载计划类型
  321. /// </summary>
  322. private void getRequireType()//加载计划类型
  323. {
  324. DataTable dt1 = ServerHelper.GetData("com.hnshituo.pur.configure.service.impl.CoreBaseInfoNew.doQuery", new Object[] { "1221" }, this.ob);
  325. comm.FilComboboxAdd(txt_RequeType, dt1, "baseCode", "baseName", "validflag NOT in ('0') and baseCode in ('122103','122101','122104')", false, "", "");
  326. }
  327. /// <summary>
  328. /// 操作标识
  329. /// </summary>
  330. private void setTips()// 操作标识
  331. {
  332. if (tips == "0")
  333. {
  334. tips = "1";
  335. }
  336. }
  337. #endregion
  338. private void txt_URGENCYTYPE_ValueChanged(object sender, EventArgs e)
  339. {
  340. if (txt_URGENCYTYPE.SelectedIndex == 1)
  341. {
  342. txt_MRPERIODEND.Enabled = true;
  343. }
  344. else
  345. {
  346. txt_MRPERIODEND.Enabled = false;
  347. txt_MRPERIODEND.Value = DateTime.Now < DateTime.Parse(DateTime.Now.ToString("yyyy/MM/26")) ? DateTime.Parse(DateTime.Now.AddMonths(1).ToString("yyyy/MM")) : DateTime.Parse(DateTime.Now.AddMonths(2).ToString("yyyy/MM"));
  348. }
  349. }
  350. }
  351. }