F_PM_3203.cs 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620
  1. /*******************************************************************************
  2. * Copyright(c) 2019 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_3203.cs
  5. * 2.功能描述:半检-新增、编辑
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * xuwei 2019/12/12 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. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  24. namespace Dongke.IBOSS.PRD.Client.PMModule
  25. {
  26. /// <summary>
  27. /// 成品检验-新增、编辑
  28. /// </summary>
  29. public partial class F_PM_3203 : FormBase
  30. {
  31. #region 成员变量
  32. // 当前操作数据表
  33. private DataTable _dtBarCode = null;
  34. // 当前产品条码
  35. private string _barcode;
  36. // 当前产品ID
  37. private int _goodsID = 0;
  38. // 当前工序ID
  39. private int _procedureID = 0;
  40. // 当前是否为编辑 true
  41. private bool _isEdit = false;
  42. // 临时数
  43. private int _tempcount = 0;
  44. // 调用实例对象
  45. F_PM_3202 _frm3202 = null;
  46. // 员工数据集
  47. private DataSet _dsStaff = null;
  48. // 漏检员工数据集
  49. private DataSet _dsMissedStaff = null;
  50. // 图片数据集
  51. private DataSet _dsImage = null;
  52. // 生产数据ID
  53. private int _productionDataID = 0;
  54. // 图片字节集
  55. private List<byte[]> _PicByte = new List<byte[]>();
  56. // 缩略图片字节集
  57. private List<byte[]> _smallByte = new List<byte[]>();
  58. // 行索引
  59. private int _rowIndex = 0;
  60. // 当前缺陷编码
  61. private string _currentDutyCode = "";
  62. // 当前缺陷位置编码
  63. private string _currentDefectPositionCode = "";
  64. // 当前缺陷责任工序编码
  65. private string _currentDefectProcedureCode = "";
  66. // 当前缺陷工号编码
  67. private string _currentDefectUserCode = "";
  68. // 当前漏检工号
  69. private string _currentMissedUserCode = "";
  70. // 默认责任工号数据源
  71. private DataTable _dtDutyProcedureUser = null;
  72. // 是否干补
  73. private int SpecialRepairflag = 0;//0未干补 1干补
  74. //默认缺陷对应的工种
  75. private DataTable _defaultJobsID = null;
  76. // 缺陷扣罚关系所有数据源
  77. private DataTable _dtDefectFineRelation = null;
  78. // 缺陷扣除数关系所有数据源
  79. private DataTable _dtDefectDeductionRelation = null;
  80. // 默认缺陷扣罚关系所有数据源
  81. private DataTable _dtDefaultDefectFineRelation = null;
  82. // 默认缺陷扣除数关系所有数据源
  83. private DataTable _dtDefaultDefectDeductionRelation = null;
  84. #endregion
  85. #region 构造函数
  86. public F_PM_3203()
  87. {
  88. InitializeComponent();
  89. }
  90. /// <summary>
  91. ///
  92. /// </summary>
  93. /// <param name="dtBarCode">当前操作的数据表</param>
  94. /// <param name="barcode">当前产品条码</param>
  95. /// <param name="goodsID">当前产品ID</param>
  96. /// <param name="tempcount">当前累加数,防止重复</param>
  97. /// <param name="procedureID">当前工序</param>
  98. /// <param name="titleText">当前窗体名称</param>
  99. /// <param name="isEdit">false 新建 true编辑</param>
  100. /// <param name="frm3202">调用实例对象</param>
  101. /// <param name="dsStaff">员工数据集</param>
  102. /// <param name="dsImage">图片数据集</param>
  103. /// <param name="picByte">原图字节数组</param>
  104. /// <param name="smallByte">缩略图字节数组</param>
  105. /// <param name="rowIndex">编辑行号标识</param>
  106. public F_PM_3203(DataTable dtBarCode
  107. , string barcode
  108. , int goodsID
  109. , int tempcount
  110. , int procedureID
  111. , string titleText
  112. , bool isEdit
  113. , F_PM_3202 frm3202
  114. , DataSet dsStaff
  115. , DataSet dsMissedStaff
  116. , DataSet dsImage
  117. , List<byte[]> picByte
  118. , List<byte[]> smallByte
  119. , int rowIndex)
  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._frm3202 = frm3202;
  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.btnUpload.Text = ButtonText.BTN_UPLOAD;
  137. this.btnDelete.Text = ButtonText.BTN_DELETE;
  138. }
  139. #endregion
  140. #region 事件
  141. /// <summary>
  142. /// 窗体加载事件
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void F_PM_3203_Load(object sender, EventArgs e)
  147. {
  148. // add 2016/01/06 wangx
  149. DataSet dsDefectFineRelation = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  150. {
  151. return SystemModuleProxy.Service.GetAllDefectFineRelation();
  152. }));
  153. _dtDefectFineRelation = dsDefectFineRelation.Tables[0];
  154. DataSet dsDefectDeductionRelation = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  155. {
  156. return SystemModuleProxy.Service.GetAllDefectDeductionRelation();
  157. }));
  158. _dtDefectDeductionRelation = dsDefectDeductionRelation.Tables[0]; ;
  159. // add end
  160. this.dgvDefectStaff.AutoGenerateColumns = false;
  161. //获取干补标识
  162. SpecialRepairflag = (int)DoAsync(new BaseAsyncMethod(() =>
  163. {
  164. return PMModuleProxy.Service.GetSpecialRepairflagByBarcode(this._barcode);
  165. }));
  166. //SpecialRepairflag = 1;
  167. DataSet dsDefectByProcedure = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  168. {
  169. return PMModuleProxy.Service.GetDefectByProcedure(this._procedureID);
  170. }));
  171. if (dsDefectByProcedure != null && dsDefectByProcedure.Tables.Count > Constant.INT_IS_ZERO
  172. && dsDefectByProcedure.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  173. {
  174. this.dropDuty.DisplayMember = "DEFECTFLAGNAME";
  175. this.dropDuty.ValueMember = "DEFECTFLAGID";
  176. this.dropDuty.DataSource = dsDefectByProcedure.Tables[0];
  177. }
  178. else
  179. {
  180. this.dropDuty.DisplayMember = "DEFECTFLAGNAME";
  181. this.dropDuty.ValueMember = "DEFECTFLAGID";
  182. this.dropDuty.DataSource = GetDuty();
  183. }
  184. // 缺陷位置
  185. DataSet dsDefectLocation = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  186. {
  187. return PMModuleProxy.Service.GetDefectLocaionByGoodsID(this._goodsID);
  188. }));
  189. this.dropDefectLocation.DisplayMember = "DEFECTPOSITIONCODEANDNAME";
  190. this.dropDefectLocation.ValueMember = "DEFECTPOSITIONID";
  191. this.dropDefectLocation.DataSource = dsDefectLocation.Tables[0];
  192. this.dropDutyProcedure.DisplayMember = "DutyProcedureName";
  193. this.dropDutyProcedure.ValueMember = "DutyProcedureID";
  194. this.dropDutyProcedure.DataSource = GetDutyProcedure();
  195. this.dropDutyUser.DisplayMember = "UserCode";
  196. this.dropDutyUser.ValueMember = "UserID";
  197. this.dropDutyUser.DataSource = GetDutyProcedureUser();
  198. //漏检工号数据源
  199. this.dropMissUser.DisplayMember = "UserCode";
  200. this.dropMissUser.ValueMember = "UserID";
  201. this.dropMissUser.DataSource = this._dtDutyProcedureUser;
  202. this.dropJobs.DisplayMember = "JobsName";
  203. this.dropJobs.ValueMember = "Jobs";
  204. this.dropJobs.DataSource = GetDutyProcedureJobs(); // 默认空数据源,随着责任工号而改变
  205. // 缺陷扣罚
  206. //DataSet dsDefectFine = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  207. //{
  208. // return SystemModuleProxy.Service.GetDictionaryData(0, "ASE002");
  209. //}));
  210. //DataRow dr = dsDefectFine.Tables[0].NewRow();
  211. //dr["DictionaryID"] = -1;
  212. //dr["DictionaryValue"] = "";
  213. //dsDefectFine.Tables[0].Rows.InsertAt(dr, 0);
  214. //dsDefectFine.Tables[0].AcceptChanges();
  215. //this.cmbDefectFine.DisplayMember = "DictionaryValue";
  216. //this.cmbDefectFine.ValueMember = "DictionaryID";
  217. //this.cmbDefectFine.DataSource = dsDefectFine.Tables[0];
  218. DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  219. {
  220. return SystemModuleProxy.Service.GetAllDefectFine();
  221. }));
  222. if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
  223. {
  224. DataView dv = dsResultAccount.Tables[0].DefaultView;
  225. dv.RowFilter = "valueflag=1";
  226. this.cmbDefectFine.DisplayMember = "DefectFineCode";
  227. this.cmbDefectFine.ValueMember = "DefectFineID";
  228. DataTable dtNew = dv.ToTable();
  229. DataRow dr = dtNew.NewRow();
  230. dr["DefectFineID"] = -1;
  231. dr["DefectFineCode"] = "";
  232. dtNew.Rows.InsertAt(dr, 0);
  233. dtNew.AcceptChanges();
  234. this.cmbDefectFine.DisplayMember = "DefectFineCode";
  235. this.cmbDefectFine.ValueMember = "DefectFineID";
  236. this.cmbDefectFine.DataSource = dtNew;
  237. this._dtDefaultDefectFineRelation = dtNew;
  238. }
  239. // 获取缺陷扣除数数据源
  240. DataSet dsDefectDeduction = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  241. {
  242. return SystemModuleProxy.Service.GetAllDefectDeduction();
  243. }));
  244. if (dsDefectDeduction != null && dsDefectDeduction.Tables[0].Rows.Count > 0)
  245. {
  246. DataView dv = dsDefectDeduction.Tables[0].DefaultView;
  247. dv.RowFilter = "valueflag=1";
  248. this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
  249. this.cmbDefectDeduction.ValueMember = "DefectDeductionID";
  250. DataTable dtNew = dv.ToTable();
  251. DataRow dr = dtNew.NewRow();
  252. dr["DefectDeductionID"] = -1;
  253. //dr["DefectDeductionNum"] = "0";
  254. dtNew.Rows.InsertAt(dr, 0);
  255. dtNew.AcceptChanges();
  256. this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
  257. this.cmbDefectDeduction.ValueMember = "DefectDeductionID";
  258. this.cmbDefectDeduction.DataSource = dtNew;
  259. this._dtDefaultDefectDeductionRelation = dtNew;
  260. }
  261. if (this._isEdit)
  262. {
  263. this.dropDuty.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectID"].ToString();
  264. this._currentDutyCode = this._dtBarCode.Rows[this._rowIndex]["DefectCode"].ToString();
  265. // 新添加的
  266. if (this._dtBarCode.Rows[this._rowIndex]["IsOtherDefect"].ToString() == "1")
  267. {
  268. this.chkDefect.Checked = true;
  269. }
  270. //
  271. // add 2016/01/06 wangx
  272. if (this._dtDefectFineRelation != null)
  273. {
  274. DataRow[] r7 = this._dtDefectFineRelation.Select("defectid=" + this.dropDuty.SelectedValue);
  275. if (r7.Length > 0)
  276. {
  277. DataTable dtNew = r7.CopyToDataTable();
  278. DataRow dr = dtNew.NewRow();
  279. dr["DefectFineID"] = -1;
  280. dr["DefectFineCode"] = "";
  281. dtNew.Rows.InsertAt(dr, 0);
  282. dtNew.AcceptChanges();
  283. this.cmbDefectFine.DisplayMember = "DefectFineCode";
  284. this.cmbDefectFine.ValueMember = "DefectFineID";
  285. this.cmbDefectFine.DataSource = dtNew;
  286. }
  287. else
  288. {
  289. this.cmbDefectFine.DisplayMember = "DefectFineCode";
  290. this.cmbDefectFine.ValueMember = "DefectFineID";
  291. this.cmbDefectFine.DataSource = this._dtDefaultDefectFineRelation;
  292. }
  293. }
  294. if (this._dtDefectDeductionRelation != null)
  295. {
  296. DataRow[] r7 = this._dtDefectDeductionRelation.Select("defectid=" + this.dropDuty.SelectedValue);
  297. if (r7.Length > 0)
  298. {
  299. DataTable dtNew = r7.CopyToDataTable();
  300. DataRow dr = dtNew.NewRow();
  301. dr["DefectDeductionID"] = -1;
  302. //dr["DefectDeductionNum"] = "";
  303. dtNew.Rows.InsertAt(dr, 0);
  304. dtNew.AcceptChanges();
  305. this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
  306. this.cmbDefectDeduction.ValueMember = "DefectDeductionNum";
  307. this.cmbDefectDeduction.DataSource = dtNew;
  308. }
  309. else
  310. {
  311. this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
  312. this.cmbDefectDeduction.ValueMember = "DefectDeductionNum";
  313. this.cmbDefectDeduction.DataSource = this._dtDefaultDefectDeductionRelation;
  314. }
  315. }
  316. // add end
  317. // 缺陷选定后事件
  318. BindDutyDefect(this._barcode, Convert.ToInt32(this.dropDuty.SelectedValue));
  319. // 缺陷位置
  320. this.dropDefectLocation.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectPositionID"].ToString();
  321. this._currentDefectPositionCode = this._dtBarCode.Rows[this._rowIndex]["DefectPositionCode"].ToString();
  322. // 责任工序
  323. if (this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"].ToString() != Constant.INT_IS_ZERO.ToString()
  324. && this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"].ToString() != string.Empty)
  325. {
  326. this.dropDutyProcedure.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"].ToString();
  327. this.dropDutyProcedure.Text = this._dtBarCode.Rows[this._rowIndex]["DefectProcedureName"].ToString();
  328. this._currentDefectProcedureCode = this._dtBarCode.Rows[this._rowIndex]["DefectProcedureCode"].ToString();
  329. // 责任工种
  330. SetDutyCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
  331. string DutyProcedure = this.dropDutyProcedure.SelectedValue.ToString();
  332. DataTable dtDutyProcedureCode = this.dropDutyProcedure.DataSource as DataTable;
  333. if (dtDutyProcedureCode.Rows.Count > Constant.INT_IS_ZERO)
  334. {
  335. DataRow[] drJobs = dtDutyProcedureCode.Select("DutyProcedureID=" + DutyProcedure);
  336. if (drJobs.Length > Constant.INT_IS_ZERO)
  337. {
  338. this._currentDefectProcedureCode = drJobs[0]["DutyProcedureCode"].ToString();
  339. }
  340. }
  341. DataSet dsDutyCode = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  342. {
  343. return PMModuleProxy.Service.GetDutyProcedureCodeByBarCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
  344. }));
  345. if (dsDutyCode != null && dsDutyCode.Tables.Count > Constant.INT_IS_ZERO
  346. && dsDutyCode.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  347. {
  348. this.dropDutyUser.DisplayMember = "UserCode";
  349. this.dropDutyUser.ValueMember = "UserID";
  350. this.dropDutyUser.DataSource = dsDutyCode.Tables[0];
  351. this.dropDutyUser.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectUserID"].ToString();
  352. this._currentDefectUserCode = this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"].ToString();
  353. this._productionDataID = Convert.ToInt32(this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"].ToString());
  354. DataSet dsDutyJobs = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  355. {
  356. return PMModuleProxy.Service.GetDutyJobsCodeByUser(Convert.ToInt32(this.dropDutyUser.SelectedValue), this._productionDataID);
  357. }));
  358. if (dsDutyJobs != null && dsDutyJobs.Tables.Count > Constant.INT_IS_ZERO
  359. && dsDutyJobs.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  360. {
  361. this.dropJobs.DisplayMember = "JobsName";
  362. this.dropJobs.ValueMember = "JobsID";
  363. this.dropJobs.DataSource = dsDutyJobs.Tables[0];
  364. this.dropJobs.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["Jobs"].ToString();
  365. }
  366. }
  367. }
  368. else
  369. {
  370. this.dropDutyProcedure.SelectedValue = null;
  371. this.dropDutyProcedure.Text = "";
  372. this._currentDefectProcedureCode = "";
  373. // 没有责任工序,获取号及工种
  374. if (this._dtDutyProcedureUser != null && this._dtDutyProcedureUser.Rows.Count > Constant.INT_IS_ZERO)
  375. {
  376. this.dropDutyUser.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectUserID"].ToString();
  377. this._currentDefectUserCode = this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"].ToString();
  378. this._productionDataID = Convert.ToInt32(this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"].ToString());
  379. DataSet dsDutyJobs = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  380. {
  381. return SystemModuleProxy.Service.GetAllJobsByUserID(Convert.ToInt32(this.dropDutyUser.SelectedValue));
  382. }));
  383. if (dsDutyJobs != null && dsDutyJobs.Tables.Count > Constant.INT_IS_ZERO
  384. && dsDutyJobs.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  385. {
  386. this.dropJobs.DisplayMember = "JobsName";
  387. this.dropJobs.ValueMember = "Jobs";
  388. this.dropJobs.DataSource = dsDutyJobs.Tables[0];
  389. this.dropJobs.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["Jobs"].ToString();
  390. }
  391. }
  392. }
  393. // 漏检工号
  394. if (this._dtBarCode.Rows[this._rowIndex]["MissedUserID"].ToString() != "-1")
  395. {
  396. this.dropMissUser.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["MissedUserID"].ToString();
  397. this.dropMissUser.Text = this._dtBarCode.Rows[this._rowIndex]["MissedUserName"].ToString();
  398. this._currentMissedUserCode = this._dtBarCode.Rows[this._rowIndex]["MissedUserCode"].ToString();
  399. }
  400. this.txtRemarks.Text = this._dtBarCode.Rows[this._rowIndex]["DefectRemarks"].ToString();
  401. this.dgvDefectStaff.DataSource = this._dsStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())];
  402. this.dgvMissStaff.DataSource = this._dsMissedStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())];
  403. BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount.ToString())]);
  404. if (this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString() != "-1"
  405. && this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString() != string.Empty)
  406. {
  407. this.cmbDefectFine.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString();
  408. }
  409. if (this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"].ToString() != "-1"
  410. && this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"].ToString() != string.Empty)
  411. {
  412. this.cmbDefectDeduction.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"].ToString();
  413. }
  414. }
  415. }
  416. /// <summary>
  417. /// 缺陷验证事件
  418. /// </summary>
  419. /// <param name="sender"></param>
  420. /// <param name="e"></param>
  421. private void dropDuty_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  422. {
  423. if (this.dropDuty.SelectedValue != null && this.dropDuty.SelectedValue.ToString() != string.Empty)
  424. {
  425. if (!this.dropDuty.ReadOnly)
  426. {
  427. // 选定缺陷值
  428. string DutyValue = this.dropDuty.SelectedValue.ToString();
  429. DataTable dtDuty = this.dropDuty.DataSource as DataTable;
  430. string newDefectCode = "";
  431. if (dtDuty.Rows.Count > Constant.INT_IS_ZERO)
  432. {
  433. DataRow[] dr = dtDuty.Select("DefectFlagID=" + DutyValue);
  434. if (dr.Length > Constant.INT_IS_ZERO)
  435. {
  436. newDefectCode = dr[0]["DefectCode"].ToString();
  437. // 当前缺陷编码
  438. //this._currentDutyCode = dr[0]["DefectCode"].ToString();
  439. }
  440. }
  441. if (newDefectCode != this._currentDutyCode)
  442. {
  443. this._currentDutyCode = newDefectCode;
  444. BindDutyDefect(this._barcode, Convert.ToInt32(DutyValue));
  445. dropDutyProcedure_Validating(sender, e);
  446. // add 2016/01/06 wangx
  447. if (this._dtDefectFineRelation != null)
  448. {
  449. DataRow[] r7 = this._dtDefectFineRelation.Select("defectid=" + DutyValue);
  450. if (r7.Length > 0)
  451. {
  452. DataTable dtNew = r7.CopyToDataTable();
  453. DataRow dr = dtNew.NewRow();
  454. dr["DefectFineID"] = -1;
  455. dr["DefectFineCode"] = "";
  456. dtNew.Rows.InsertAt(dr, 0);
  457. dtNew.AcceptChanges();
  458. this.cmbDefectFine.DisplayMember = "DefectFineCode";
  459. this.cmbDefectFine.ValueMember = "DefectFineID";
  460. this.cmbDefectFine.DataSource = dtNew;
  461. }
  462. else
  463. {
  464. this.cmbDefectFine.DisplayMember = "DefectFineCode";
  465. this.cmbDefectFine.ValueMember = "DefectFineID";
  466. this.cmbDefectFine.DataSource = this._dtDefaultDefectFineRelation;
  467. }
  468. }
  469. if (this._dtDefectDeductionRelation != null)
  470. {
  471. DataRow[] r7 = this._dtDefectDeductionRelation.Select("defectid=" + DutyValue);
  472. if (r7.Length > 0)
  473. {
  474. DataTable dtNew = r7.CopyToDataTable();
  475. DataRow dr = dtNew.NewRow();
  476. dr["DefectDeductionID"] = -1;
  477. //dr["DefectDeductionNum"] = "";
  478. dtNew.Rows.InsertAt(dr, 0);
  479. dtNew.AcceptChanges();
  480. this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
  481. this.cmbDefectDeduction.ValueMember = "DefectDeductionID";
  482. this.cmbDefectDeduction.DataSource = dtNew;
  483. }
  484. else
  485. {
  486. this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
  487. this.cmbDefectDeduction.ValueMember = "DefectDeductionID";
  488. this.cmbDefectDeduction.DataSource = this._dtDefaultDefectDeductionRelation;
  489. }
  490. }
  491. // add end
  492. }
  493. }
  494. }
  495. }
  496. /// <summary>
  497. /// 责任工序验证事件
  498. /// </summary>
  499. /// <param name="sender"></param>
  500. /// <param name="e"></param>
  501. private void dropDutyProcedure_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  502. {
  503. if (this.dropDutyProcedure.SelectedValue != null && this.dropDutyProcedure.SelectedValue.ToString() != string.Empty)
  504. {
  505. if (!this.txtRemarks.ReadOnly)
  506. {
  507. string DutyProcedure = this.dropDutyProcedure.SelectedValue.ToString();
  508. DataTable dtDutyProcedureCode = this.dropDutyProcedure.DataSource as DataTable;
  509. string newDutyProcedureCode = "";
  510. if (dtDutyProcedureCode.Rows.Count > Constant.INT_IS_ZERO)
  511. {
  512. DataRow[] dr = dtDutyProcedureCode.Select("DutyProcedureID=" + DutyProcedure);
  513. if (dr.Length > Constant.INT_IS_ZERO)
  514. {
  515. newDutyProcedureCode = dr[0]["DutyProcedureCode"].ToString();
  516. //this._currentDefectProcedureCode = dr[0]["DutyProcedureCode"].ToString();
  517. }
  518. }
  519. if (newDutyProcedureCode != this._currentDefectProcedureCode)
  520. {
  521. this._currentDefectProcedureCode = newDutyProcedureCode;
  522. SetDutyCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
  523. }
  524. this.txtRemarks.Focus();
  525. }
  526. }
  527. else
  528. {
  529. if (this._currentDefectProcedureCode == "")
  530. return;
  531. //当前责任工序编码为空串
  532. this._currentDefectProcedureCode = "";
  533. //责任工序为空串时,责任工号为当前账套所有生产工号
  534. this._currentDefectUserCode = "";
  535. this.dropDutyUser.DataSource = null;
  536. this.dropDutyUser.DisplayMember = "UserCode";
  537. this.dropDutyUser.ValueMember = "UserID";
  538. this.dropDutyUser.DataSource = this._dtDutyProcedureUser;
  539. this.dropDutyUser.Text = "";
  540. //责任工序为空串时,责任工种置回空数据源
  541. this.dropJobs.DataSource = null;
  542. this.dropJobs.DisplayMember = "JobsName";
  543. this.dropJobs.ValueMember = "Jobs";
  544. this.dropJobs.DataSource = GetDutyProcedureJobs();
  545. this.dropJobs.Text = string.Empty;
  546. //清空缺陷责任员工
  547. if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", this._tempcount.ToString())))
  548. {
  549. DataTable dtStaff = new DataTable(string.Format("TempTable{0}", this._tempcount.ToString()));
  550. dtStaff.Columns.Add("IsSelected");
  551. dtStaff.Columns.Add("StaffID");
  552. dtStaff.Columns.Add("StaffCode");
  553. dtStaff.Columns.Add("StaffName");
  554. dtStaff.Columns.Add("StaffTempCount");
  555. dtStaff.Columns.Add("StaffStatus");
  556. this._dsStaff.Tables.Add(dtStaff);
  557. }
  558. // 获取临时表是否有数据,如果有行,则删除,
  559. DataTable dtTemp = this._dsStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())];
  560. if (dtTemp != null)
  561. {
  562. // 清空临时表数据
  563. this._dsStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())].Clear();
  564. }
  565. }
  566. }
  567. /// <summary>
  568. /// 保存按钮事件
  569. /// </summary>
  570. /// <param name="sender"></param>
  571. /// <param name="e"></param>
  572. private void btnSave_Click(object sender, EventArgs e)
  573. {
  574. try
  575. {
  576. if (this.dropDuty.SelectedValue == null || this.dropDuty.SelectedValue.ToString() == string.Empty)
  577. {
  578. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷"),
  579. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  580. return;
  581. }
  582. if (this.dropDefectLocation.SelectedValue == null || this.dropDefectLocation.SelectedValue.ToString() == string.Empty)
  583. {
  584. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷位置"),
  585. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  586. return;
  587. }
  588. if (this.dropDutyUser.SelectedValue == null || this.dropDutyUser.SelectedValue.ToString() == string.Empty)
  589. {
  590. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "责任工号"),
  591. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  592. return;
  593. }
  594. if (this.dropJobs.SelectedValue == null || this.dropJobs.SelectedValue.ToString() == string.Empty)
  595. {
  596. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工种"),
  597. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  598. return;
  599. }
  600. if (!this._isEdit)
  601. {
  602. // 每次添加不能重复
  603. if (this._dtBarCode != null && this._dtBarCode.Rows.Count > Constant.INT_IS_ZERO)
  604. {
  605. // 缺陷、缺陷位置、责任工序、责任工号、责任工种
  606. DataRow[] drExist = this._dtBarCode.Select(
  607. string.Format("DefectID={0} and DefectPositionID={1} and DefectUserID={2} and (({3} = 0 and (DefectProcedureID=0 or DefectProcedureID is null)) or ({3} > 0 and DefectProcedureID={3})) and Jobs={4}",
  608. this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue,
  609. this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue,
  610. this.dropDutyUser.SelectedValue.ToString() == string.Empty ? 0 : this.dropDutyUser.SelectedValue,
  611. (this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : this.dropDutyProcedure.SelectedValue,
  612. this.dropJobs.SelectedValue.ToString() == string.Empty ? 0 : this.dropJobs.SelectedValue
  613. )
  614. );
  615. if (drExist.Length > Constant.INT_IS_ZERO)
  616. {
  617. // 提示信息
  618. MessageBox.Show(Messages.MSG_PM_W001,
  619. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  620. return;
  621. }
  622. }
  623. DataRow dr = this._dtBarCode.NewRow();
  624. dr["BarCode"] = this._dtBarCode;
  625. dr["DefectID"] = this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue;
  626. dr["DefectName"] = this.dropDuty.Text;
  627. dr["DefectCode"] = this._currentDutyCode;
  628. dr["DefectPositionID"] = this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue;
  629. dr["DefectPositionName"] = this.dropDefectLocation.Text;
  630. dr["DefectPositionCode"] = this._currentDefectPositionCode;
  631. dr["DefectProcedureID"] = (this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : this.dropDutyProcedure.SelectedValue;
  632. dr["DefectProcedureName"] = this.dropDutyProcedure.Text;
  633. dr["DefectProcedureCode"] = this._currentDefectProcedureCode;
  634. dr["DefectUserID"] = this.dropDutyUser.SelectedValue.ToString() == string.Empty ? 0 : this.dropDutyUser.SelectedValue;
  635. dr["DefectUserName"] = this.dropDutyUser.Text;
  636. dr["DefectUserCode"] = this._currentDefectUserCode;
  637. dr["Jobs"] = this.dropJobs.SelectedValue.ToString() == string.Empty ? 0 : this.dropJobs.SelectedValue;
  638. dr["JobsText"] = this.dropJobs.Text;
  639. dr["DefectRemarks"] = this.txtRemarks.Text;
  640. dr["TempCount"] = this._tempcount;
  641. dr["ProductionDataID"] = this._productionDataID;
  642. if (this.cmbDefectFine.SelectedValue != null && this.cmbDefectFine.SelectedValue.ToString() != "-1")
  643. {
  644. dr["DefectFineID"] = this.cmbDefectFine.SelectedValue;
  645. dr["DefectFineValue"] = this.cmbDefectFine.Text;
  646. }
  647. else
  648. {
  649. dr["DefectFineID"] = -1;
  650. dr["DefectFineValue"] = string.Empty;
  651. }
  652. dr["MissedUserID"] = (this.dropMissUser.SelectedValue == null || this.dropMissUser.SelectedValue.ToString() == string.Empty) ? -1 : this.dropMissUser.SelectedValue;
  653. dr["MissedUserCode"] = this._currentMissedUserCode;
  654. dr["MissedUserName"] = this.dropMissUser.Text;
  655. dr["IsAllowEdit"] = 1;
  656. if (this.cmbDefectDeduction.SelectedValue != null && this.cmbDefectDeduction.SelectedValue.ToString() != "-1")
  657. {
  658. dr["DefectDeductionID"] = this.cmbDefectDeduction.SelectedValue;
  659. dr["DefectDeductionNum"] = this.cmbDefectDeduction.Text;
  660. }
  661. else
  662. {
  663. dr["DefectDeductionID"] = -1;
  664. dr["DefectDeductionNum"] = string.Empty;
  665. }
  666. dr["IsOtherDefect"] = this.chkDefect.Checked ? 1 : 0;
  667. this._dtBarCode.Rows.Add(dr);
  668. }
  669. else
  670. {
  671. if (this._dtBarCode != null && this._dtBarCode.Rows.Count > Constant.INT_IS_ZERO)
  672. {
  673. int currentRowIndex = -1; // 用来匹配是否编辑自己
  674. for (int i = 0; i < this._dtBarCode.Rows.Count; i++)
  675. {
  676. if (Convert.ToInt32(this._dtBarCode.Rows[i]["DefectID"]) ==
  677. (this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : Convert.ToInt32(this.dropDuty.SelectedValue))
  678. &&
  679. Convert.ToInt32(this._dtBarCode.Rows[i]["DefectPositionID"]) ==
  680. (this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : Convert.ToInt32(this.dropDefectLocation.SelectedValue))
  681. &&
  682. Convert.ToInt32(this._dtBarCode.Rows[i]["DefectProcedureID"].ToString() == "" ? 0 : this._dtBarCode.Rows[i]["DefectProcedureID"]) ==
  683. ((this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : Convert.ToInt32(this.dropDutyProcedure.SelectedValue))
  684. )
  685. {
  686. currentRowIndex = i;
  687. break;
  688. }
  689. }
  690. if (currentRowIndex != -Constant.INT_IS_ONE && currentRowIndex != this._rowIndex) // 更新后会有重复
  691. {
  692. // 提示信息
  693. MessageBox.Show(Messages.MSG_PM_W001,
  694. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  695. return;
  696. }
  697. }
  698. this._dtBarCode.Rows[this._rowIndex]["BarCode"] = this._dtBarCode;
  699. this._dtBarCode.Rows[this._rowIndex]["DefectID"] = this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue;
  700. this._dtBarCode.Rows[this._rowIndex]["DefectName"] = this.dropDuty.Text;
  701. this._dtBarCode.Rows[this._rowIndex]["DefectCode"] = this._currentDutyCode;
  702. this._dtBarCode.Rows[this._rowIndex]["DefectPositionID"] = this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue;
  703. this._dtBarCode.Rows[this._rowIndex]["DefectPositionName"] = this.dropDefectLocation.Text;
  704. this._dtBarCode.Rows[this._rowIndex]["DefectPositionCode"] = this._currentDefectPositionCode;
  705. this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"] = (this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : this.dropDutyProcedure.SelectedValue;
  706. this._dtBarCode.Rows[this._rowIndex]["DefectProcedureName"] = this.dropDutyProcedure.Text;
  707. this._dtBarCode.Rows[this._rowIndex]["DefectProcedureCode"] = this._currentDefectProcedureCode;
  708. this._dtBarCode.Rows[this._rowIndex]["DefectUserID"] = this.dropDutyUser.SelectedValue.ToString() == string.Empty ? 0 : this.dropDutyUser.SelectedValue;
  709. this._dtBarCode.Rows[this._rowIndex]["DefectUserName"] = this.dropDutyUser.Text;
  710. this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"] = this._currentDefectUserCode;
  711. this._dtBarCode.Rows[this._rowIndex]["Jobs"] = this.dropJobs.SelectedValue.ToString() == string.Empty ? 0 : this.dropJobs.SelectedValue;
  712. this._dtBarCode.Rows[this._rowIndex]["JobsText"] = this.dropJobs.Text;
  713. this._dtBarCode.Rows[this._rowIndex]["DefectRemarks"] = this.txtRemarks.Text;
  714. this._dtBarCode.Rows[this._rowIndex]["TempCount"] = this._tempcount;
  715. this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"] = this._productionDataID;
  716. if (this.cmbDefectFine.SelectedValue != null && this.cmbDefectFine.SelectedValue.ToString() != "-1")
  717. {
  718. this._dtBarCode.Rows[this._rowIndex]["DefectFineID"] = this.cmbDefectFine.SelectedValue;
  719. this._dtBarCode.Rows[this._rowIndex]["DefectFineValue"] = this.cmbDefectFine.Text;
  720. ;
  721. }
  722. else
  723. {
  724. this._dtBarCode.Rows[this._rowIndex]["DefectFineID"] = -1;
  725. this._dtBarCode.Rows[this._rowIndex]["DefectFineValue"] = string.Empty;
  726. }
  727. this._dtBarCode.Rows[this._rowIndex]["MissedUserID"] = (this.dropMissUser.SelectedValue == null || this.dropMissUser.SelectedValue.ToString() == string.Empty) ? -1 : this.dropMissUser.SelectedValue;
  728. this._dtBarCode.Rows[this._rowIndex]["MissedUserCode"] = this._currentMissedUserCode;
  729. ;
  730. this._dtBarCode.Rows[this._rowIndex]["MissedUserName"] = this.dropMissUser.Text;
  731. this._dtBarCode.Rows[this._rowIndex]["IsAllowEdit"] = 1;
  732. if (this.cmbDefectDeduction.SelectedValue != null && this.cmbDefectDeduction.SelectedValue.ToString() != "-1")
  733. {
  734. this._dtBarCode.Rows[this._rowIndex]["DefectDeductionID"] = this.cmbDefectDeduction.SelectedValue;
  735. this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"] = this.cmbDefectDeduction.Text;
  736. ;
  737. }
  738. else
  739. {
  740. this._dtBarCode.Rows[this._rowIndex]["DefectDeductionID"] = -1;
  741. this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"] = string.Empty;
  742. }
  743. this._dtBarCode.Rows[this._rowIndex]["IsOtherDefect"] = this.chkDefect.Checked ? 1 : 0;
  744. this._dtBarCode.AcceptChanges();
  745. }
  746. // 防止工种不选择的话,直接New一个
  747. if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", _tempcount.ToString())))
  748. {
  749. DataTable dtStaff = new DataTable(string.Format("TempTable{0}", _tempcount.ToString()));
  750. dtStaff.Columns.Add("IsSelected");
  751. dtStaff.Columns.Add("StaffID");
  752. dtStaff.Columns.Add("StaffCode");
  753. dtStaff.Columns.Add("StaffName");
  754. dtStaff.Columns.Add("StaffTempCount");
  755. dtStaff.Columns.Add("StaffStatus");
  756. this._dsStaff.Tables.Add(dtStaff);
  757. }
  758. // 防止工种不选择的话,直接New一个
  759. if (!this._dsMissedStaff.Tables.Contains(string.Format("TempTable{0}", _tempcount.ToString())))
  760. {
  761. DataTable dtMissedStaff = new DataTable(string.Format("TempTable{0}", _tempcount.ToString()));
  762. dtMissedStaff.Columns.Add("IsSelected");
  763. dtMissedStaff.Columns.Add("StaffID");
  764. dtMissedStaff.Columns.Add("StaffCode");
  765. dtMissedStaff.Columns.Add("StaffName");
  766. dtMissedStaff.Columns.Add("StaffTempCount");
  767. dtMissedStaff.Columns.Add("StaffStatus");
  768. dtMissedStaff.Columns.Add("UJobsID");
  769. dtMissedStaff.Columns.Add("SJobsID");
  770. this._dsMissedStaff.Tables.Add(dtMissedStaff);
  771. }
  772. if (!this._dsImage.Tables.Contains(string.Format("TempTable{0}", this._tempcount.ToString())))
  773. {
  774. DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._tempcount.ToString()));
  775. dtImage.Columns.Add("StaffTempCount");
  776. dtImage.Columns.Add("ImageByte", typeof(byte[]));
  777. dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
  778. this._dsImage.Tables.Add(dtImage);
  779. }
  780. this._frm3202.BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", _tempcount.ToString())]);
  781. this._tempcount = _tempcount + 1;
  782. this._frm3202.SetDataSource(_tempcount);
  783. ClearText();
  784. if (this._isEdit)
  785. {
  786. // 保存后如果是编辑进来的,更改后可以继续录入,当前改为插入了
  787. this._isEdit = false;
  788. }
  789. }
  790. catch (Exception ex)
  791. {
  792. // 对异常进行共通处理
  793. ExceptionManager.HandleEventException(this.ToString(),
  794. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  795. }
  796. }
  797. /// <summary>
  798. /// 上传图片按钮事件
  799. /// </summary>
  800. /// <param name="sender"></param>
  801. /// <param name="e"></param>
  802. private void btnUpload_Click(object sender, EventArgs e)
  803. {
  804. try
  805. {
  806. if (!this._dsImage.Tables.Contains(string.Format("TempTable{0}", this._tempcount.ToString())))
  807. {
  808. DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._tempcount.ToString()));
  809. dtImage.Columns.Add("StaffTempCount");
  810. dtImage.Columns.Add("ImageByte", typeof(byte[]));
  811. dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
  812. this._dsImage.Tables.Add(dtImage);
  813. }
  814. this.odlgFile.Filter = Constant.FILTER_PIC;
  815. this.odlgFile.FilterIndex = Constant.INT_IS_ZERO;
  816. this.odlgFile.RestoreDirectory = true;
  817. this.odlgFile.Title = "选择缺陷图片";
  818. this.odlgFile.FileName = null;
  819. this.odlgFile.RestoreDirectory = true;
  820. if (this.odlgFile.ShowDialog() == DialogResult.OK)
  821. {
  822. FileInfo file = new FileInfo(odlgFile.FileName);
  823. if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
  824. {
  825. MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "缺陷图片", "大小", "1M"),
  826. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  827. }
  828. else
  829. {
  830. Image PicImage = Image.FromStream(file.OpenRead());
  831. byte[] orgImageByte = ImageToByte(PicImage);
  832. this._PicByte.Add(orgImageByte);
  833. GetThumbnail(file, orgImageByte);
  834. BindImg();
  835. }
  836. }
  837. }
  838. catch (Exception ex)
  839. {
  840. // 对异常进行共通处理
  841. ExceptionManager.HandleEventException(this.ToString(),
  842. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  843. }
  844. }
  845. /// <summary>
  846. /// 删除图片按钮事件
  847. /// </summary>
  848. /// <param name="sender"></param>
  849. /// <param name="e"></param>
  850. private void btnDelete_Click(object sender, EventArgs e)
  851. {
  852. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  853. {
  854. int index = lvSelect.Index;
  855. if (index < Constant.INT_IS_ZERO)
  856. {
  857. index = Constant.INT_IS_ZERO;
  858. }
  859. this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].Rows.RemoveAt(lvSelect.Index);
  860. this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].AcceptChanges();
  861. this._frm3202.BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)]);
  862. this.BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)]);
  863. }
  864. }
  865. /// <summary>
  866. /// 缺陷位置验证事件
  867. /// </summary>
  868. /// <param name="sender"></param>
  869. /// <param name="e"></param>
  870. private void dropDefectLocation_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  871. {
  872. if (this.dropDefectLocation.SelectedValue != null && this.dropDefectLocation.SelectedValue.ToString() != string.Empty)
  873. {
  874. string DefectLocationCode = this.dropDefectLocation.SelectedValue.ToString();
  875. DataTable dtDefectLocationCode = this.dropDefectLocation.DataSource as DataTable;
  876. if (dtDefectLocationCode.Rows.Count > Constant.INT_IS_ZERO)
  877. {
  878. DataRow[] dr = dtDefectLocationCode.Select("DefectPositionID=" + DefectLocationCode);
  879. if (dr.Length > Constant.INT_IS_ZERO)
  880. {
  881. this._currentDefectPositionCode = dr[0]["DefectPositionCode"].ToString();
  882. }
  883. }
  884. }
  885. }
  886. /// <summary>
  887. /// 工号验证事件
  888. /// </summary>
  889. /// <param name="sender"></param>
  890. /// <param name="e"></param>
  891. private void dropDutyUser_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  892. {
  893. if (this.dropDutyUser.SelectedValue != null && this.dropDutyUser.SelectedValue.ToString() != string.Empty)
  894. {
  895. if (!this.txtRemarks.ReadOnly)
  896. {
  897. string DutyUserID = this.dropDutyUser.SelectedValue.ToString();
  898. DataTable dtDutyUserCode = this.dropDutyUser.DataSource as DataTable;
  899. if (dtDutyUserCode.Rows.Count > Constant.INT_IS_ZERO)
  900. {
  901. DataRow[] dr = dtDutyUserCode.Select("UserID=" + DutyUserID);
  902. if (dr.Length > Constant.INT_IS_ZERO)
  903. {
  904. this._currentDefectUserCode = dr[0]["UserCode"].ToString();
  905. }
  906. }
  907. // 判断责任工序是否选择,如果未选择,根据责任工号绑定工种
  908. if (this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty)
  909. {
  910. // 根据工号查找工种
  911. DataSet dsAllJobsByUserID = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  912. {
  913. return SystemModuleProxy.Service.GetAllJobsByUserID(Convert.ToInt32(DutyUserID));
  914. }));
  915. if (dsAllJobsByUserID != null && dsAllJobsByUserID.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  916. {
  917. this.dropJobs.DisplayMember = "JobsName";
  918. this.dropJobs.ValueMember = "Jobs";
  919. this.dropJobs.DataSource = dsAllJobsByUserID.Tables[0];
  920. this.dropJobs.SelectedValue = dsAllJobsByUserID.Tables[0].Rows[0]["Jobs"].ToString();
  921. //// 通过工种来搜索缺陷责任员工列表
  922. BindNoProcedureDutyStaff(Convert.ToInt32(dsAllJobsByUserID.Tables[0].Rows[0]["Jobs"]), this._tempcount);
  923. }
  924. }
  925. }
  926. }
  927. }
  928. /// <summary>
  929. /// 无责任工序下绑定缺陷责任员工
  930. /// </summary>
  931. /// <param name="productionDataID">生产数据ID</param>
  932. /// <param name="userID">用户ID</param>
  933. /// <param name="jobs">工种ID</param>
  934. /// <param name="StaffTempCount">唯一标识</param>
  935. private void BindNoProcedureDutyStaff(int jobs, int StaffTempCount)
  936. {
  937. if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", StaffTempCount.ToString())))
  938. {
  939. DataTable dtStaff = new DataTable(string.Format("TempTable{0}", StaffTempCount.ToString()));
  940. dtStaff.Columns.Add("IsSelected");
  941. dtStaff.Columns.Add("StaffID");
  942. dtStaff.Columns.Add("StaffCode");
  943. dtStaff.Columns.Add("StaffName");
  944. dtStaff.Columns.Add("StaffTempCount");
  945. dtStaff.Columns.Add("StaffStatus");
  946. this._dsStaff.Tables.Add(dtStaff);
  947. }
  948. // 获取临时表是否有数据,如果有行,则删除,
  949. DataTable dtTemp = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  950. if (dtTemp.Rows.Count > Constant.INT_IS_ZERO)
  951. {
  952. // 清空临时表数据
  953. this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Clear();
  954. }
  955. //DataSet dsDutyStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  956. //{
  957. // return PMModuleProxy.Service.GetDutyStaffByUserID(jobs);
  958. //}));
  959. int UserID = Convert.ToInt32(dropDutyUser.SelectedValue);
  960. DataSet dsDutyStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  961. {
  962. return PMModuleProxy.Service.GetDutyStaffByUserJobsID(jobs, UserID);
  963. }));
  964. if (dsDutyStaff != null && dsDutyStaff.Tables.Count > Constant.INT_IS_ZERO
  965. && dsDutyStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  966. {
  967. foreach (DataRow dr in dsDutyStaff.Tables[0].Rows)
  968. {
  969. DataRow addDr = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].NewRow();
  970. addDr["IsSelected"] = 1;
  971. addDr["StaffID"] = dr["StaffID"];
  972. addDr["StaffCode"] = dr["StaffCode"];
  973. addDr["StaffName"] = dr["StaffName"];
  974. addDr["StaffTempCount"] = StaffTempCount;
  975. addDr["StaffStatus"] = dr["StaffStatus"];
  976. this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Rows.Add(addDr);
  977. }
  978. this.dgvDefectStaff.DataSource = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  979. }
  980. }
  981. /// <summary>
  982. /// 工种验证事件
  983. /// </summary>
  984. /// <param name="sender"></param>
  985. /// <param name="e"></param>
  986. private void dropJobs_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  987. {
  988. if (this.dropJobs.SelectedValue != null && this.dropJobs.SelectedValue.ToString() != string.Empty)
  989. {
  990. if (!this.txtRemarks.ReadOnly)
  991. {
  992. if (this.dropDutyProcedure.SelectedValue != null && this.dropDutyProcedure.SelectedValue.ToString() != string.Empty)
  993. {
  994. BindDutyStaff(this._productionDataID, Convert.ToInt32(this.dropDutyUser.SelectedValue == null || this.dropDutyUser.SelectedValue.ToString() == "" ? 0 : this.dropDutyUser.SelectedValue), Convert.ToInt32(this.dropJobs.SelectedValue), this._tempcount);
  995. }
  996. else
  997. {
  998. BindNoProcedureDutyStaff(Convert.ToInt32(this.dropJobs.SelectedValue), this._tempcount);
  999. }
  1000. }
  1001. }
  1002. }
  1003. /// <summary>
  1004. /// 漏检工号检验事件
  1005. /// </summary>
  1006. /// <param name="sender"></param>
  1007. /// <param name="e"></param>
  1008. private void dropMissUser_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  1009. {
  1010. if (this.dropMissUser.SelectedValue != null && this.dropMissUser.SelectedValue.ToString() != string.Empty)
  1011. {
  1012. if (!this.txtRemarks.ReadOnly)
  1013. {
  1014. string MissedUserID = this.dropMissUser.SelectedValue.ToString();
  1015. DataTable dtMissedUserCode = this.dropMissUser.DataSource as DataTable;
  1016. if (dtMissedUserCode.Rows.Count > Constant.INT_IS_ZERO)
  1017. {
  1018. DataRow[] dr = dtMissedUserCode.Select("UserID=" + MissedUserID);
  1019. if (dr.Length > Constant.INT_IS_ZERO)
  1020. {
  1021. this._currentMissedUserCode = dr[0]["UserCode"].ToString();
  1022. }
  1023. }
  1024. BindMissedDutyStaff(Convert.ToInt32(this.dropMissUser.SelectedValue), this._tempcount);
  1025. }
  1026. }
  1027. }
  1028. /// <summary>
  1029. /// 关闭按钮事件
  1030. /// </summary>
  1031. /// <param name="sender"></param>
  1032. /// <param name="e"></param>
  1033. private void btnCancel_Click(object sender, EventArgs e)
  1034. {
  1035. this.Close();
  1036. }
  1037. #endregion
  1038. #region 私有方法
  1039. /// <summary>
  1040. /// 获取缺陷
  1041. /// </summary>
  1042. /// <returns></returns>
  1043. private DataTable GetDuty()
  1044. {
  1045. DataTable dtDuty = new DataTable();
  1046. dtDuty.Columns.Add("DEFECTFLAGNAME");
  1047. dtDuty.Columns.Add("DEFECTFLAGID");
  1048. return dtDuty;
  1049. }
  1050. /// <summary>
  1051. /// 责任工序数据表
  1052. /// </summary>
  1053. /// <returns></returns>
  1054. private DataTable GetDutyProcedure()
  1055. {
  1056. DataTable dtDutyProcedure = new DataTable();
  1057. dtDutyProcedure.Columns.Add("DutyProcedureName");
  1058. dtDutyProcedure.Columns.Add("DutyProcedureID");
  1059. return dtDutyProcedure;
  1060. }
  1061. /// <summary>
  1062. /// 责任工号数据表 责任工序不选择时,默认数据源
  1063. /// </summary>
  1064. /// <returns></returns>
  1065. private DataTable GetDutyProcedureUser()
  1066. {
  1067. SUserEntity userEntity = new SUserEntity();
  1068. userEntity.IsWorker = 1;//生产工号
  1069. DataSet dsDutyProcedureUser = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1070. {
  1071. return SystemModuleProxy.Service.SearchUserData(userEntity);
  1072. }));
  1073. DataRow dr = dsDutyProcedureUser.Tables[0].NewRow();
  1074. dr["UserID"] = -1;
  1075. dr["UserCode"] = "";
  1076. dr["UserName"] = "";
  1077. dsDutyProcedureUser.Tables[0].Rows.InsertAt(dr, 0);
  1078. dsDutyProcedureUser.Tables[0].AcceptChanges();
  1079. this._dtDutyProcedureUser = dsDutyProcedureUser.Tables[0];
  1080. return dsDutyProcedureUser.Tables[0];
  1081. }
  1082. /// <summary>
  1083. /// 责任工种数据表
  1084. /// </summary>
  1085. /// <returns></returns>
  1086. private DataTable GetDutyProcedureJobs()
  1087. {
  1088. DataTable dtDutyProcedureJobs = new DataTable();
  1089. dtDutyProcedureJobs.Columns.Add("JobsName");
  1090. dtDutyProcedureJobs.Columns.Add("Jobs");
  1091. return dtDutyProcedureJobs;
  1092. }
  1093. /// <summary>
  1094. /// 绑定责任工序
  1095. /// </summary>
  1096. /// <param name="barcode">产品条码</param>
  1097. /// <param name="defectid">责任工序</param>
  1098. private void BindDutyDefect(string barcode, int defectid)
  1099. {
  1100. DataSet dsDutyDefect = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1101. {
  1102. return PMModuleProxy.Service.GetDutyProcedureByBarCode(barcode, defectid);
  1103. }));
  1104. if (dsDutyDefect != null && dsDutyDefect.Tables.Count > Constant.INT_IS_ZERO
  1105. && dsDutyDefect.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  1106. {
  1107. //modify wangx 20150629
  1108. if (dsDutyDefect.Tables[1] != null && dsDutyDefect.Tables[1].Rows.Count > 0)
  1109. {
  1110. this._defaultJobsID = dsDutyDefect.Tables[1];
  1111. }
  1112. //modify wangx 20150629 end
  1113. if (SpecialRepairflag == 1) //干补过,去掉首节点,即交坯节
  1114. {
  1115. DataRow[] dr = dsDutyDefect.Tables[0].Select("ModelType<>5");
  1116. DataTable dt = null;
  1117. if (dr.Length > 0)
  1118. {
  1119. dt = dsDutyDefect.Tables[0].Select("ModelType<>5").CopyToDataTable();
  1120. }
  1121. this.dropDutyProcedure.DataSource = null;
  1122. this.dropDutyProcedure.DisplayMember = "DutyProcedureName";
  1123. this.dropDutyProcedure.ValueMember = "DutyProcedureID";
  1124. if (dt != null)
  1125. {
  1126. this.dropDutyProcedure.DataSource = dt;
  1127. }
  1128. else
  1129. {
  1130. this.dropDutyProcedure.DataSource = GetDutyProcedure();
  1131. }
  1132. }
  1133. else
  1134. {
  1135. this.dropDutyProcedure.DataSource = null;
  1136. this.dropDutyProcedure.DisplayMember = "DutyProcedureName";
  1137. this.dropDutyProcedure.ValueMember = "DutyProcedureID";
  1138. this.dropDutyProcedure.DataSource = dsDutyDefect.Tables[0];
  1139. }
  1140. //// 设置责任工号及责任工种
  1141. //SetDutyCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
  1142. //string DutyProcedure = this.dropDutyProcedure.SelectedValue.ToString();
  1143. //DataTable dtDutyProcedureCode = this.dropDutyProcedure.DataSource as DataTable;
  1144. //if (dtDutyProcedureCode.Rows.Count > Constant.INT_IS_ZERO)
  1145. //{
  1146. // DataRow[] dr = dtDutyProcedureCode.Select("DutyProcedureID=" + DutyProcedure);
  1147. // if (dr.Length > Constant.INT_IS_ZERO)
  1148. // {
  1149. // this._currentDefectProcedureCode = dr[0]["DutyProcedureCode"].ToString();
  1150. // }
  1151. //}
  1152. }
  1153. else
  1154. {
  1155. this.dropDutyProcedure.DisplayMember = "DutyProcedureName";
  1156. this.dropDutyProcedure.ValueMember = "DutyProcedureID";
  1157. this.dropDutyProcedure.DataSource = GetDutyProcedure();
  1158. this.dropDutyProcedure.Text = string.Empty;
  1159. }
  1160. this.dropDutyUser.DataSource = null;
  1161. this.dropDutyUser.DisplayMember = "UserCode";
  1162. this.dropDutyUser.ValueMember = "UserID";
  1163. this.dropDutyUser.DataSource = this._dtDutyProcedureUser;//GetDutyProcedureUser();
  1164. this.dropDutyUser.Text = string.Empty;
  1165. this.dropJobs.DataSource = null;
  1166. this.dropJobs.DisplayMember = "JobsName";
  1167. this.dropJobs.ValueMember = "Jobs";
  1168. this.dropJobs.DataSource = GetDutyProcedureJobs();
  1169. this.dropJobs.Text = string.Empty;
  1170. }
  1171. /// <summary>
  1172. /// 根据责任工序读出责任员工,并绑定到数据源
  1173. /// </summary>
  1174. /// <param name="barcode"></param>
  1175. /// <param name="dutyProcedureID"></param>
  1176. private void SetDutyCode(string barcode, int dutyProcedureID)
  1177. {
  1178. //DataSet dsDutyCode = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1179. //{
  1180. // return PMModuleProxy.Service.GetDutyProcedureCodeByBarCode(barcode, dutyProcedureID);
  1181. //}));
  1182. DataTable dt = this.dropDutyProcedure.DataSource as DataTable;
  1183. int ProductionDataID = Convert.ToInt32(dt.Select("DutyProcedureID=" + dutyProcedureID)[0]["ProductionDataID"]);
  1184. DataSet dsDutyCode = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1185. {
  1186. return PMModuleProxy.Service.GetDutyProcedureCodeByProductionDataID(ProductionDataID);
  1187. }));
  1188. if (dsDutyCode != null && dsDutyCode.Tables.Count > Constant.INT_IS_ZERO
  1189. && dsDutyCode.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  1190. {
  1191. this.dropDutyUser.DataSource = null;
  1192. this.dropDutyUser.DisplayMember = "UserCode";
  1193. this.dropDutyUser.ValueMember = "UserID";
  1194. this.dropDutyUser.DataSource = dsDutyCode.Tables[0];
  1195. string DutyUserCode = this.dropDutyUser.SelectedValue.ToString();
  1196. DataTable dtDutyUserCode = this.dropDutyUser.DataSource as DataTable;
  1197. if (dtDutyUserCode.Rows.Count > Constant.INT_IS_ZERO)
  1198. {
  1199. DataRow[] dr = dtDutyUserCode.Select("UserID=" + DutyUserCode);
  1200. if (dr.Length > Constant.INT_IS_ZERO)
  1201. {
  1202. this._currentDefectUserCode = dr[0]["UserCode"].ToString();
  1203. }
  1204. }
  1205. this._productionDataID = Convert.ToInt32(dsDutyCode.Tables[0].Rows[0]["ProductionDataID"].ToString());
  1206. SetDutyJobs(Convert.ToInt32(dsDutyCode.Tables[0].Rows[0]["UserID"]), dutyProcedureID, 0, Convert.ToInt32(dsDutyCode.Tables[0].Rows[0]["ProductionDataID"]));
  1207. }
  1208. else
  1209. {
  1210. this.dropDutyUser.DisplayMember = "UserCode";
  1211. this.dropDutyUser.ValueMember = "UserID";
  1212. this.dropDutyUser.DataSource = GetDutyProcedureUser();
  1213. }
  1214. }
  1215. /// <summary>
  1216. /// 根据责任工序读出工种,并绑定到数据源
  1217. /// </summary>
  1218. private void SetDutyJobs(int UserID, int dutyProcedureID, int rowIndex, int ProductionDataID)
  1219. {
  1220. DataSet dsDutyJobs = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1221. {
  1222. return PMModuleProxy.Service.GetDutyJobsCodeByUser(UserID, ProductionDataID);
  1223. }));
  1224. if (dsDutyJobs != null && dsDutyJobs.Tables.Count > Constant.INT_IS_ZERO
  1225. && dsDutyJobs.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  1226. {
  1227. this.dropJobs.DataSource = null;
  1228. this.dropJobs.DisplayMember = "JobsName";
  1229. this.dropJobs.ValueMember = "JobsID";
  1230. this.dropJobs.DataSource = dsDutyJobs.Tables[0];
  1231. this.dropJobs.SelectedValue = dsDutyJobs.Tables[0].Rows[0]["JobsID"].ToString();
  1232. if (this._defaultJobsID != null)
  1233. {
  1234. DataRow[] dr = this._defaultJobsID.Select("procedureid=" + dutyProcedureID);
  1235. if (dr.Length > 0)
  1236. {
  1237. if (dsDutyJobs.Tables[0].Select("JobsID=" + dr[0]["jobsid"].ToString()).Length > 0)
  1238. {
  1239. this.dropJobs.SelectedValue = dr[0]["jobsid"].ToString();
  1240. }
  1241. }
  1242. }
  1243. //// 通过工种来搜索缺陷责任员工列表 dsDutyJobs.Tables[0].Rows[0]["JobsID"]-->this.dropJobs.SelectedValue
  1244. BindDutyStaff(ProductionDataID, UserID, Convert.ToInt32(this.dropJobs.SelectedValue), this._tempcount);
  1245. }
  1246. }
  1247. /// <summary>
  1248. /// 绑定缺陷责任员工
  1249. /// </summary>
  1250. /// <param name="productionDataID">生产数据ID</param>
  1251. /// <param name="userID">用户ID</param>
  1252. /// <param name="jobs">工种ID</param>
  1253. /// <param name="StaffTempCount">唯一标识</param>
  1254. private void BindDutyStaff(int productionDataID, int userID, int jobs, int StaffTempCount)
  1255. {
  1256. if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", StaffTempCount.ToString())))
  1257. {
  1258. DataTable dtStaff = new DataTable(string.Format("TempTable{0}", StaffTempCount.ToString()));
  1259. dtStaff.Columns.Add("IsSelected");
  1260. dtStaff.Columns.Add("StaffID");
  1261. dtStaff.Columns.Add("StaffCode");
  1262. dtStaff.Columns.Add("StaffName");
  1263. dtStaff.Columns.Add("StaffTempCount");
  1264. dtStaff.Columns.Add("StaffStatus");
  1265. this._dsStaff.Tables.Add(dtStaff);
  1266. }
  1267. // 获取临时表是否有数据,如果有行,则删除,
  1268. DataTable dtTemp = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  1269. if (dtTemp.Rows.Count > Constant.INT_IS_ZERO)
  1270. {
  1271. // 清空临时表数据
  1272. this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Clear();
  1273. }
  1274. DataSet dsDutyStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1275. {
  1276. return PMModuleProxy.Service.GetDutyStaffByUserIDAndJobs(productionDataID, userID, jobs);
  1277. }));
  1278. if (dsDutyStaff != null && dsDutyStaff.Tables.Count > Constant.INT_IS_ZERO
  1279. && dsDutyStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  1280. {
  1281. foreach (DataRow dr in dsDutyStaff.Tables[0].Rows)
  1282. {
  1283. DataRow addDr = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].NewRow();
  1284. addDr["IsSelected"] = 1;
  1285. addDr["StaffID"] = dr["StaffID"];
  1286. addDr["StaffCode"] = dr["StaffCode"];
  1287. addDr["StaffName"] = dr["StaffName"];
  1288. addDr["StaffTempCount"] = StaffTempCount;
  1289. addDr["StaffStatus"] = dr["StaffStatus"];
  1290. this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Rows.Add(addDr);
  1291. }
  1292. this.dgvDefectStaff.DataSource = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  1293. }
  1294. }
  1295. /// <summary>
  1296. /// 保存后界面数据初始化
  1297. /// </summary>
  1298. private void ClearText()
  1299. {
  1300. this.dropDuty.SelectedValue = string.Empty;
  1301. this.dropDuty.Text = string.Empty;
  1302. this.dropDefectLocation.SelectedValue = string.Empty;
  1303. this.dropDefectLocation.Text = string.Empty;
  1304. this.dropDutyProcedure.SelectedValue = null;
  1305. this.dropDutyProcedure.Text = string.Empty;
  1306. this.dropDutyUser.SelectedValue = null;
  1307. this.dropDutyUser.Text = string.Empty;
  1308. this.dropJobs.SelectedValue = null;
  1309. this.dropJobs.Text = string.Empty;
  1310. this.txtRemarks.Text = string.Empty;
  1311. this.dgvDefectStaff.DataSource = null;
  1312. this.dgvMissStaff.DataSource = null;
  1313. this._smallByte.Clear();
  1314. this.lvPic.Clear();
  1315. this.cmbDefectFine.SelectedValue = -1;
  1316. this.dropMissUser.SelectedValue = null;
  1317. this.dropMissUser.Text = string.Empty;
  1318. }
  1319. /// <summary>
  1320. /// 将图片文件转换成二进制
  1321. /// </summary>
  1322. /// <param name="img"></param>
  1323. /// <returns></returns>
  1324. public static byte[] ImageToByte(Image img)
  1325. {
  1326. byte[] smallbuffer = null;
  1327. using (MemoryStream ms = new MemoryStream())
  1328. {
  1329. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1330. ms.Position = Constant.INT_IS_ZERO;
  1331. smallbuffer = new byte[ms.Length];
  1332. ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
  1333. ms.Flush();
  1334. }
  1335. return smallbuffer;
  1336. }
  1337. /// <SUMMARY>
  1338. /// 重绘缩略图并把缩略图转为二进制储存
  1339. /// </SUMMARY>
  1340. /// <PARAM name="sourceFile">图片源路径</PARAM>
  1341. /// <PARAM name="destHeight">缩放后图片高度</PARAM>
  1342. /// <PARAM name="destWidth">缩放后图片宽度</PARAM>
  1343. /// <RETURNS></RETURNS>
  1344. public void GetThumbnail(FileInfo sourceFile, byte[] orgImageByte)
  1345. {
  1346. Image imgSource = Image.FromStream(sourceFile.OpenRead());
  1347. ImageFormat thisFormat = imgSource.RawFormat;
  1348. int sW = 0, sH = 0;
  1349. // 按比例缩放
  1350. int sWidth = imgSource.Width;
  1351. int sHeight = imgSource.Height;
  1352. int destWidth = 100;
  1353. int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
  1354. if (sHeight > destHeight || sWidth > destWidth)
  1355. {
  1356. if ((sWidth * destHeight) > (sHeight * destWidth))
  1357. {
  1358. sW = destWidth;
  1359. sH = (destWidth * sHeight) / sWidth;
  1360. }
  1361. else
  1362. {
  1363. sH = destHeight;
  1364. sW = (sWidth * destHeight) / sHeight;
  1365. }
  1366. }
  1367. else
  1368. {
  1369. sW = sWidth;
  1370. sH = sHeight;
  1371. }
  1372. Bitmap outBmp = new Bitmap(destWidth, destHeight);
  1373. Graphics g = Graphics.FromImage(outBmp);
  1374. g.Clear(Color.Black);
  1375. // 设置画布的描绘质量
  1376. g.CompositingQuality = CompositingQuality.HighQuality;
  1377. g.SmoothingMode = SmoothingMode.HighQuality;
  1378. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  1379. g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
  1380. g.Dispose();
  1381. //将重绘的图片转为二进制并保存
  1382. Image image = (Image)outBmp;
  1383. byte[] smallbuffer = ImageToByte(image);
  1384. DataRow dr = this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].NewRow();
  1385. dr["StaffTempCount"] = this._tempcount;
  1386. dr["ImageByte"] = smallbuffer;
  1387. dr["OrgImageByte"] = orgImageByte;
  1388. this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].Rows.Add(dr);
  1389. this._smallByte.Add(smallbuffer);
  1390. imgSource.Dispose();
  1391. outBmp.Dispose();
  1392. }
  1393. /// <summary>
  1394. /// 根据原图片宽高比获取缩略图的高(根据宽)
  1395. /// </summary>
  1396. /// <param name="BigWidth"></param>
  1397. /// <param name="BigHeight"></param>
  1398. /// <param name="SmallWidth"></param>
  1399. /// <returns></returns>
  1400. protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
  1401. {
  1402. decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
  1403. return Convert.ToInt32(SmallWidth / scale);
  1404. }
  1405. /// <summary>
  1406. /// 绑定缩略图到控件中
  1407. /// </summary>
  1408. protected void BindImg()
  1409. {
  1410. ImageList ilPic = new ImageList();
  1411. //每次绑定要清空数据源
  1412. ilPic.Images.Clear();
  1413. //将缩略图二进制集合中的数据转换成图片文件
  1414. List<Image> LSImageList = new List<Image>();
  1415. foreach (byte[] smallby in _smallByte)
  1416. {
  1417. LSImageList.Add(byteArrayToImage(smallby));
  1418. }
  1419. //添加数据源
  1420. foreach (Image img in LSImageList)
  1421. {
  1422. ilPic.Images.Add(img);
  1423. }
  1424. ilPic.ImageSize = new Size(100, 100);
  1425. this.lvPic.LargeImageList = ilPic;
  1426. this.lvPic.BeginUpdate();
  1427. //清空列表的数据源
  1428. lvPic.Items.Clear();
  1429. //添加列表的数据源
  1430. for (int i = 0; i < ilPic.Images.Count; i++)
  1431. {
  1432. ListViewItem lvi = new ListViewItem();
  1433. lvi.ImageIndex = i;
  1434. this.lvPic.Items.Add(lvi);
  1435. }
  1436. this.lvPic.EndUpdate();
  1437. }
  1438. /// <summary>
  1439. /// 将数据库中的二进制转换成图片
  1440. /// </summary>
  1441. /// <param name="data"></param>
  1442. /// <returns></returns>
  1443. public static Image byteArrayToImage(object data)
  1444. {
  1445. System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
  1446. System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
  1447. return returnImage;
  1448. }
  1449. /// <summary>
  1450. /// 绑定并显示图片
  1451. /// </summary>
  1452. /// <param name="ImageData"></param>
  1453. private void BindByteImage(DataTable ImageData)
  1454. {
  1455. this._smallByte.Clear();
  1456. foreach (DataRow dr in ImageData.Rows)
  1457. {
  1458. //将数据库中的缩略图取出
  1459. this._smallByte.Add((byte[])dr[1]);
  1460. }
  1461. //绑定缩略图
  1462. BindImg();
  1463. }
  1464. /// <summary>
  1465. /// 根据漏检工号绑定漏检责任员工
  1466. /// </summary>
  1467. /// <param name="jobs">工种ID</param>
  1468. /// <param name="StaffTempCount">唯一标识</param>
  1469. private void BindMissedDutyStaff(int userid, int StaffTempCount)
  1470. {
  1471. if (!this._dsMissedStaff.Tables.Contains(string.Format("TempTable{0}", StaffTempCount.ToString())))
  1472. {
  1473. DataTable dtMissedStaff = new DataTable(string.Format("TempTable{0}", StaffTempCount.ToString()));
  1474. dtMissedStaff.Columns.Add("IsSelected");
  1475. dtMissedStaff.Columns.Add("StaffID");
  1476. dtMissedStaff.Columns.Add("StaffCode");
  1477. dtMissedStaff.Columns.Add("StaffName");
  1478. dtMissedStaff.Columns.Add("StaffTempCount");
  1479. dtMissedStaff.Columns.Add("StaffStatus");
  1480. dtMissedStaff.Columns.Add("UJobsID");
  1481. dtMissedStaff.Columns.Add("SJobsID");
  1482. this._dsMissedStaff.Tables.Add(dtMissedStaff);
  1483. }
  1484. // 获取临时表是否有数据,如果有行,则删除,
  1485. DataTable dtTemp = this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  1486. if (dtTemp.Rows.Count > Constant.INT_IS_ZERO)
  1487. {
  1488. // 清空临时表数据
  1489. this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Clear();
  1490. }
  1491. DataSet dsMissedDutyStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1492. {
  1493. return PMModuleProxy.Service.GetMissedStaffByUserID(userid);
  1494. }));
  1495. if (dsMissedDutyStaff != null && dsMissedDutyStaff.Tables.Count > Constant.INT_IS_ZERO
  1496. && dsMissedDutyStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  1497. {
  1498. foreach (DataRow dr in dsMissedDutyStaff.Tables[0].Rows)
  1499. {
  1500. DataRow addDr = this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].NewRow();
  1501. addDr["IsSelected"] = 1;
  1502. addDr["StaffID"] = dr["StaffID"];
  1503. addDr["StaffCode"] = dr["StaffCode"];
  1504. addDr["StaffName"] = dr["StaffName"];
  1505. addDr["StaffTempCount"] = StaffTempCount;
  1506. addDr["StaffStatus"] = dr["StaffStatus"];
  1507. addDr["UJobsID"] = dr["UJobsID"];
  1508. addDr["SJobsID"] = dr["SJobsID"];
  1509. this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Rows.Add(addDr);
  1510. }
  1511. this.dgvMissStaff.DataSource = this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  1512. }
  1513. }
  1514. #endregion
  1515. }
  1516. }