F_PM_2203.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_2203.cs
  5. * 2.功能描述:半成品检验-新增、编辑
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2016/06/28 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Drawing.Drawing2D;
  15. using System.Drawing.Imaging;
  16. using System.IO;
  17. using System.Windows.Forms;
  18. using Dongke.IBOSS.PRD.Basics.BaseControls;
  19. using Dongke.IBOSS.PRD.Basics.BaseResources;
  20. using Dongke.IBOSS.PRD.Client.CommonModule;
  21. using Dongke.IBOSS.PRD.WCF.DataModels;
  22. using Dongke.IBOSS.PRD.WCF.Proxys;
  23. namespace Dongke.IBOSS.PRD.Client.PMModule
  24. {
  25. public partial class F_PM_2203 : FormBase
  26. {
  27. #region 成员变量
  28. // 当前操作数据表
  29. private DataTable _dtBarCode = null;
  30. // 当前产品条码
  31. private string _barcode;
  32. // 当前产品ID
  33. private int _goodsID = 0;
  34. // 当前工序ID
  35. private int _procedureID = 0;
  36. // 当前是否为编辑 true
  37. private bool _isEdit = false;
  38. // 临时数
  39. private int _tempcount = 0;
  40. // 调用实例对象
  41. F_PM_2202 _frm1202 = null;
  42. // 员工数据集
  43. private DataSet _dsStaff = null;
  44. // 漏检员工数据集
  45. private DataSet _dsMissedStaff = null;
  46. // 图片数据集
  47. private DataSet _dsImage = null;
  48. // 生产数据ID
  49. private int _productionDataID = 0;
  50. // 缺陷生产数据ID
  51. private int _defectProductionDataID = 0;
  52. // 图片字节集
  53. private List<byte[]> _PicByte = new List<byte[]>();
  54. // 缩略图片字节集
  55. private List<byte[]> _smallByte = new List<byte[]>();
  56. // 行索引
  57. private int _rowIndex = 0;
  58. // 当前缺陷编码
  59. private string _currentDutyCode = "";
  60. // 当前缺陷位置编码
  61. private string _currentDefectPositionCode = "";
  62. // 当前缺陷责任工序编码
  63. private string _currentDefectProcedureCode = "";
  64. // 当前缺陷工号编码
  65. private string _currentDefectUserCode = "";
  66. // 当前漏检工号
  67. private string _currentMissedUserCode = "";
  68. // 默认责任工号数据源
  69. private DataTable _dtDutyProcedureUser = null;
  70. // 是否干补
  71. private int SpecialRepairflag = 0;//0未干补 1干补
  72. //默认缺陷对应的工种
  73. private DataTable _defaultJobsID = null;
  74. // 缺陷扣罚关系所有数据源
  75. private DataTable _dtDefectFineRelation = null;
  76. // 缺陷扣除数关系所有数据源
  77. private DataTable _dtDefectDeductionRelation = null;
  78. // 默认缺陷扣罚关系所有数据源
  79. private DataTable _dtDefaultDefectFineRelation = null;
  80. // 默认缺陷扣除数关系所有数据源
  81. private DataTable _dtDefaultDefectDeductionRelation = null;
  82. private int? _reworkprocedure = null;
  83. #endregion
  84. #region 构造函数
  85. public F_PM_2203()
  86. {
  87. InitializeComponent();
  88. }
  89. /// <summary>
  90. ///
  91. /// </summary>
  92. /// <param name="dtBarCode">当前操作的数据表</param>
  93. /// <param name="barcode">当前产品条码</param>
  94. /// <param name="goodsID">当前产品ID</param>
  95. /// <param name="tempcount">当前累加数,防止重复</param>
  96. /// <param name="procedureID">当前工序</param>
  97. /// <param name="titleText">当前窗体名称</param>
  98. /// <param name="isEdit">false 新建 true编辑</param>
  99. /// <param name="frm1202">调用实例对象</param>
  100. /// <param name="dsStaff">员工数据集</param>
  101. /// <param name="dsImage">图片数据集</param>
  102. /// <param name="picByte">原图字节数组</param>
  103. /// <param name="smallByte">缩略图字节数组</param>
  104. /// <param name="rowIndex">编辑行号标识</param>
  105. public F_PM_2203(DataTable dtBarCode
  106. , string barcode
  107. , int goodsID
  108. , int tempcount
  109. , int procedureID
  110. , string titleText
  111. , bool isEdit
  112. , F_PM_2202 frm1202
  113. , DataSet dsStaff
  114. , DataSet dsMissedStaff
  115. , DataSet dsImage
  116. , List<byte[]> picByte
  117. , List<byte[]> smallByte
  118. , int rowIndex
  119. , int? reworkprocedure)
  120. {
  121. InitializeComponent();
  122. this.Text = titleText;
  123. this._dtBarCode = dtBarCode;
  124. this._barcode = barcode;
  125. this._goodsID = goodsID;
  126. this._procedureID = procedureID;
  127. this._isEdit = isEdit;
  128. this._tempcount = tempcount;
  129. this._frm1202 = frm1202;
  130. this._dsStaff = dsStaff;
  131. this._dsMissedStaff = dsMissedStaff;
  132. this._dsImage = dsImage;
  133. this._rowIndex = rowIndex;
  134. this.btnSave.Text = ButtonText.BTN_SAVE;
  135. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  136. this._reworkprocedure = reworkprocedure;
  137. }
  138. #endregion
  139. #region 事件
  140. /// <summary>
  141. /// 窗体加载事件
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. private void F_PM_1203_Load(object sender, EventArgs e)
  146. {
  147. try
  148. {
  149. this.dgvDefectStaff.AutoGenerateColumns = false;
  150. #region 加载缺陷
  151. DataSet dsResultDefect = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  152. {
  153. return SystemModuleProxy.Service.GetAllSemicheckDefect();
  154. }));
  155. if (dsResultDefect != null && dsResultDefect.Tables[0].Rows.Count > 0)
  156. {
  157. DataView dv = dsResultDefect.Tables[0].DefaultView;
  158. dv.RowFilter = "ValueFlag='1'";
  159. this.dropDuty.DisplayMember = "DefectFlagName";
  160. this.dropDuty.ValueMember = "DEFECTID";
  161. this.dropDuty.DataSource = dv.ToTable();
  162. }
  163. #endregion 加载缺陷和缺陷位置 end
  164. #region 加载缺陷位置
  165. DataSet dsResultPosition = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  166. {
  167. return SystemModuleProxy.Service.GetAllScdefectPosition();
  168. }));
  169. if (dsResultPosition != null && dsResultPosition.Tables[0].Rows.Count > 0)
  170. {
  171. DataView dv = dsResultPosition.Tables[0].DefaultView;
  172. dv.RowFilter = "ValueFlag='1'";
  173. this.dropDefectLocation.DisplayMember = "DefectPositionFlagName";
  174. this.dropDefectLocation.ValueMember = "DEFECTPOSITIONID";
  175. this.dropDefectLocation.DataSource = dv.ToTable();
  176. }
  177. #endregion 加载缺陷位置 end
  178. #region 加载条码对应的返工工序
  179. DataSet dsProcedure = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  180. {
  181. return PMModuleProxy.Service.GetSemiCheckPassProcedure(this._barcode);
  182. }));
  183. if (dsProcedure != null && dsProcedure.Tables[0].Rows.Count > 0)
  184. {
  185. DataTable dtProcedure = dsProcedure.Tables[0];
  186. DataRow dr = dtProcedure.NewRow();
  187. dr["ProcedureName"] = "";
  188. dr["ProcedureID"] = -1;
  189. dtProcedure.Rows.InsertAt(dr, 0);
  190. this.dropDutyProcedure.DataSource = dtProcedure;
  191. this.dropDutyProcedure.DisplayMember = "ProcedureName";
  192. this.dropDutyProcedure.ValueMember = "ProcedureID";
  193. }
  194. #endregion
  195. #region 加载责任工号
  196. this.dropDutyUser.DisplayMember = "UserCode";
  197. this.dropDutyUser.ValueMember = "UserID";
  198. this.dropDutyUser.DataSource = GetDutyProcedureUser();
  199. #endregion
  200. if (this._reworkprocedure != null && this._reworkprocedure != -1)
  201. {
  202. this.dropDutyProcedure.SelectedValue = this._reworkprocedure;
  203. dropDutyProcedure_Validating(null, null);
  204. }
  205. ////漏检工号数据源
  206. //this.dropMissUser.DisplayMember = "UserCode";
  207. //this.dropMissUser.ValueMember = "UserID";
  208. //this.dropMissUser.DataSource = this._dtDutyProcedureUser;
  209. //this.dropJobs.DisplayMember = "JobsName";
  210. //this.dropJobs.ValueMember = "Jobs";
  211. //this.dropJobs.DataSource = GetDutyProcedureJobs(); // 默认空数据源,随着责任工号而改变
  212. // 缺陷扣罚
  213. //DataSet dsDefectFine = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  214. //{
  215. // return SystemModuleProxy.Service.GetDictionaryData(0, "ASE002");
  216. //}));
  217. //DataRow dr = dsDefectFine.Tables[0].NewRow();
  218. //dr["DictionaryID"] = -1;
  219. //dr["DictionaryValue"] = "";
  220. //dsDefectFine.Tables[0].Rows.InsertAt(dr, 0);
  221. //dsDefectFine.Tables[0].AcceptChanges();
  222. //this.cmbDefectFine.DisplayMember = "DictionaryValue";
  223. //this.cmbDefectFine.ValueMember = "DictionaryID";
  224. //this.cmbDefectFine.DataSource = dsDefectFine.Tables[0];
  225. if (this._isEdit)
  226. {
  227. this.dropDuty.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectID"].ToString();
  228. this._currentDutyCode = this._dtBarCode.Rows[this._rowIndex]["DefectCode"].ToString();
  229. // add 2016/01/06 wangx
  230. //if (this._dtDefectFineRelation != null)
  231. //{
  232. // DataRow[] r7 = this._dtDefectFineRelation.Select("defectid=" + this.dropDuty.SelectedValue);
  233. // if (r7.Length > 0)
  234. // {
  235. // DataTable dtNew = r7.CopyToDataTable();
  236. // DataRow dr = dtNew.NewRow();
  237. // dr["DefectFineID"] = -1;
  238. // dr["DefectFineCode"] = "";
  239. // dtNew.Rows.InsertAt(dr, 0);
  240. // dtNew.AcceptChanges();
  241. // //this.cmbDefectFine.DisplayMember = "DefectFineCode";
  242. // //this.cmbDefectFine.ValueMember = "DefectFineID";
  243. // //this.cmbDefectFine.DataSource = dtNew;
  244. // }
  245. // else
  246. // {
  247. // //this.cmbDefectFine.DisplayMember = "DefectFineCode";
  248. // //this.cmbDefectFine.ValueMember = "DefectFineID";
  249. // //this.cmbDefectFine.DataSource = this._dtDefaultDefectFineRelation;
  250. // }
  251. //}
  252. //if (this._dtDefectDeductionRelation != null)
  253. //{
  254. // DataRow[] r7 = this._dtDefectDeductionRelation.Select("defectid=" + this.dropDuty.SelectedValue);
  255. // if (r7.Length > 0)
  256. // {
  257. // DataTable dtNew = r7.CopyToDataTable();
  258. // DataRow dr = dtNew.NewRow();
  259. // dr["DefectDeductionID"] = -1;
  260. // //dr["DefectDeductionNum"] = "";
  261. // dtNew.Rows.InsertAt(dr, 0);
  262. // dtNew.AcceptChanges();
  263. // //this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
  264. // //this.cmbDefectDeduction.ValueMember = "DefectDeductionNum";
  265. // //this.cmbDefectDeduction.DataSource = dtNew;
  266. // }
  267. // else
  268. // {
  269. // //this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
  270. // //this.cmbDefectDeduction.ValueMember = "DefectDeductionNum";
  271. // //this.cmbDefectDeduction.DataSource = this._dtDefaultDefectDeductionRelation;
  272. // }
  273. //}
  274. // add end
  275. // 缺陷选定后事件
  276. //BindDutyDefect(this._barcode, Convert.ToInt32(this.dropDuty.SelectedValue));
  277. // 缺陷位置
  278. this.dropDefectLocation.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectPositionID"].ToString();
  279. this._currentDefectPositionCode = this._dtBarCode.Rows[this._rowIndex]["DefectPositionCode"].ToString();
  280. // 责任工序
  281. if (this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"].ToString() != Constant.INT_IS_ZERO.ToString()
  282. && this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"].ToString() != string.Empty)
  283. {
  284. this.dropDutyProcedure.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"].ToString();
  285. this.dropDutyProcedure.Text = this._dtBarCode.Rows[this._rowIndex]["DefectProcedureName"].ToString();
  286. this._currentDefectProcedureCode = this._dtBarCode.Rows[this._rowIndex]["DefectProcedureCode"].ToString();
  287. this._defectProductionDataID = Convert.ToInt32(this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"]);
  288. // 责任工种
  289. //SetDutyCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
  290. string DutyProcedure = this.dropDutyProcedure.SelectedValue.ToString();
  291. DataTable dtDutyProcedureCode = this.dropDutyProcedure.DataSource as DataTable;
  292. if (dtDutyProcedureCode.Rows.Count > Constant.INT_IS_ZERO)
  293. {
  294. DataRow[] drJobs = dtDutyProcedureCode.Select("ProcedureID=" + DutyProcedure);
  295. if (drJobs.Length > Constant.INT_IS_ZERO)
  296. {
  297. this._currentDefectProcedureCode = drJobs[0]["ProcedureCode"].ToString();
  298. }
  299. }
  300. //DataSet dsDutyCode = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  301. //{
  302. // return PMModuleProxy.Service.GetDutyProcedureCodeByBarCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
  303. //}));
  304. //if (dsDutyCode != null && dsDutyCode.Tables.Count > Constant.INT_IS_ZERO
  305. // && dsDutyCode.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  306. //{
  307. // this.dropDutyUser.DisplayMember = "UserCode";
  308. // this.dropDutyUser.ValueMember = "UserID";
  309. // this.dropDutyUser.DataSource = dsDutyCode.Tables[0];
  310. this.dropDutyUser.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectUserID"].ToString();
  311. // this._currentDefectUserCode = this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"].ToString();
  312. this._productionDataID = Convert.ToInt32(this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"].ToString());
  313. // DataSet dsDutyJobs = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  314. // {
  315. // return PMModuleProxy.Service.GetDutyJobsCodeByUser(Convert.ToInt32(this.dropDutyUser.SelectedValue), this._productionDataID);
  316. // }));
  317. // if (dsDutyJobs != null && dsDutyJobs.Tables.Count > Constant.INT_IS_ZERO
  318. // && dsDutyJobs.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  319. // {
  320. // //this.dropJobs.DisplayMember = "JobsName";
  321. // //this.dropJobs.ValueMember = "JobsID";
  322. // //this.dropJobs.DataSource = dsDutyJobs.Tables[0];
  323. // //this.dropJobs.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["Jobs"].ToString();
  324. // }
  325. //}
  326. }
  327. else
  328. {
  329. this.dropDutyProcedure.SelectedValue = null;
  330. this.dropDutyProcedure.Text = "";
  331. this._currentDefectProcedureCode = "";
  332. // 没有责任工序,获取号及工种
  333. if (this._dtDutyProcedureUser != null && this._dtDutyProcedureUser.Rows.Count > Constant.INT_IS_ZERO)
  334. {
  335. this.dropDutyUser.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectUserID"].ToString();
  336. this._currentDefectUserCode = this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"].ToString();
  337. this._productionDataID = Convert.ToInt32(this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"].ToString());
  338. //DataSet dsDutyJobs = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  339. //{
  340. // return SystemModuleProxy.Service.GetAllJobsByUserID(Convert.ToInt32(this.dropDutyUser.SelectedValue));
  341. //}));
  342. //if (dsDutyJobs != null && dsDutyJobs.Tables.Count > Constant.INT_IS_ZERO
  343. // && dsDutyJobs.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  344. //{
  345. // //this.dropJobs.DisplayMember = "JobsName";
  346. // //this.dropJobs.ValueMember = "Jobs";
  347. // //this.dropJobs.DataSource = dsDutyJobs.Tables[0];
  348. // //this.dropJobs.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["Jobs"].ToString();
  349. //}
  350. }
  351. }
  352. // 漏检工号
  353. //if (this._dtBarCode.Rows[this._rowIndex]["MissedUserID"].ToString() != "-1")
  354. //{
  355. // //this.dropMissUser.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["MissedUserID"].ToString();
  356. // //this.dropMissUser.Text = this._dtBarCode.Rows[this._rowIndex]["MissedUserName"].ToString();
  357. // //this._currentMissedUserCode = this._dtBarCode.Rows[this._rowIndex]["MissedUserCode"].ToString();
  358. //}
  359. this.txtRemarks.Text = this._dtBarCode.Rows[this._rowIndex]["DefectRemarks"].ToString();
  360. this.dgvDefectStaff.DataSource = this._dsStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())];
  361. // BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount.ToString())]);
  362. //if (this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString() != "-1"
  363. // && this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString() != string.Empty)
  364. //{
  365. // // this.cmbDefectFine.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString();
  366. //}
  367. //if (this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"].ToString() != "-1"
  368. // && this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"].ToString() != string.Empty)
  369. //{
  370. // //this.cmbDefectDeduction.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"].ToString();
  371. //}
  372. }
  373. }
  374. catch (Exception ex)
  375. {
  376. // 对异常进行共通处理
  377. ExceptionManager.HandleEventException(this.ToString(),
  378. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  379. }
  380. }
  381. /// <summary>
  382. /// 缺陷验证事件
  383. /// </summary>
  384. /// <param name="sender"></param>
  385. /// <param name="e"></param>
  386. private void dropDuty_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  387. {
  388. try
  389. {
  390. if (this.dropDuty.SelectedValue != null && this.dropDuty.SelectedValue.ToString() != string.Empty)
  391. {
  392. if (!this.dropDuty.ReadOnly)
  393. {
  394. //选定缺陷值
  395. string DutyValue = this.dropDuty.SelectedValue.ToString();
  396. DataTable dtDuty = this.dropDuty.DataSource as DataTable;
  397. string newDefectCode = "";
  398. if (dtDuty.Rows.Count > Constant.INT_IS_ZERO)
  399. {
  400. DataRow[] dr = dtDuty.Select("DefectID=" + DutyValue);
  401. if (dr.Length > Constant.INT_IS_ZERO)
  402. {
  403. newDefectCode = dr[0]["DefectCode"].ToString();
  404. //当前缺陷编码
  405. this._currentDutyCode = dr[0]["DefectCode"].ToString();
  406. }
  407. }
  408. }
  409. }
  410. }
  411. catch (Exception ex)
  412. {
  413. // 对异常进行共通处理
  414. ExceptionManager.HandleEventException(this.ToString(),
  415. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  416. }
  417. }
  418. /// <summary>
  419. /// 责任工序验证事件
  420. /// </summary>
  421. /// <param name="sender"></param>
  422. /// <param name="e"></param>
  423. private void dropDutyProcedure_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  424. {
  425. try
  426. {
  427. //if (this.dropDutyProcedure.SelectedValue != null && this.dropDutyProcedure.SelectedValue.ToString() != string.Empty)
  428. //{
  429. // if (!this.txtRemarks.ReadOnly)
  430. // {
  431. // string DutyProcedure = this.dropDutyProcedure.SelectedValue.ToString();
  432. // DataTable dtDutyProcedureCode = this.dropDutyProcedure.DataSource as DataTable;
  433. // string newDutyProcedureCode = "";
  434. // if (dtDutyProcedureCode.Rows.Count > Constant.INT_IS_ZERO)
  435. // {
  436. // DataRow[] dr = dtDutyProcedureCode.Select("DutyProcedureID=" + DutyProcedure);
  437. // if (dr.Length > Constant.INT_IS_ZERO)
  438. // {
  439. // newDutyProcedureCode = dr[0]["DutyProcedureCode"].ToString();
  440. // //this._currentDefectProcedureCode = dr[0]["DutyProcedureCode"].ToString();
  441. // }
  442. // }
  443. // if (newDutyProcedureCode != this._currentDefectProcedureCode)
  444. // {
  445. // this._currentDefectProcedureCode = newDutyProcedureCode;
  446. // SetDutyCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
  447. // }
  448. // this.txtRemarks.Focus();
  449. // }
  450. //}
  451. //else
  452. //{
  453. // if (this._currentDefectProcedureCode == "")
  454. // return;
  455. // //当前责任工序编码为空串
  456. // this._currentDefectProcedureCode = "";
  457. // //责任工序为空串时,责任工号为当前账套所有生产工号
  458. // this._currentDefectUserCode = "";
  459. // this.dropDutyUser.DataSource = null;
  460. // this.dropDutyUser.DisplayMember = "UserCode";
  461. // this.dropDutyUser.ValueMember = "UserID";
  462. // this.dropDutyUser.DataSource = this._dtDutyProcedureUser;
  463. // this.dropDutyUser.Text = "";
  464. // //责任工序为空串时,责任工种置回空数据源
  465. // //this.dropJobs.DataSource = null;
  466. // //this.dropJobs.DisplayMember = "JobsName";
  467. // //this.dropJobs.ValueMember = "Jobs";
  468. // //this.dropJobs.DataSource = GetDutyProcedureJobs();
  469. // //this.dropJobs.Text = string.Empty;
  470. // //清空缺陷责任员工
  471. // if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", this._tempcount.ToString())))
  472. // {
  473. // DataTable dtStaff = new DataTable(string.Format("TempTable{0}", this._tempcount.ToString()));
  474. // dtStaff.Columns.Add("IsSelected");
  475. // dtStaff.Columns.Add("StaffID");
  476. // dtStaff.Columns.Add("StaffCode");
  477. // dtStaff.Columns.Add("StaffName");
  478. // dtStaff.Columns.Add("StaffTempCount");
  479. // dtStaff.Columns.Add("StaffStatus");
  480. // this._dsStaff.Tables.Add(dtStaff);
  481. // }
  482. // // 获取临时表是否有数据,如果有行,则删除,
  483. // DataTable dtTemp = this._dsStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())];
  484. // if (dtTemp != null)
  485. // {
  486. // // 清空临时表数据
  487. // this._dsStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())].Clear();
  488. // }
  489. //}
  490. if (this.dropDutyProcedure.SelectedValue != null && this.dropDutyProcedure.SelectedValue.ToString() != "-1")
  491. {
  492. if (!this.txtRemarks.ReadOnly)
  493. {
  494. string DutyProcedure = this.dropDutyProcedure.SelectedValue.ToString();
  495. DataTable dtDutyProcedureCode = this.dropDutyProcedure.DataSource as DataTable;
  496. if (dtDutyProcedureCode.Rows.Count > Constant.INT_IS_ZERO)
  497. {
  498. DataRow[] dr = dtDutyProcedureCode.Select("ProcedureID=" + DutyProcedure);
  499. if (dr.Length > Constant.INT_IS_ZERO)
  500. {
  501. this.dropDutyUser.SelectedValue = dr[0]["UserID"].ToString();
  502. this._currentDefectUserCode = dr[0]["UserCode"].ToString();
  503. this._currentDefectProcedureCode = dr[0]["ProcedureCode"].ToString();
  504. this._defectProductionDataID = Convert.ToInt32(dr[0]["ProductionDataID"]);
  505. // 工号带出所有责任人,默认全部选中
  506. BindNoProcedureDutyStaff(this._tempcount);
  507. }
  508. }
  509. }
  510. }
  511. else
  512. {
  513. //默认加载全部生产工号
  514. this.dropDutyUser.DisplayMember = "UserCode";
  515. this.dropDutyUser.ValueMember = "UserID";
  516. this.dropDutyUser.DataSource = this._dtDutyProcedureUser;
  517. this.dropDutyUser.SelectedValue = -1;
  518. this._currentDefectProcedureCode = "";
  519. this._defectProductionDataID = 0;
  520. }
  521. }
  522. catch (Exception ex)
  523. {
  524. // 对异常进行共通处理
  525. ExceptionManager.HandleEventException(this.ToString(),
  526. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  527. }
  528. }
  529. /// <summary>
  530. /// 保存按钮事件
  531. /// </summary>
  532. /// <param name="sender"></param>
  533. /// <param name="e"></param>
  534. private void btnSave_Click(object sender, EventArgs e)
  535. {
  536. try
  537. {
  538. if (this.dropDuty.SelectedValue == null || this.dropDuty.SelectedValue.ToString() == string.Empty)
  539. {
  540. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷"),
  541. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  542. return;
  543. }
  544. if (this.dropDefectLocation.SelectedValue == null || this.dropDefectLocation.SelectedValue.ToString() == string.Empty)
  545. {
  546. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷位置"),
  547. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  548. return;
  549. }
  550. if (this.dropDutyUser.SelectedValue == null || this.dropDutyUser.SelectedValue.ToString() == "-1")
  551. {
  552. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "责任工号"),
  553. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  554. return;
  555. }
  556. //if (this.dropJobs.SelectedValue == null || this.dropJobs.SelectedValue.ToString() == string.Empty)
  557. //{
  558. // MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工种"),
  559. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  560. // return;
  561. //}
  562. if (dropDutyUser.ListBox != null)
  563. {
  564. DataRowView drv = dropDutyUser.ListBox.SelectedItem as DataRowView;
  565. if (drv != null)
  566. {
  567. this._currentDefectUserCode = drv["UserCode"].ToString();
  568. }
  569. }
  570. if (!this._isEdit)
  571. {
  572. // 每次添加不能重复
  573. //if (this._dtBarCode != null && this._dtBarCode.Rows.Count > Constant.INT_IS_ZERO)
  574. //{
  575. // DataRow[] drExist = this._dtBarCode.Select(
  576. // string.Format("DefectID={0} and DefectPositionID={1} and DefectUserID={2}",
  577. // this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue,
  578. // this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue,
  579. // this.dropDutyUser.SelectedValue.ToString() == string.Empty ? 0 : this.dropDutyUser.SelectedValue
  580. // )
  581. // );
  582. // if (drExist.Length > Constant.INT_IS_ZERO)
  583. // {
  584. // // 提示信息
  585. // MessageBox.Show(Messages.MSG_PM_W001,
  586. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  587. // return;
  588. // }
  589. //}
  590. DataRow dr = this._dtBarCode.NewRow();
  591. dr["BarCode"] = this._dtBarCode;
  592. dr["DefectID"] = this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue;
  593. dr["DefectName"] = this.dropDuty.Text;
  594. dr["DefectCode"] = this._currentDutyCode;
  595. dr["DefectPositionID"] = this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue;
  596. dr["DefectPositionName"] = this.dropDefectLocation.Text;
  597. dr["DefectPositionCode"] = this._currentDefectPositionCode;
  598. dr["DefectProcedureID"] = (this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : this.dropDutyProcedure.SelectedValue;
  599. dr["DefectProcedureName"] = this.dropDutyProcedure.Text;
  600. dr["DefectProcedureCode"] = this._currentDefectProcedureCode;
  601. dr["DefectUserID"] = this.dropDutyUser.SelectedValue.ToString() == string.Empty ? 0 : this.dropDutyUser.SelectedValue;
  602. dr["DefectUserName"] = this.dropDutyUser.Text;
  603. dr["DefectUserCode"] = this._currentDefectUserCode;
  604. //dr["Jobs"] = this.dropJobs.SelectedValue.ToString() == string.Empty ? 0 : this.dropJobs.SelectedValue;
  605. //dr["JobsText"] = this.dropJobs.Text;
  606. dr["DefectRemarks"] = this.txtRemarks.Text;
  607. dr["TempCount"] = this._tempcount;
  608. dr["ProductionDataID"] = this._productionDataID;
  609. dr["ProductionDataID"] = this._defectProductionDataID;
  610. //if (this.cmbDefectFine.SelectedValue != null && this.cmbDefectFine.SelectedValue.ToString() != "-1")
  611. //{
  612. // dr["DefectFineID"] = this.cmbDefectFine.SelectedValue;
  613. // dr["DefectFineValue"] = this.cmbDefectFine.Text;
  614. //}
  615. //else
  616. //{
  617. // dr["DefectFineID"] = -1;
  618. // dr["DefectFineValue"] = string.Empty;
  619. //}
  620. //dr["MissedUserID"] = (this.dropMissUser.SelectedValue == null || this.dropMissUser.SelectedValue.ToString() == string.Empty) ? -1 : this.dropMissUser.SelectedValue;
  621. //dr["MissedUserCode"] = this._currentMissedUserCode;
  622. //dr["MissedUserName"] = this.dropMissUser.Text;
  623. dr["IsAllowEdit"] = 1;
  624. //if (this.cmbDefectDeduction.SelectedValue != null && this.cmbDefectDeduction.SelectedValue.ToString() != "-1")
  625. //{
  626. // dr["DefectDeductionID"] = this.cmbDefectDeduction.SelectedValue;
  627. // dr["DefectDeductionNum"] = this.cmbDefectDeduction.Text;
  628. //}
  629. //else
  630. //{
  631. // dr["DefectDeductionID"] = -1;
  632. // dr["DefectDeductionNum"] = string.Empty;
  633. //}
  634. //dr["IsOtherDefect"] = this.chkDefect.Checked ? 1 : 0;
  635. this._dtBarCode.Rows.Add(dr);
  636. }
  637. else
  638. {
  639. if (this._dtBarCode != null && this._dtBarCode.Rows.Count > Constant.INT_IS_ZERO)
  640. {
  641. int currentRowIndex = -1; // 用来匹配是否编辑自己
  642. for (int i = 0; i < this._dtBarCode.Rows.Count; i++)
  643. {
  644. if (Convert.ToInt32(this._dtBarCode.Rows[i]["DefectID"]) ==
  645. (this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : Convert.ToInt32(this.dropDuty.SelectedValue))
  646. &&
  647. Convert.ToInt32(this._dtBarCode.Rows[i]["DefectPositionID"]) ==
  648. (this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : Convert.ToInt32(this.dropDefectLocation.SelectedValue))
  649. &&
  650. Convert.ToInt32(this._dtBarCode.Rows[i]["DefectProcedureID"].ToString() == "" ? 0 : this._dtBarCode.Rows[i]["DefectProcedureID"]) ==
  651. ((this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : Convert.ToInt32(this.dropDutyProcedure.SelectedValue))
  652. )
  653. {
  654. currentRowIndex = i;
  655. break;
  656. }
  657. }
  658. if (currentRowIndex != -Constant.INT_IS_ONE && currentRowIndex != this._rowIndex) // 更新后会有重复
  659. {
  660. // 提示信息
  661. MessageBox.Show(Messages.MSG_PM_W001,
  662. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  663. return;
  664. }
  665. }
  666. this._dtBarCode.Rows[this._rowIndex]["BarCode"] = this._dtBarCode;
  667. this._dtBarCode.Rows[this._rowIndex]["DefectID"] = this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue;
  668. this._dtBarCode.Rows[this._rowIndex]["DefectName"] = this.dropDuty.Text;
  669. this._dtBarCode.Rows[this._rowIndex]["DefectCode"] = this._currentDutyCode;
  670. this._dtBarCode.Rows[this._rowIndex]["DefectPositionID"] = this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue;
  671. this._dtBarCode.Rows[this._rowIndex]["DefectPositionName"] = this.dropDefectLocation.Text;
  672. this._dtBarCode.Rows[this._rowIndex]["DefectPositionCode"] = this._currentDefectPositionCode;
  673. this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"] = (this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : this.dropDutyProcedure.SelectedValue;
  674. this._dtBarCode.Rows[this._rowIndex]["DefectProcedureName"] = this.dropDutyProcedure.Text;
  675. this._dtBarCode.Rows[this._rowIndex]["DefectProcedureCode"] = this._currentDefectProcedureCode;
  676. this._dtBarCode.Rows[this._rowIndex]["DefectUserID"] = this.dropDutyUser.SelectedValue.ToString() == string.Empty ? 0 : this.dropDutyUser.SelectedValue;
  677. this._dtBarCode.Rows[this._rowIndex]["DefectUserName"] = this.dropDutyUser.Text;
  678. this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"] = this._currentDefectUserCode;
  679. //this._dtBarCode.Rows[this._rowIndex]["Jobs"] = this.dropJobs.SelectedValue.ToString() == string.Empty ? 0 : this.dropJobs.SelectedValue;
  680. //this._dtBarCode.Rows[this._rowIndex]["JobsText"] = this.dropJobs.Text;
  681. this._dtBarCode.Rows[this._rowIndex]["DefectRemarks"] = this.txtRemarks.Text;
  682. this._dtBarCode.Rows[this._rowIndex]["TempCount"] = this._tempcount;
  683. this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"] = this._productionDataID;
  684. this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"] = this._defectProductionDataID;
  685. this._dtBarCode.AcceptChanges();
  686. }
  687. // 防止工种不选择的话,直接New一个
  688. if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", _tempcount.ToString())))
  689. {
  690. DataTable dtStaff = new DataTable(string.Format("TempTable{0}", _tempcount.ToString()));
  691. dtStaff.Columns.Add("IsSelected");
  692. dtStaff.Columns.Add("StaffID");
  693. dtStaff.Columns.Add("StaffCode");
  694. dtStaff.Columns.Add("StaffName");
  695. dtStaff.Columns.Add("StaffTempCount");
  696. dtStaff.Columns.Add("StaffStatus");
  697. dtStaff.Columns.Add("UjobsID");
  698. dtStaff.Columns.Add("SjobsID");
  699. this._dsStaff.Tables.Add(dtStaff);
  700. }
  701. ////// 防止工种不选择的话,直接New一个
  702. ////if (!this._dsMissedStaff.Tables.Contains(string.Format("TempTable{0}", _tempcount.ToString())))
  703. ////{
  704. //// DataTable dtMissedStaff = new DataTable(string.Format("TempTable{0}", _tempcount.ToString()));
  705. //// dtMissedStaff.Columns.Add("IsSelected");
  706. //// dtMissedStaff.Columns.Add("StaffID");
  707. //// dtMissedStaff.Columns.Add("StaffCode");
  708. //// dtMissedStaff.Columns.Add("StaffName");
  709. //// dtMissedStaff.Columns.Add("StaffTempCount");
  710. //// dtMissedStaff.Columns.Add("StaffStatus");
  711. //// dtMissedStaff.Columns.Add("UJobsID");
  712. //// dtMissedStaff.Columns.Add("SJobsID");
  713. //// this._dsMissedStaff.Tables.Add(dtMissedStaff);
  714. ////}
  715. //if (!this._dsImage.Tables.Contains(string.Format("TempTable{0}", this._tempcount.ToString())))
  716. //{
  717. // DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._tempcount.ToString()));
  718. // dtImage.Columns.Add("StaffTempCount");
  719. // dtImage.Columns.Add("ImageByte", typeof(byte[]));
  720. // dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
  721. // this._dsImage.Tables.Add(dtImage);
  722. //}
  723. //this._frm1202.BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", _tempcount.ToString())]);
  724. this._tempcount = _tempcount + 1;
  725. this._frm1202.SetDataSource(_tempcount);
  726. ClearText();
  727. if (this._isEdit)
  728. {
  729. // 保存后如果是编辑进来的,更改后可以继续录入,当前改为插入了
  730. this._isEdit = false;
  731. }
  732. this.Close();
  733. }
  734. catch (Exception ex)
  735. {
  736. // 对异常进行共通处理
  737. ExceptionManager.HandleEventException(this.ToString(),
  738. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  739. }
  740. }
  741. /// <summary>
  742. /// 缺陷位置验证事件
  743. /// </summary>
  744. /// <param name="sender"></param>
  745. /// <param name="e"></param>
  746. private void dropDefectLocation_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  747. {
  748. try
  749. {
  750. if (this.dropDefectLocation.SelectedValue != null && this.dropDefectLocation.SelectedValue.ToString() != string.Empty)
  751. {
  752. string DefectLocationCode = this.dropDefectLocation.SelectedValue.ToString();
  753. DataTable dtDefectLocationCode = this.dropDefectLocation.DataSource as DataTable;
  754. if (dtDefectLocationCode.Rows.Count > Constant.INT_IS_ZERO)
  755. {
  756. DataRow[] dr = dtDefectLocationCode.Select("DefectPositionID=" + DefectLocationCode);
  757. if (dr.Length > Constant.INT_IS_ZERO)
  758. {
  759. this._currentDefectPositionCode = dr[0]["DefectPositionCode"].ToString();
  760. }
  761. }
  762. }
  763. }
  764. catch (Exception ex)
  765. {
  766. // 对异常进行共通处理
  767. ExceptionManager.HandleEventException(this.ToString(),
  768. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  769. }
  770. }
  771. /// <summary>
  772. /// 工号验证事件
  773. /// </summary>
  774. /// <param name="sender"></param>
  775. /// <param name="e"></param>
  776. private void dropDutyUser_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  777. {
  778. try
  779. {
  780. if (this.dropDutyUser.SelectedValue != null && this.dropDutyUser.SelectedValue.ToString() != string.Empty)
  781. {
  782. if (!this.txtRemarks.ReadOnly)
  783. {
  784. string DutyUserID = this.dropDutyUser.SelectedValue.ToString();
  785. DataTable dtDutyUserCode = this.dropDutyUser.DataSource as DataTable;
  786. if (dtDutyUserCode.Rows.Count > Constant.INT_IS_ZERO)
  787. {
  788. DataRow[] dr = dtDutyUserCode.Select("UserID=" + DutyUserID);
  789. if (dr.Length > Constant.INT_IS_ZERO)
  790. {
  791. this._currentDefectUserCode = dr[0]["UserCode"].ToString();
  792. }
  793. }
  794. BindNoProcedureDutyStaff(this._tempcount);
  795. }
  796. }
  797. }
  798. catch (Exception ex)
  799. {
  800. // 对异常进行共通处理
  801. ExceptionManager.HandleEventException(this.ToString(),
  802. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  803. }
  804. }
  805. /// <summary>
  806. /// 无责任工序下绑定缺陷责任员工
  807. /// </summary>
  808. /// <param name="productionDataID">生产数据ID</param>
  809. /// <param name="userID">用户ID</param>
  810. /// <param name="jobs">工种ID</param>
  811. /// <param name="StaffTempCount">唯一标识</param>
  812. private void BindNoProcedureDutyStaff(int StaffTempCount)
  813. {
  814. if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", StaffTempCount.ToString())))
  815. {
  816. DataTable dtStaff = new DataTable(string.Format("TempTable{0}", StaffTempCount.ToString()));
  817. dtStaff.Columns.Add("IsSelected");
  818. dtStaff.Columns.Add("StaffID");
  819. dtStaff.Columns.Add("StaffCode");
  820. dtStaff.Columns.Add("StaffName");
  821. dtStaff.Columns.Add("StaffTempCount");
  822. dtStaff.Columns.Add("StaffStatus");
  823. dtStaff.Columns.Add("UjobsID");
  824. dtStaff.Columns.Add("SjobsID");
  825. this._dsStaff.Tables.Add(dtStaff);
  826. }
  827. // 获取临时表是否有数据,如果有行,则删除,
  828. DataTable dtTemp = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  829. if (dtTemp.Rows.Count > Constant.INT_IS_ZERO)
  830. {
  831. // 清空临时表数据
  832. this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Clear();
  833. }
  834. int UserID = Convert.ToInt32(dropDutyUser.SelectedValue);
  835. DataSet dsDutyStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  836. {
  837. return PMModuleProxy.Service.GetSemiCheckDefectStaffByUserID(UserID);
  838. }));
  839. if (dsDutyStaff != null && dsDutyStaff.Tables.Count > Constant.INT_IS_ZERO
  840. && dsDutyStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  841. {
  842. foreach (DataRow dr in dsDutyStaff.Tables[0].Rows)
  843. {
  844. DataRow addDr = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].NewRow();
  845. addDr["IsSelected"] = 1;
  846. addDr["StaffID"] = dr["StaffID"];
  847. addDr["StaffCode"] = dr["StaffCode"];
  848. addDr["StaffName"] = dr["StaffName"];
  849. addDr["StaffTempCount"] = StaffTempCount;
  850. addDr["StaffStatus"] = dr["StaffStatus"];
  851. addDr["UjobsID"] = dr["UjobsID"];
  852. addDr["SjobsID"] = dr["SjobsID"];
  853. this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Rows.Add(addDr);
  854. }
  855. this.dgvDefectStaff.DataSource = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  856. }
  857. }
  858. /// <summary>
  859. /// 关闭按钮事件
  860. /// </summary>
  861. /// <param name="sender"></param>
  862. /// <param name="e"></param>
  863. private void btnCancel_Click(object sender, EventArgs e)
  864. {
  865. this.Close();
  866. }
  867. #endregion
  868. #region 私有方法
  869. /// <summary>
  870. /// 责任工号数据表 责任工序不选择时,默认数据源
  871. /// </summary>
  872. /// <returns></returns>
  873. private DataTable GetDutyProcedureUser()
  874. {
  875. SUserEntity userEntity = new SUserEntity();
  876. userEntity.IsWorker = 1;//生产工号
  877. DataSet dsDutyProcedureUser = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  878. {
  879. return SystemModuleProxy.Service.SearchUserData(userEntity);
  880. }));
  881. DataRow dr = dsDutyProcedureUser.Tables[0].NewRow();
  882. dr["UserID"] = -1;
  883. dr["UserCode"] = "";
  884. dr["UserName"] = "";
  885. dsDutyProcedureUser.Tables[0].Rows.InsertAt(dr, 0);
  886. dsDutyProcedureUser.Tables[0].AcceptChanges();
  887. this._dtDutyProcedureUser = dsDutyProcedureUser.Tables[0];
  888. return dsDutyProcedureUser.Tables[0];
  889. }
  890. /// <summary>
  891. /// 保存后界面数据初始化
  892. /// </summary>
  893. private void ClearText()
  894. {
  895. this.dropDuty.SelectedValue = string.Empty;
  896. this.dropDuty.Text = string.Empty;
  897. this.dropDefectLocation.SelectedValue = string.Empty;
  898. this.dropDefectLocation.Text = string.Empty;
  899. this.dropDutyProcedure.SelectedValue = null;
  900. this.dropDutyProcedure.Text = string.Empty;
  901. this.dropDutyUser.SelectedValue = null;
  902. this.dropDutyUser.Text = string.Empty;
  903. //this.dropJobs.SelectedValue = null;
  904. //this.dropJobs.Text = string.Empty;
  905. this.txtRemarks.Text = string.Empty;
  906. this.dgvDefectStaff.DataSource = null;
  907. //this.cmbDefectFine.SelectedValue = -1;
  908. //this.dropMissUser.SelectedValue = null;
  909. //this.dropMissUser.Text = string.Empty;
  910. }
  911. /// <summary>
  912. /// 将图片文件转换成二进制
  913. /// </summary>
  914. /// <param name="img"></param>
  915. /// <returns></returns>
  916. public static byte[] ImageToByte(Image img)
  917. {
  918. byte[] smallbuffer = null;
  919. using (MemoryStream ms = new MemoryStream())
  920. {
  921. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  922. ms.Position = Constant.INT_IS_ZERO;
  923. smallbuffer = new byte[ms.Length];
  924. ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
  925. ms.Flush();
  926. }
  927. return smallbuffer;
  928. }
  929. /// <SUMMARY>
  930. /// 重绘缩略图并把缩略图转为二进制储存
  931. /// </SUMMARY>
  932. /// <PARAM name="sourceFile">图片源路径</PARAM>
  933. /// <PARAM name="destHeight">缩放后图片高度</PARAM>
  934. /// <PARAM name="destWidth">缩放后图片宽度</PARAM>
  935. /// <RETURNS></RETURNS>
  936. public void GetThumbnail(FileInfo sourceFile, byte[] orgImageByte)
  937. {
  938. Image imgSource = Image.FromStream(sourceFile.OpenRead());
  939. ImageFormat thisFormat = imgSource.RawFormat;
  940. int sW = 0, sH = 0;
  941. // 按比例缩放
  942. int sWidth = imgSource.Width;
  943. int sHeight = imgSource.Height;
  944. int destWidth = 100;
  945. int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
  946. if (sHeight > destHeight || sWidth > destWidth)
  947. {
  948. if ((sWidth * destHeight) > (sHeight * destWidth))
  949. {
  950. sW = destWidth;
  951. sH = (destWidth * sHeight) / sWidth;
  952. }
  953. else
  954. {
  955. sH = destHeight;
  956. sW = (sWidth * destHeight) / sHeight;
  957. }
  958. }
  959. else
  960. {
  961. sW = sWidth;
  962. sH = sHeight;
  963. }
  964. Bitmap outBmp = new Bitmap(destWidth, destHeight);
  965. Graphics g = Graphics.FromImage(outBmp);
  966. g.Clear(Color.Black);
  967. // 设置画布的描绘质量
  968. g.CompositingQuality = CompositingQuality.HighQuality;
  969. g.SmoothingMode = SmoothingMode.HighQuality;
  970. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  971. g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
  972. g.Dispose();
  973. //将重绘的图片转为二进制并保存
  974. Image image = (Image)outBmp;
  975. byte[] smallbuffer = ImageToByte(image);
  976. DataRow dr = this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].NewRow();
  977. dr["StaffTempCount"] = this._tempcount;
  978. dr["ImageByte"] = smallbuffer;
  979. dr["OrgImageByte"] = orgImageByte;
  980. this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].Rows.Add(dr);
  981. this._smallByte.Add(smallbuffer);
  982. imgSource.Dispose();
  983. outBmp.Dispose();
  984. }
  985. /// <summary>
  986. /// 根据原图片宽高比获取缩略图的高(根据宽)
  987. /// </summary>
  988. /// <param name="BigWidth"></param>
  989. /// <param name="BigHeight"></param>
  990. /// <param name="SmallWidth"></param>
  991. /// <returns></returns>
  992. protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
  993. {
  994. decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
  995. return Convert.ToInt32(SmallWidth / scale);
  996. }
  997. /// <summary>
  998. /// 绑定缩略图到控件中
  999. /// </summary>
  1000. protected void BindImg()
  1001. {
  1002. ImageList ilPic = new ImageList();
  1003. //每次绑定要清空数据源
  1004. ilPic.Images.Clear();
  1005. //将缩略图二进制集合中的数据转换成图片文件
  1006. List<Image> LSImageList = new List<Image>();
  1007. foreach (byte[] smallby in _smallByte)
  1008. {
  1009. LSImageList.Add(byteArrayToImage(smallby));
  1010. }
  1011. //添加数据源
  1012. foreach (Image img in LSImageList)
  1013. {
  1014. ilPic.Images.Add(img);
  1015. }
  1016. ilPic.ImageSize = new Size(100, 100);
  1017. }
  1018. /// <summary>
  1019. /// 将数据库中的二进制转换成图片
  1020. /// </summary>
  1021. /// <param name="data"></param>
  1022. /// <returns></returns>
  1023. public static Image byteArrayToImage(object data)
  1024. {
  1025. System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
  1026. System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
  1027. return returnImage;
  1028. }
  1029. /// <summary>
  1030. /// 绑定并显示图片
  1031. /// </summary>
  1032. /// <param name="ImageData"></param>
  1033. private void BindByteImage(DataTable ImageData)
  1034. {
  1035. this._smallByte.Clear();
  1036. foreach (DataRow dr in ImageData.Rows)
  1037. {
  1038. //将数据库中的缩略图取出
  1039. this._smallByte.Add((byte[])dr[1]);
  1040. }
  1041. //绑定缩略图
  1042. BindImg();
  1043. }
  1044. /// <summary>
  1045. /// 根据漏检工号绑定漏检责任员工
  1046. /// </summary>
  1047. /// <param name="jobs">工种ID</param>
  1048. /// <param name="StaffTempCount">唯一标识</param>
  1049. private void BindMissedDutyStaff(int userid, int StaffTempCount)
  1050. {
  1051. if (!this._dsMissedStaff.Tables.Contains(string.Format("TempTable{0}", StaffTempCount.ToString())))
  1052. {
  1053. DataTable dtMissedStaff = new DataTable(string.Format("TempTable{0}", StaffTempCount.ToString()));
  1054. dtMissedStaff.Columns.Add("IsSelected");
  1055. dtMissedStaff.Columns.Add("StaffID");
  1056. dtMissedStaff.Columns.Add("StaffCode");
  1057. dtMissedStaff.Columns.Add("StaffName");
  1058. dtMissedStaff.Columns.Add("StaffTempCount");
  1059. dtMissedStaff.Columns.Add("StaffStatus");
  1060. dtMissedStaff.Columns.Add("UJobsID");
  1061. dtMissedStaff.Columns.Add("SJobsID");
  1062. this._dsMissedStaff.Tables.Add(dtMissedStaff);
  1063. }
  1064. // 获取临时表是否有数据,如果有行,则删除,
  1065. DataTable dtTemp = this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  1066. if (dtTemp.Rows.Count > Constant.INT_IS_ZERO)
  1067. {
  1068. // 清空临时表数据
  1069. this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Clear();
  1070. }
  1071. DataSet dsMissedDutyStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1072. {
  1073. return PMModuleProxy.Service.GetMissedStaffByUserID(userid);
  1074. }));
  1075. if (dsMissedDutyStaff != null && dsMissedDutyStaff.Tables.Count > Constant.INT_IS_ZERO
  1076. && dsMissedDutyStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  1077. {
  1078. foreach (DataRow dr in dsMissedDutyStaff.Tables[0].Rows)
  1079. {
  1080. DataRow addDr = this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].NewRow();
  1081. addDr["IsSelected"] = 1;
  1082. addDr["StaffID"] = dr["StaffID"];
  1083. addDr["StaffCode"] = dr["StaffCode"];
  1084. addDr["StaffName"] = dr["StaffName"];
  1085. addDr["StaffTempCount"] = StaffTempCount;
  1086. addDr["StaffStatus"] = dr["StaffStatus"];
  1087. addDr["UJobsID"] = dr["UJobsID"];
  1088. addDr["SJobsID"] = dr["SJobsID"];
  1089. this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Rows.Add(addDr);
  1090. }
  1091. }
  1092. }
  1093. #endregion
  1094. }
  1095. }