F_PM_1107.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. /*******************************************************************************
  2. * 类的信息:
  3. * 1.程序名称:F_PM_1107.cs
  4. * 2.功能描述:批量报废信息窗体
  5. * 编辑履历:
  6. * 作者 日期
  7. * 李士越 2024/05/29
  8. *******************************************************************************/
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseResources;
  14. using Dongke.IBOSS.PRD.WCF.Proxys;
  15. using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.Basics.BaseControls;
  18. using Dongke.IBOSS.PRD.Basics.Library;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.Client.Controls;
  21. namespace Dongke.IBOSS.PRD.Client.PMModule
  22. {
  23. /// <summary>
  24. /// 批量报废信息窗体
  25. /// </summary>
  26. public partial class F_PM_1107 : DKFormBase
  27. {
  28. #region 成员变量
  29. //窗体模式ID
  30. private Constant.FormMode _formType;
  31. //修改产品报损信息ID
  32. private string _barCode;
  33. //页面报损工序的数据源
  34. private List<ProductionDataEntity> _productionDataList = new List<ProductionDataEntity>();
  35. //该产品在产信息实体
  36. private InProductionEntity _isScrapProductEntity;
  37. //用户选择报损工序实体
  38. private ProductionDataEntity _scrapProductResponProcedure;
  39. //当前责任人集合
  40. private List<ScrapResponsibleEntity> _scrapResponsibleList = new List<ScrapResponsibleEntity>();
  41. //修改用废弃产品实体
  42. private ScrapProductEntity _updateEntity;
  43. //修改用废弃责任工序实体
  44. private ResponProcedureEntity _updateProcedureEntity;
  45. //修改用责任人集合
  46. private List<ScrapResponsibleEntity> _updateScrapResponsibleList;
  47. //有效条码标示
  48. private bool _yxBarCode = false;
  49. //产品分级类别ID
  50. private int _goodsLevelTypeID = Convert.ToInt32(Constant.GoodsLevelType.Damage);
  51. //产品分级ID
  52. private int _goodsLevelId;
  53. //报损信息ID
  54. private int _editSPId;
  55. //是否允许审批
  56. private bool _isScrap = false;
  57. //未干补
  58. int SpecialRepairFlag = 0;
  59. //完成工序
  60. int? _CompleteProcdureID = null;
  61. //完成工序编码
  62. string _CompleteProcdureCode = "";
  63. //完成工序名称
  64. string _CompleteProcdureName = "";
  65. // 商标ID
  66. int? _LogoID = null;
  67. //可以报损的产品条码集合
  68. List<string> ReportingLosses = new List<string>();
  69. #endregion
  70. #region 构造函数
  71. /// <summary>
  72. /// 窗体构造
  73. /// </summary>
  74. public F_PM_1107(Constant.FormMode formType, string BarCode, int EditSPId, bool isScrap)
  75. {
  76. InitializeComponent();
  77. this._formType = formType;
  78. this._barCode = BarCode;
  79. this._editSPId = EditSPId;
  80. this._isScrap = isScrap;
  81. //if (formType == Constant.FormMode.Add)
  82. //{
  83. this.Text = "批量报损";
  84. //}
  85. //else
  86. //{
  87. // this.Text = FormTitles.F_PM_1107_EDIT;
  88. //}
  89. //this.btnViewApprover.Text = ButtonText.BTN_VIEWAPPROVER;
  90. this.btnSave.Text = ButtonText.BTN_SAVE;
  91. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  92. }
  93. #endregion
  94. #region 事件
  95. /// <summary>
  96. /// 窗体加载
  97. /// </summary>
  98. /// <param name="sender"></param>
  99. /// <param name="e"></param>
  100. private void F_PM_1107_Load(object sender, EventArgs e)
  101. {
  102. try
  103. {
  104. //获取当前产品分级ID
  105. this._goodsLevelId = Convert.ToInt32(SystemModuleProxy.Service.GetGoodsLevelDataById(_goodsLevelTypeID, null)
  106. .Tables[0].Rows[0]["GoodsLevelID"]);
  107. DataTable dt = new DataTable();
  108. dt.Columns.Add("DictionaryID", typeof(int));
  109. dt.Columns.Add("DictionaryValue", typeof(string));
  110. DataRow drbydt = dt.NewRow();
  111. drbydt["DictionaryID"] = 119;
  112. drbydt["DictionaryValue"] = "盘点报损";
  113. dt.Rows.Add(drbydt);
  114. this.cmbRreason.DisplayMember = "DictionaryValue";
  115. this.cmbRreason.ValueMember = "DictionaryID";
  116. this.cmbRreason.DataSource = dt;
  117. //绑定损坯状态
  118. DataTable dtAuditStatus = new DataTable();
  119. dtAuditStatus.Columns.Add("AuditStatusID");
  120. dtAuditStatus.Columns.Add("AuditStatusValue");
  121. DataRow dr = dtAuditStatus.NewRow();
  122. dr = dtAuditStatus.NewRow();
  123. dr["AuditStatusID"] = 1;
  124. dr["AuditStatusValue"] = "损坯通过";
  125. dtAuditStatus.Rows.Add(dr);
  126. this.cmbAuditStatus.DisplayMember = "AuditStatusValue";
  127. this.cmbAuditStatus.ValueMember = "AuditStatusID";
  128. this.cmbAuditStatus.DataSource = dtAuditStatus;
  129. if (this._formType == Constant.FormMode.Edit)
  130. {
  131. BindEntity();
  132. }
  133. }
  134. catch (Exception ex)
  135. {
  136. // 对异常进行共通处理
  137. ExceptionManager.HandleEventException(this.ToString(),
  138. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  139. }
  140. }
  141. /// <summary>
  142. /// 提交操作
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void btnSave_Click(object sender, EventArgs e)
  147. {
  148. try
  149. {
  150. if (this.txtBarCode.Text == string.Empty)
  151. {
  152. this.txtBarCode.Focus();
  153. return;
  154. }
  155. this.txtRemarks.Focus();//把光标移开,由于删除工号后,值未变
  156. DataTable dt = new DataTable();
  157. //备注
  158. dt.Columns.Add("notes");
  159. //产品编码
  160. dt.Columns.Add("ProductCode");
  161. foreach (var item in ReportingLosses) {
  162. DataRow dr = dt.NewRow();
  163. dr["notes"] = save(item);
  164. dr["ProductCode"] = item;
  165. dt.Rows.Add(dr);
  166. }
  167. this.detailsView.DataSource = dt;
  168. }
  169. catch (Exception ex)
  170. {
  171. // 对异常进行共通处理
  172. ExceptionManager.HandleEventException(this.ToString(),
  173. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  174. }
  175. }
  176. /// <summary>
  177. /// 保存方法
  178. /// </summary>
  179. /// <param name="barcode"></param>
  180. /// <returns></returns>
  181. public string save(string barcode) {
  182. string result = "";
  183. try
  184. {
  185. if (this.txtBarCode.Text == string.Empty)
  186. {
  187. this.txtBarCode.Focus();
  188. return "";
  189. }
  190. ServiceResultEntity sreByid = DoAsync<ServiceResultEntity>(() =>
  191. {
  192. ClientRequestEntity cre = new ClientRequestEntity();
  193. cre.NameSpace = "F_PM_1107";
  194. cre.Name = "ReadAllDataByProductCode";
  195. cre.Properties["BARCODE"] = barcode;
  196. return SystemModuleProxy.Service.DoRequest(cre);
  197. });
  198. if (sreByid.Data.Tables[0].Rows[0]["USERID"].ToString()==string.Empty || sreByid.Data.Tables[0].Rows[0]["USERID"].ToString()=="" || sreByid.Data.Tables[0].Rows[0]["USERID"].ToString()==null) {
  199. return "信息不全,此产品不做任何处理";
  200. }
  201. ServiceResultEntity sreByuserid = DoAsync<ServiceResultEntity>(() =>
  202. {
  203. ClientRequestEntity cre = new ClientRequestEntity();
  204. cre.NameSpace = "F_PM_1107";
  205. cre.Name = "ReadStaffInformation";
  206. cre.Properties["USERID"] = sreByid.Data.Tables[0].Rows[0]["USERID"].ToString();
  207. return SystemModuleProxy.Service.DoRequest(cre);
  208. });
  209. this.txtRemarks.Focus();//把光标移开,由于删除工号后,值未变
  210. if (this._formType == Constant.FormMode.Add)
  211. {
  212. //获取责任人集合
  213. List<ScrapResponsibleEntity> addResponsibleList = new List<ScrapResponsibleEntity>()
  214. {
  215. new ScrapResponsibleEntity() {
  216. BarCode = sreByid.Data.Tables[0].Rows[0]["BarCode"].ToString(),
  217. StaffID = Convert.ToInt32(sreByuserid.Data.Tables[0].Rows[0]["STAFFID"].ToString()),
  218. StaffStatus = Convert.ToInt32(sreByuserid.Data.Tables[0].Rows[0]["Staffstatus"].ToString()),
  219. UserID = Convert.ToInt32(sreByuserid.Data.Tables[0].Rows[0]["USERID"].ToString()),
  220. UserCode = sreByuserid.Data.Tables[0].Rows[0]["USERCODE"].ToString() + "",
  221. UJobsID = Convert.ToInt32(sreByuserid.Data.Tables[0].Rows[0]["UJobsId"].ToString()),
  222. SJobsID = Convert.ToInt32(sreByuserid.Data.Tables[0].Rows[0]["JOBS"].ToString()),
  223. }
  224. };
  225. //如果选择了责任工序就一定要选择责任人
  226. //if (cbResponProcedure.Text != string.Empty && addResponsibleList.Count == Constant.INT_IS_ZERO)
  227. if (addResponsibleList.Count == Constant.INT_IS_ZERO)
  228. {
  229. //MessageBox.Show("请选择责任人!",
  230. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  231. return "请选择责任人!";
  232. }
  233. //首先判断责任类型
  234. int thisResponType = 0;
  235. if (sreByid.Data.Tables[0].Rows.Count == 0 && addResponsibleList.Count == Constant.INT_IS_ZERO)
  236. {
  237. thisResponType = 1;
  238. }
  239. else if (sreByid.Data.Tables[0].Rows.Count > 0 && addResponsibleList.Count != Constant.INT_IS_ZERO)
  240. {
  241. thisResponType = 3;
  242. }
  243. else if (sreByid.Data.Tables[0].Rows.Count == 0 && addResponsibleList.Count != Constant.INT_IS_ZERO)
  244. {
  245. thisResponType = 2;
  246. }
  247. if (thisResponType == Constant.INT_IS_ZERO)
  248. {
  249. //MessageBox.Show("责任类别不正确!",
  250. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  251. return "责任类别不正确!";
  252. }
  253. //新建报损产品实体
  254. ScrapProductEntity addScrapProduct = new ScrapProductEntity();
  255. addScrapProduct.BarCode = sreByid.Data.Tables[0].Rows[0]["BarCode"].ToString();
  256. addScrapProduct.ProductionLineID = int.Parse(sreByid.Data.Tables[0].Rows[0]["PRODUCTIONLINEID"].ToString());
  257. addScrapProduct.ProductionLineCode = sreByid.Data.Tables[0].Rows[0]["PRODUCTIONLINECODE"].ToString();
  258. addScrapProduct.ProductionLineName = sreByid.Data.Tables[0].Rows[0]["PRODUCTIONLINENAME"].ToString();
  259. addScrapProduct.GoodsID = int.Parse(sreByid.Data.Tables[0].Rows[0]["GOODSID"].ToString());
  260. addScrapProduct.GoodsCode = sreByid.Data.Tables[0].Rows[0]["GOODSCODE"].ToString();
  261. addScrapProduct.GoodsName = sreByid.Data.Tables[0].Rows[0]["GOODSNAME"].ToString();
  262. addScrapProduct.GroutingDailyID = int.Parse(sreByid.Data.Tables[0].Rows[0]["GROUTINGDAILYID"].ToString());
  263. addScrapProduct.GroutingDailyDetailID = int.Parse(sreByid.Data.Tables[0].Rows[0]["GROUTINGDAILYDETAILID"].ToString());
  264. addScrapProduct.GroutingDate = Convert.ToDateTime(sreByid.Data.Tables[0].Rows[0]["GROUTINGDATE"].ToString());
  265. addScrapProduct.GroutingLineID = int.Parse(sreByid.Data.Tables[0].Rows[0]["GROUTINGLINEID"].ToString());
  266. addScrapProduct.GroutingLineCode = sreByid.Data.Tables[0].Rows[0]["GROUTINGLINECODE"].ToString();
  267. addScrapProduct.GroutingLineName = sreByid.Data.Tables[0].Rows[0]["GROUTINGLINENAME"].ToString();
  268. addScrapProduct.GMouldTypeID = int.Parse(sreByid.Data.Tables[0].Rows[0]["GMOULDTYPEID"].ToString());
  269. addScrapProduct.GroutingLineDetailID = int.Parse(sreByid.Data.Tables[0].Rows[0]["GROUTINGLINEDETAILID"].ToString());
  270. addScrapProduct.GroutingMouldCode = sreByid.Data.Tables[0].Rows[0]["GROUTINGMOULDCODE"].ToString();
  271. addScrapProduct.MouldCode = sreByid.Data.Tables[0].Rows[0]["MOULDCODE"].ToString();
  272. addScrapProduct.GoodsLevelTypeID = _goodsLevelTypeID;
  273. addScrapProduct.GoodsLevelID = _goodsLevelId;
  274. addScrapProduct.ScrapDate = DateTime.Now;
  275. addScrapProduct.Rreason = "盘点报损";
  276. addScrapProduct.ResponUserID = Convert.ToInt32(sreByuserid.Data.Tables[0].Rows[0]["USERID"].ToString());
  277. addScrapProduct.ResponUserCode = sreByuserid.Data.Tables[0].Rows[0]["USERCODE"].ToString() + "";
  278. addScrapProduct.ResponUserName = sreByuserid.Data.Tables[0].Rows[0]["USERNAME"].ToString();
  279. addScrapProduct.Remarks = this.txtRemarks.Text;
  280. addScrapProduct.AuditStatus = 0;
  281. addScrapProduct.SettlementFlag = 0;
  282. addScrapProduct.ResponType = thisResponType;
  283. addScrapProduct.GroutingUserID = Convert.ToInt32(sreByid.Data.Tables[0].Rows[0]["GROUTINGUSERID"].ToString());
  284. addScrapProduct.GroutingUserCode = sreByid.Data.Tables[0].Rows[0]["GROUTINGUSERCODE"].ToString();
  285. addScrapProduct.GroutingNum = decimal.Parse(sreByid.Data.Tables[0].Rows[0]["GROUTINGNUM"].ToString());
  286. addScrapProduct.IsPublicBody = Convert.ToInt32(sreByid.Data.Tables[0].Rows[0]["ISPUBLICBODY"].ToString());
  287. addScrapProduct.IsReFire = Convert.ToInt32(sreByid.Data.Tables[0].Rows[0]["ISREFIRE"].ToString());
  288. addScrapProduct.AuditStatus = Convert.ToInt32(cmbAuditStatus.SelectedValue);
  289. addScrapProduct.SpecialRepairflag = int.Parse(sreByid.Data.Tables[0].Rows[0]["SPECIALREPAIRFLAG"].ToString());
  290. addScrapProduct.LogoID = int.Parse(sreByid.Data.Tables[0].Rows[0]["LogoID"].ToString());
  291. if (sreByid.Data.Tables[0].Rows[0]["PROCEDUREID"].ToString() != null)
  292. {
  293. addScrapProduct.ProcedureID = int.Parse(sreByid.Data.Tables[0].Rows[0]["PROCEDUREID"].ToString());
  294. //addScrapProduct.ProcedureName = this.txtCompleteProcdure.Text;
  295. addScrapProduct.ProcedureName = sreByid.Data.Tables[0].Rows[0]["ProcedureName"].ToString();
  296. addScrapProduct.ProcedureCode = sreByid.Data.Tables[0].Rows[0]["ProcedureCode"].ToString();
  297. }
  298. ResponProcedureEntity addRProcedure = new ResponProcedureEntity();
  299. //如果存在责任工序的话,也要添加责任工序
  300. if (thisResponType == Constant.INT_IS_THREE)
  301. {
  302. addRProcedure.BarCode = sreByid.Data.Tables[0].Rows[0]["BarCode"].ToString();
  303. addRProcedure.ProductionDataID = int.Parse(sreByid.Data.Tables[0].Rows[0]["PRODUCTIONDATAID"].ToString());
  304. addRProcedure.ProductionLineID = int.Parse(sreByid.Data.Tables[0].Rows[0]["PRODUCTIONLINEID"].ToString());
  305. addRProcedure.ProductionLineCode = sreByid.Data.Tables[0].Rows[0]["PRODUCTIONLINECODE"].ToString();
  306. addRProcedure.ProductionLineName = sreByid.Data.Tables[0].Rows[0]["PRODUCTIONLINENAME"].ToString();
  307. addRProcedure.ProcedureID = int.Parse(sreByid.Data.Tables[0].Rows[0]["PROCEDUREID"].ToString());
  308. addRProcedure.ProcedureCode = sreByid.Data.Tables[0].Rows[0]["ProcedureCode"].ToString();
  309. addRProcedure.ProcedureName = sreByid.Data.Tables[0].Rows[0]["ProcedureName"].ToString();
  310. addRProcedure.UserID = Convert.ToInt32(sreByuserid.Data.Tables[0].Rows[0]["USERID"].ToString());
  311. addRProcedure.UserCode = sreByuserid.Data.Tables[0].Rows[0]["USERCODE"].ToString() + "";
  312. addRProcedure.UserName = sreByuserid.Data.Tables[0].Rows[0]["USERNAME"].ToString();
  313. addRProcedure.Remarks = "";
  314. }
  315. int addReturn = (int)DoAsync(new BaseAsyncMethod(() =>
  316. {
  317. return PMModuleProxy.Service.AddScrapProduct(addScrapProduct, addRProcedure, addResponsibleList);
  318. }));
  319. if (addReturn > Constant.INT_IS_ZERO)
  320. {
  321. //成功
  322. //MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "废弃产品", "保存"),
  323. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  324. //this.DialogResult = DialogResult.OK;
  325. return string.Format(Messages.MSG_CMN_I001, "废弃产品", "保存");
  326. }
  327. else if (addReturn == Constant.RETURN_IS_DATACHANGED)
  328. {
  329. //成功
  330. //MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "操作的数据已经发生了变化"),
  331. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  332. //this.DialogResult = DialogResult.OK;
  333. return string.Format(Messages.MSG_CMN_W007, "操作的数据已经发生了变化");
  334. }
  335. else
  336. {
  337. //失败
  338. //MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "废弃产品", "保存"),
  339. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  340. return string.Format(Messages.MSG_CMN_W001, "废弃产品", "保存");
  341. }
  342. }
  343. }
  344. catch (Exception ex)
  345. {
  346. // 对异常进行共通处理
  347. ExceptionManager.HandleEventException(this.ToString(),
  348. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  349. }
  350. return result;
  351. }
  352. /// <summary>
  353. /// 窗体关闭
  354. /// </summary>
  355. /// <param name="sender"></param>
  356. /// <param name="e"></param>
  357. private void btnCancel_Click(object sender, EventArgs e)
  358. {
  359. this.Close();
  360. }
  361. /// <summary>
  362. /// 按下回车后调用产品条码检验
  363. /// </summary>
  364. /// <param name="sender"></param>
  365. /// <param name="e"></param>
  366. private void txtBarCode_KeyPress(object sender, KeyPressEventArgs e)
  367. {
  368. try
  369. {
  370. //清除所有产品条码
  371. ReportingLosses.Clear();
  372. if ((int)e.KeyChar == 13 && (this.txtBarCode.Text != "" && this.txtBarCode.Text != string.Empty && this.txtBarCode.Text != null)) // 按了回车键
  373. {
  374. var dt = new DataTable();
  375. //备注
  376. dt.Columns.Add("notes");
  377. //产品编码
  378. dt.Columns.Add("ProductCode");
  379. var sss = SplitLong11(this.txtBarCode.Text);
  380. foreach (var item in sss)
  381. {
  382. var pubg = ReadAllDataByProductCode(item);
  383. DataRow dr = dt.NewRow();
  384. dr["notes"] = pubg ;
  385. dr["ProductCode"] = item;
  386. dt.Rows.Add(dr);
  387. if (pubg =="没有问题") { ReportingLosses.Add(item); }
  388. }
  389. this.dgvResponsible.DataSource = dt;
  390. }
  391. }
  392. catch (Exception ex)
  393. {
  394. // 对异常进行共通处理
  395. ExceptionManager.HandleEventException(this.ToString(),
  396. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  397. }
  398. }
  399. /// <summary>
  400. /// 字符串按11位分割
  401. /// </summary>
  402. /// <param name="item"></param>
  403. /// <returns></returns>
  404. public List<string> SplitLong11(string item) {
  405. List<string> result = new List<string>();
  406. // 检查字符串长度是否大于或等于分组大小
  407. if (item.Length >= 11)
  408. {
  409. for (int i = 0; i < item.Length; i += 11)
  410. {
  411. // 截取当前分组,注意不要超出字符串长度
  412. int length = Math.Min(11, this.txtBarCode.Text.Length - i);
  413. string chunk = this.txtBarCode.Text.Substring(i, length);
  414. result.Add(chunk);
  415. }
  416. }
  417. return result;
  418. }
  419. #endregion
  420. /// <summary>
  421. /// 产品条码检验
  422. /// </summary>
  423. /// <param name="item"></param>
  424. /// <returns></returns>
  425. private string ReadAllDataByProductCode(string item)
  426. {
  427. string notes = "没有问题";
  428. try
  429. {
  430. string doRuselt = (string)DoAsync(new BaseAsyncMethod(() =>
  431. {
  432. return PMModuleProxy.Service.ScrapProductChack(item);
  433. }));
  434. string[] doRuselts = doRuselt.Split(':');
  435. int isHave = Convert.ToInt32(doRuselts[0]);
  436. if (isHave == 2)
  437. {
  438. return notes = "不是在产产品不能报损!";
  439. //MessageBox.Show("产品编码为" + item + " 不是在产产品不能报损!",
  440. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  441. //this.txtBarCode.Text = "";
  442. //this.txtBarCode.Focus();
  443. //Product = false;
  444. }
  445. if (isHave == 3)
  446. {
  447. return notes = "当前工号没有此产品所在工序"+ doRuselts[1] + "的操作权限,不能报损!";
  448. //MessageBox.Show(string.Format("产品编码为" + item + " 当前工号没有此产品所在工序【{0}】的操作权限,不能报损!", doRuselts[1]),
  449. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  450. //this.txtBarCode.Text = "";
  451. //this.txtBarCode.Focus();
  452. //Product = false;
  453. }
  454. if (isHave == 4)
  455. {
  456. return notes = doRuselts[1];
  457. // MessageBox.Show(doRuselts[1],
  458. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  459. //this.txtBarCode.Text = "";
  460. //this.txtBarCode.Focus();
  461. //Product = false;
  462. }
  463. if (isHave == Constant.INT_IS_ZERO)
  464. {
  465. return notes = "已经存在报损记录!";
  466. // MessageBox.Show("产品编码为" + item + " 已经存在报损记录!",
  467. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  468. //this.txtBarCode.Text = "";
  469. //this.txtBarCode.Focus();
  470. //Product = false;
  471. }
  472. DataSet dsReturn = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  473. {
  474. return PMModuleProxy.Service.GetInProductionAndProductionData(item);
  475. }));
  476. if (dsReturn != null)
  477. {
  478. if (dsReturn.Tables.Count == Constant.INT_IS_TWO)
  479. {
  480. if (dsReturn.Tables[0].Rows.Count == Constant.INT_IS_ZERO) //在产表中没有数据
  481. {
  482. //目前不在生产线上也只报损 2015/07/14 modify wangx
  483. DataSet dsDailyDetail = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  484. {
  485. return PMModuleProxy.Service.GetBarCodeInGroutingDailyDetail(item);
  486. }));
  487. if (dsDailyDetail != null && dsDailyDetail.Tables[0].Rows.Count == 0)
  488. {
  489. return notes = "条码无效,无法报损!";
  490. //MessageBox.Show("产品编码为" + item + " 条码无效,无法报损!",
  491. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  492. //this.txtBarCode.Text = "";
  493. //this.txtBarCode.Focus();
  494. //Product = false;
  495. }
  496. return notes = "不是在产产品不能报损!";
  497. // 2015/07/14 modify wangx end
  498. ////产品不在生产线上
  499. //MessageBox.Show("产品编码为" + item + " 不是在产产品不能报损!",
  500. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  501. //this.txtBarCode.Text = "";
  502. //this.txtBarCode.Focus();
  503. //////判断条码是否有效
  504. //Product = false;
  505. }
  506. //获取产品情况以及经过工序情况
  507. DataTable dtInProduction = dsReturn.Tables[0];
  508. //2015-05-26 begin modify by wangx
  509. if (dtInProduction != null && dtInProduction.Rows.Count > 0)
  510. {
  511. if (dtInProduction.Rows[0]["endmode"].ToString() == "2")//代表已经产成品
  512. {
  513. return notes = "已经生产完成,无法报损!";
  514. //MessageBox.Show("产品编码为" + item + " 已经生产完成,无法报损!",
  515. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  516. //this.txtBarCode.Text = "";
  517. //this.txtBarCode.Focus();
  518. //Product = false;
  519. }
  520. if (dtInProduction.Rows[0]["IsReworkFlag"].ToString() == "1")//代表已经返工
  521. {
  522. return notes = "已经是返工状态,无法报损!";
  523. //MessageBox.Show("产品编码为" + item + " 已经是返工状态,无法报损!",
  524. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  525. //this.txtBarCode.Text = "";
  526. //this.txtBarCode.Focus();
  527. //Product = false;
  528. }
  529. }
  530. //2015-05-26 end
  531. //获取节点类型
  532. //如果存在该类型的字段的话,判断一下
  533. // string a = dtInProduction.Columns[dtInProduction.Columns.Count - 1].ColumnName;
  534. foreach (DataColumn dcFor in dtInProduction.Columns)
  535. {
  536. if (dcFor.ColumnName.ToLower() == "proceduremodeltypeid")
  537. {
  538. int modelType = Convert.ToInt32(dtInProduction.Rows[0]["ProcedureModelTypeID"]);
  539. // 装车,入窑,出窑,窑车补件不能报损
  540. if (modelType == Constant.INT_IS_ONE || modelType == Constant.INT_IS_TWO || modelType == Constant.INT_IS_THREE || modelType == Constant.INT_IS_SIX)
  541. {
  542. return notes = "处于无法报损的特殊工序中!";
  543. //某些特殊工序不可报损
  544. //MessageBox.Show("产品编码为" + item + " 处于无法报损的特殊工序中!",
  545. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  546. //this.txtBarCode.Text = "";
  547. //this.txtBarCode.Focus();
  548. //Product = false;
  549. }
  550. }
  551. }
  552. List<InProductionEntity> inProductionList = DataConvert.TableConvertToObject<InProductionEntity>(dtInProduction);
  553. if (inProductionList.Count != Constant.INT_IS_ZERO)
  554. {
  555. this._isScrapProductEntity = inProductionList[0];
  556. }
  557. else
  558. {
  559. if (this._updateEntity == null)
  560. {
  561. return null;
  562. }
  563. if (this._updateEntity.GoodsLevelTypeID != this._goodsLevelTypeID)
  564. {
  565. return null;
  566. }
  567. //失败,条码不存在数据或无法转换
  568. MessageBox.Show(Messages.MSG_PM_W007,
  569. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  570. return null;
  571. }
  572. }
  573. else
  574. {
  575. if (this._updateEntity == null)
  576. {
  577. return null;
  578. }
  579. if (this._updateEntity.GoodsLevelTypeID != this._goodsLevelTypeID)
  580. {
  581. return null;
  582. }
  583. //失败
  584. MessageBox.Show(Messages.MSG_PM_W007,
  585. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  586. }
  587. }
  588. }
  589. catch (Exception ex)
  590. {
  591. // 对异常进行共通处理
  592. ExceptionManager.HandleEventException(this.ToString(),
  593. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  594. }
  595. return notes;
  596. }
  597. #region 私有方法
  598. /// <summary>
  599. /// 加载数据
  600. /// </summary>
  601. private void BindEntity()
  602. {
  603. try
  604. {
  605. //条码控件不可用
  606. this.txtBarCode.Enabled = false;
  607. this._updateEntity = new ScrapProductEntity();
  608. this._updateEntity.BarCode = _barCode;
  609. this._updateEntity.ScrapProductID = _editSPId;
  610. //绑定生产工序集合
  611. DataSet dsReturn = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  612. {
  613. return PMModuleProxy.Service.GetInProductionAndProductionData(_barCode);
  614. }));
  615. if (dsReturn != null)
  616. {
  617. if (dsReturn.Tables.Count == Constant.INT_IS_TWO)
  618. {
  619. //获取产品情况以及经过工序情况
  620. DataTable dtInProduction = dsReturn.Tables[0];
  621. DataTable dtProductionData = dsReturn.Tables[1];
  622. //foreach (DataRow drFor in dtInProduction.Rows)
  623. //{
  624. // this.txtProductionLineName.Text = drFor["ProductionLineName"].ToString();
  625. // this.txtGoodsCode.Text = drFor["GoodsCode"].ToString();
  626. // this.txtGroutingLine.Text = drFor["GroutingLineCode"].ToString();
  627. // this.txtMouldCode.Text = drFor["GroutingMouldCode"].ToString();
  628. // this.txtGroutingUser.Text = drFor["GroutingUserCode"].ToString();
  629. //}
  630. //this.cbResponProcedure.DataSource = dtProductionData;
  631. //this.cbResponProcedure.DisplayMember = "ProcedureName";
  632. //this.cbResponProcedure.ValueMember = "ProcedureID";
  633. this._productionDataList = DataTableToListByProductionData(dtProductionData);
  634. if (this._productionDataList.Count != Constant.INT_IS_ZERO)
  635. {
  636. this._scrapProductResponProcedure = this._productionDataList[0];
  637. }
  638. }
  639. }
  640. //获取报废产品实体
  641. DataSet dsScrap = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  642. {
  643. return PMModuleProxy.Service.GetScrapProduct(this._updateEntity);
  644. }));
  645. if (dsScrap != null)
  646. {
  647. if (dsScrap.Tables.Count != Constant.INT_IS_ZERO)
  648. {
  649. DataRow drScrap = dsScrap.Tables[0].Rows[0];
  650. this._updateEntity.BarCode = drScrap["BarCode"].ToString();
  651. if (drScrap["ProductionLineID"].ToString() != "")
  652. {
  653. this._updateEntity.ProductionLineID = Convert.ToInt32(drScrap["ProductionLineID"]);
  654. this._updateEntity.ProductionLineCode = drScrap["ProductionLineCode"].ToString();
  655. this._updateEntity.ProductionLineName = drScrap["ProductionLineName"].ToString();
  656. //this.txtGoodsCode.Text = drScrap["GoodsCode"].ToString();
  657. //this.txtGroutingLine.Text = drScrap["GroutingLineCode"].ToString();
  658. //this.txtMouldCode.Text = drScrap["GroutingMouldCode"].ToString();
  659. //this.txtGroutingUser.Text = drScrap["GroutingUserCode"].ToString();
  660. this._CompleteProcdureID = Convert.ToInt32(drScrap["ProcedureID"]);
  661. this._CompleteProcdureCode = drScrap["ProcedureCode"].ToString();
  662. //this.txtCompleteProcdure.Text = drScrap["ProcedureName"].ToString();
  663. }
  664. //else //等于空时,取模具信息
  665. //{
  666. // this.txtGoodsCode.Text = drScrap["GoodsCode"].ToString();
  667. // this.txtGroutingLine.Text = drScrap["GroutingLineCode"].ToString();
  668. // this.txtMouldCode.Text = drScrap["GroutingMouldCode"].ToString();
  669. // this.txtGroutingUser.Text = drScrap["GroutingUserCode"].ToString();
  670. //}
  671. if (drScrap["logoid"].ToString() != "")
  672. {
  673. this._LogoID = Convert.ToInt32(drScrap["logoid"]);
  674. }
  675. this._updateEntity.GoodsID = Convert.ToInt32(drScrap["GoodsID"]);
  676. this._updateEntity.GoodsCode = drScrap["GoodsCode"].ToString();
  677. this._updateEntity.GoodsName = drScrap["GoodsName"].ToString();
  678. this._updateEntity.GroutingDailyID = Convert.ToInt32(drScrap["GroutingDailyID"]);
  679. this._updateEntity.GroutingDailyDetailID = Convert.ToInt32(drScrap["GroutingDailyDetailID"]);
  680. this._updateEntity.GroutingDate = Convert.ToDateTime(drScrap["GroutingDate"]);
  681. this._updateEntity.GroutingLineID = Convert.ToInt32(drScrap["GroutingLineID"]);
  682. this._updateEntity.GroutingLineCode = drScrap["GroutingLineCode"].ToString();
  683. this._updateEntity.GroutingLineName = drScrap["GroutingLineName"].ToString();
  684. this._updateEntity.GMouldTypeID = Convert.ToInt32(drScrap["GMouldTypeID"]);
  685. this._updateEntity.GroutingLineDetailID = Convert.ToInt32(drScrap["GroutingLineDetailID"]);
  686. this._updateEntity.GroutingMouldCode = drScrap["GroutingMouldCode"].ToString();
  687. this._updateEntity.MouldCode = drScrap["MouldCode"].ToString();
  688. this._updateEntity.GoodsLevelTypeID = Convert.ToInt32(drScrap["GoodsLevelTypeID"]);
  689. this._updateEntity.GoodsLevelID = Convert.ToInt32(drScrap["GoodsLevelID"]);
  690. this._updateEntity.ScrapDate = Convert.ToDateTime(drScrap["ScrapDate"]);
  691. this._updateEntity.Rreason = drScrap["Rreason"].ToString();
  692. this._updateEntity.Remarks = drScrap["Remarks"].ToString();
  693. this._updateEntity.AuditStatus = Convert.ToInt32(drScrap["AuditStatus"]);
  694. this._updateEntity.ResponType = Convert.ToInt32(drScrap["ResponType"]);
  695. this._updateEntity.SpecialRepairflag = Convert.ToInt32(drScrap["SpecialRepairflag"]);
  696. this.SpecialRepairFlag = Convert.ToInt32(drScrap["SpecialRepairflag"]);
  697. if (drScrap["Auditor"] != DBNull.Value)
  698. {
  699. this._updateEntity.Auditor = Convert.ToInt32(drScrap["Auditor"]);
  700. }
  701. if (drScrap["AuditDate"] != DBNull.Value)
  702. {
  703. this._updateEntity.AuditlDate = Convert.ToDateTime(drScrap["AuditDate"]);
  704. }
  705. this._updateEntity.SettlementFlag = Convert.ToInt32(drScrap["SettlementFlag"]);
  706. if (drScrap["ResponProcedureID"] != DBNull.Value) //ProcedureID--改到ResponProcedureID
  707. {
  708. this._updateEntity.ResponProcedureID = Convert.ToInt32(drScrap["ResponProcedureID"]);
  709. }
  710. if (drScrap["UserID"] != DBNull.Value)
  711. {
  712. this._updateEntity.ResponUserID = Convert.ToInt32(drScrap["UserID"]);
  713. }
  714. if (drScrap["UserCode"] != DBNull.Value)
  715. {
  716. this._updateEntity.ResponUserCode = drScrap["UserCode"].ToString();
  717. }
  718. if (drScrap["UserName"] != DBNull.Value)
  719. {
  720. this._updateEntity.ResponUserName = drScrap["UserName"].ToString();
  721. }
  722. if (drScrap["ScrapFine"] != DBNull.Value)
  723. {
  724. this._updateEntity.ScrapFine = Convert.ToDecimal(drScrap["ScrapFine"]);
  725. }
  726. this.cmbAuditStatus.SelectedValue = this._updateEntity.AuditStatus;
  727. if (this._updateEntity.GoodsLevelTypeID != this._goodsLevelTypeID ||
  728. (this._updateEntity.AuditStatus == Constant.INT_IS_ONE || this._updateEntity.AuditStatus == Constant.INT_IS_TWO)) //除关闭窗体外所有功能不可用
  729. {
  730. this.txtBarCode.Enabled = false;
  731. //this.txtGoodsCode.Enabled = false;
  732. //this.txtProductionLineName.Enabled = false;
  733. //this.cbResponProcedure.Enabled = false;
  734. // 报损日期不能修改
  735. //this.txtScrapDate.Enabled = false;
  736. this.cmbRreason.Enabled = false;
  737. this.txtRemarks.Enabled = false;
  738. //this.scbUser.Enabled = false;
  739. this.dgvResponsible.Enabled = false;
  740. this.btnSave.Enabled = false;
  741. //this.btnViewApprover.Visible = false;
  742. this.cmbAuditStatus.Enabled = false;
  743. }
  744. }
  745. }
  746. else
  747. {
  748. this.Close();
  749. return;
  750. }
  751. //获取报废责任工序实体
  752. if (Convert.ToInt32(_updateEntity.ResponType) == Constant.INT_IS_THREE)
  753. {
  754. DataSet dsResPro = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  755. {
  756. return PMModuleProxy.Service.GetResponProcedureBySPId(Convert.ToInt32(_updateEntity.ScrapProductID));
  757. }));
  758. this._updateProcedureEntity = new ResponProcedureEntity();
  759. if (dsResPro != null && dsResPro.Tables[0].Rows.Count > 0) //如果原来存在责任工序实体
  760. {
  761. DataRow drResPro = dsResPro.Tables[0].Rows[0];
  762. this._updateProcedureEntity.ResponProcedureID = Convert.ToInt32(drResPro["ResponProcedureID"]);
  763. //this.scbUser.Enabled = false;
  764. }
  765. this._updateProcedureEntity.BarCode = _updateEntity.BarCode;
  766. }
  767. //获取报废责任人实体集合
  768. if (Convert.ToInt32(_updateEntity.ResponType) != Constant.INT_IS_ONE)
  769. {
  770. this._updateScrapResponsibleList = new List<ScrapResponsibleEntity>();
  771. DataSet dsResponsible = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  772. {
  773. return PMModuleProxy.Service.GetScrapResponsibleBySPId(Convert.ToInt32(_updateEntity.ScrapProductID));
  774. }));
  775. DataTableToListByScrapResponsible(dsResponsible);
  776. }
  777. //控件赋值
  778. this.txtBarCode.Text = _updateEntity.BarCode;
  779. //this.txtGoodsCode.Text = _updateEntity.GoodsCode;
  780. //this.txtProductionLineName.Text = _updateEntity.ProductionLineName;
  781. //this.cbResponProcedure.SelectedValue = _updateEntity.ResponProcedureID;
  782. try
  783. {
  784. this.cmbRreason.Text = _updateEntity.Rreason;
  785. }
  786. catch
  787. {
  788. this.cmbRreason.Text = "";
  789. }
  790. this.txtRemarks.Text = _updateEntity.Remarks;
  791. //this.txtScrapFine.Text = _updateEntity.ScrapFine.ToString();
  792. //this._updateEntity.ScrapFine
  793. if (this._updateEntity.ResponUserID != null)
  794. {
  795. // scbUser.SearchedPKMember = Convert.ToInt32(_updateEntity.ResponUserID);
  796. // scbUser.InitValue(_updateEntity.ResponUserName, _updateEntity.ResponUserCode);
  797. //this.dkUser.UserID = _updateEntity.ResponUserID;
  798. // this.dkUser.UserCode = _updateEntity.ResponUserCode;
  799. // this.dkUser.UserName = _updateEntity.ResponUserName;
  800. }
  801. else if (this._scrapResponsibleList.Count != Constant.INT_IS_ZERO)
  802. {
  803. //scbUser.SearchedPKMember = Convert.ToInt32(_scrapResponsibleList[0].UserID);
  804. //scbUser.InitValue(_scrapResponsibleList[0].UserName, _scrapResponsibleList[0].UserCode);
  805. //this.dkUser.UserID = _scrapResponsibleList[0].UserID;
  806. // this.dkUser.UserCode = _scrapResponsibleList[0].UserCode;
  807. // this.dkUser.UserName = _scrapResponsibleList[0].UserName;
  808. }
  809. }
  810. catch (Exception ex)
  811. {
  812. throw ex;
  813. }
  814. }
  815. /// <summary>
  816. /// 数据表到实体转换
  817. /// </summary>
  818. /// <param name="dsScrapResponsible"></param>
  819. private void DataTableToListByScrapResponsible(DataSet dsScrapResponsible)
  820. {
  821. foreach (DataRow drFor in dsScrapResponsible.Tables[0].Rows)
  822. {
  823. ScrapResponsibleEntity srEntity = new ScrapResponsibleEntity();
  824. srEntity.ResponsibleID = Convert.ToInt32(drFor["ResponsibleID"]);
  825. srEntity.ScrapProductID = Convert.ToInt32(drFor["ScrapProductID"]);
  826. srEntity.BarCode = drFor["BarCode"].ToString();
  827. srEntity.ResponType = Convert.ToInt32(drFor["ResponType"]);
  828. if (drFor["ResponProcedureID"] != DBNull.Value)
  829. {
  830. srEntity.ResponProcedureID = Convert.ToInt32(drFor["ResponProcedureID"]);
  831. }
  832. srEntity.StaffID = Convert.ToInt32(drFor["StaffID"]);
  833. srEntity.UserID = Convert.ToInt32(drFor["UserID"]);
  834. srEntity.UserCode = drFor["UserCode"].ToString();
  835. srEntity.UJobsID = Convert.ToInt32(drFor["UJobsID"]);
  836. srEntity.SJobsID = Convert.ToInt32(drFor["SJobsID"]);
  837. srEntity.StaffStatus = Convert.ToInt32(drFor["StaffStatus"]);
  838. srEntity.AccountID = Convert.ToInt32(drFor["AccountID"]);
  839. srEntity.CreateTime = Convert.ToDateTime(drFor["CreateTime"]);
  840. srEntity.CreateUserID = Convert.ToInt32(drFor["CreateUserID"]);
  841. srEntity.UpdateTime = Convert.ToDateTime(drFor["UpdateTime"]);
  842. srEntity.UpdateUserID = Convert.ToInt32(drFor["UpdateUserID"]);
  843. srEntity.OPTimeStamp = Convert.ToDateTime(drFor["OPTimeStamp"]);
  844. srEntity.UserName = drFor["userName"].ToString();
  845. this._scrapResponsibleList.Add(srEntity);
  846. }
  847. }
  848. /// <summary>
  849. /// 数据表到实体转换
  850. /// </summary>
  851. /// <param name="dtProductionData"></param>
  852. /// <returns></returns>
  853. private List<ProductionDataEntity> DataTableToListByProductionData(DataTable dtProductionData)
  854. {
  855. List<ProductionDataEntity> pdList = new List<ProductionDataEntity>();
  856. foreach (DataRow drFor in dtProductionData.Rows)
  857. {
  858. ProductionDataEntity pdEntity = new ProductionDataEntity();
  859. pdEntity.ProductionDataID = Convert.ToInt32(drFor["ProductionDataID"]);
  860. pdEntity.ProcedureID = Convert.ToInt32(drFor["ProcedureID"]);
  861. pdEntity.ProcedureCode = drFor["ProcedureCode"].ToString();
  862. pdEntity.ProcedureName = drFor["ProcedureName"].ToString();
  863. pdList.Add(pdEntity);
  864. }
  865. return pdList;
  866. }
  867. #endregion
  868. }
  869. }