F_PM_0903.cs 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_0903.cs
  5. * 2.功能描述:新建半成品检验
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2014/10/06 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.Client.Controls.FormCommon;
  22. using Dongke.IBOSS.PRD.WCF.DataModels;
  23. using Dongke.IBOSS.PRD.WCF.Proxys;
  24. using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
  25. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  26. namespace Dongke.IBOSS.PRD.Client.PMModule
  27. {
  28. /// <summary>
  29. /// 新建半成品检验
  30. /// </summary>
  31. public partial class F_PM_0903 : FormBase
  32. {
  33. #region 成员变量
  34. // 工序ID
  35. private int _procedureID;
  36. // 生产工号
  37. private int _userID = -1;
  38. // 生产编号
  39. private string _userCode;
  40. // 生产名称
  41. private string _userName;
  42. // 工序实体类
  43. ProcedureEntity _procedureDataEntity;
  44. // 产品数据表
  45. DataTable _dtProductionData = null;
  46. // 产品缺陷数据表
  47. DataTable _dtProductionDefectData = null;
  48. // 当前选择的行
  49. private int _selectedRowIndex;
  50. // ComBoxEditingControl
  51. private DataGridViewComboBoxEditingControl _dataGridViewComboBox = null;
  52. // 当前产品条码的产品ID,用来查询缺陷位置
  53. private int _currentGoodsID = 0;
  54. // 当前产品条码,用来切换筛选列表数据
  55. private string _currentBarCode = "";
  56. // 当前产品缺陷
  57. private int _currentDefectFlag = 0;
  58. // 返工工序搜索列表对象
  59. C_DGV_Cell_ListBoxComboBox _C_DGV_Cell_ListBoxComboBox = null;
  60. // 过滤结果集
  61. private DataSet _ds = null;
  62. // 过滤员工结果集
  63. private DataSet _dsStaff = null;
  64. // 过滤缺陷图片
  65. private DataSet _dsImage = null;
  66. // 临时数,用来过滤责任员工数据源标识
  67. private int _tempCount = 0;
  68. // 当前临时标记
  69. private string _currentTempSign = "";
  70. // 图片字节集
  71. private List<byte[]> _PicByte = new List<byte[]>();
  72. // 缩略图片字节集
  73. private List<byte[]> _smallByte = new List<byte[]>();
  74. // 当前产品缺陷
  75. private int _currentDefaultDefectFlag = 0;
  76. // 当前默认产品分级ID
  77. private int _currentGoodsLevelTypeID = 0;
  78. // 返回工序数据源
  79. private DataSet _dsRework = null;
  80. //产品等级数据源
  81. private DataSet _dsGoodsLevel = null;
  82. // 生产数据ID
  83. private int? _productionDataID = null;
  84. // 过滤漏检员工结果集
  85. private DataSet _dsMissdeStaff = null;
  86. #endregion
  87. #region 属性
  88. /// <summary>
  89. /// 条码返工工序数据源
  90. /// </summary>
  91. public DataSet DSREWORK
  92. {
  93. set
  94. {
  95. _dsRework = value;
  96. }
  97. get
  98. {
  99. if (_dsRework == null)
  100. {
  101. return _dsRework = new DataSet();
  102. }
  103. return _dsRework;
  104. }
  105. }
  106. /// <summary>
  107. /// 生产工号
  108. /// </summary>
  109. public int UserID
  110. {
  111. set
  112. {
  113. _userID = value;
  114. }
  115. get
  116. {
  117. return _userID;
  118. }
  119. }
  120. /// <summary>
  121. /// 生产编号
  122. /// </summary>
  123. public string UserCode
  124. {
  125. set
  126. {
  127. _userCode = value;
  128. }
  129. get
  130. {
  131. return _userCode;
  132. }
  133. }
  134. /// <summary>
  135. /// 用户名称
  136. /// </summary>
  137. public string UserName
  138. {
  139. set
  140. {
  141. _userName = value;
  142. }
  143. get
  144. {
  145. return _userName;
  146. }
  147. }
  148. /// <summary>
  149. /// 产品数据表
  150. /// </summary>
  151. public DataTable TableProductionData
  152. {
  153. set
  154. {
  155. _dtProductionData = value;
  156. }
  157. get
  158. {
  159. if (_dtProductionData == null)
  160. {
  161. _dtProductionData = new DataTable("ProductionData");
  162. _dtProductionData.Columns.Add("ProductionDataID");
  163. _dtProductionData.Columns.Add("BarCode");
  164. _dtProductionData.Columns.Add("GoodsID");
  165. _dtProductionData.Columns.Add("GoodsCode");
  166. _dtProductionData.Columns.Add("GoodsName");
  167. _dtProductionData.Columns.Add("DefectFlagID", typeof(decimal));
  168. _dtProductionData.Columns.Add("ReworkProcedureID", typeof(decimal));
  169. _dtProductionData.Columns.Add("Remarks");
  170. _dtProductionData.Columns.Add("UserID");
  171. _dtProductionData.Columns.Add("GoodsLevelTypeID");
  172. _dtProductionData.Columns.Add("ReFine");//重烧标识
  173. _dtProductionData.Columns.Add("SpecialRepairflag");//干补标识
  174. _dtProductionData.Columns.Add("SpecialRepairflagValue");//干补标识
  175. _dtProductionData.Columns.Add("UserCode");//生产工号
  176. _dtProductionData.Columns.Add("MouldCode");//模具编号
  177. _dtProductionData.Columns.Add("GroutingDate", typeof(DateTime));//注浆日期
  178. _dtProductionData.Columns.Add("GroutingUserCode");//成型工号
  179. _dtProductionData.Columns.Add("GroutingNum");//注浆次数
  180. _dtProductionData.Columns.Add("KilnCarCode");
  181. _dtProductionData.Columns.Add("KilnCode");
  182. _dtProductionData.Columns.Add("Dictionaryvalue");
  183. _dtProductionData.Columns.Add("IsPublicBody");//公坯标识
  184. _dtProductionData.Columns.Add("LogoCodeName");
  185. _dtProductionData.Columns.Add("LogoID");
  186. return _dtProductionData;
  187. }
  188. else
  189. {
  190. return _dtProductionData;
  191. }
  192. }
  193. }
  194. /// <summary>
  195. /// 缺陷数据集
  196. /// </summary>
  197. public DataSet DSTable
  198. {
  199. set
  200. {
  201. _ds = value;
  202. }
  203. get
  204. {
  205. if (_ds == null)
  206. {
  207. _ds = new DataSet();
  208. return _ds;
  209. }
  210. else
  211. {
  212. return _ds;
  213. }
  214. }
  215. }
  216. /// <summary>
  217. /// 员工数据集
  218. /// </summary>
  219. public DataSet DSTableStaff
  220. {
  221. set
  222. {
  223. _dsStaff = value;
  224. }
  225. get
  226. {
  227. if (_dsStaff == null)
  228. {
  229. _dsStaff = new DataSet();
  230. return _dsStaff;
  231. }
  232. else
  233. {
  234. return _dsStaff;
  235. }
  236. }
  237. }
  238. /// <summary>
  239. /// 漏检员工数据集
  240. /// </summary>
  241. public DataSet DSTableMissedStaff
  242. {
  243. set
  244. {
  245. _dsMissdeStaff = value;
  246. }
  247. get
  248. {
  249. if (_dsMissdeStaff == null)
  250. {
  251. _dsMissdeStaff = new DataSet();
  252. return _dsMissdeStaff;
  253. }
  254. else
  255. {
  256. return _dsMissdeStaff;
  257. }
  258. }
  259. }
  260. /// <summary>
  261. /// 缺陷图片
  262. /// </summary>
  263. public DataSet DSTableImage
  264. {
  265. set
  266. {
  267. _dsImage = value;
  268. }
  269. get
  270. {
  271. if (_dsImage == null)
  272. {
  273. _dsImage = new DataSet();
  274. return _dsImage;
  275. }
  276. else
  277. {
  278. return _dsImage;
  279. }
  280. }
  281. }
  282. #endregion
  283. #region 构造函数
  284. public F_PM_0903()
  285. {
  286. InitializeComponent();
  287. }
  288. public F_PM_0903(int procedureID, string fromTitle)
  289. {
  290. InitializeComponent();
  291. this._procedureID = procedureID;
  292. this.Text = fromTitle;
  293. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  294. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  295. this.btnSave.Text = ButtonText.BTN_SAVE;
  296. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  297. //this.tsbtnClose.Text = ButtonText.TSBTN_TOOL_CLOSE;
  298. this.btnUpload.Text = ButtonText.BTN_UPLOAD;
  299. this.btnDelete.Text = ButtonText.BTN_DELETE;
  300. }
  301. public F_PM_0903(int procedureID, string fromTitle, int ProductionDataID)
  302. {
  303. InitializeComponent();
  304. this._procedureID = procedureID;
  305. this._productionDataID = ProductionDataID;
  306. this.Text = fromTitle;
  307. this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
  308. this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
  309. this.btnSave.Text = ButtonText.BTN_SAVE;
  310. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  311. //this.tsbtnClose.Text = ButtonText.TSBTN_TOOL_CLOSE;
  312. this.btnUpload.Text = ButtonText.BTN_UPLOAD;
  313. this.btnDelete.Text = ButtonText.BTN_DELETE;
  314. }
  315. #endregion
  316. #region 事件
  317. /// <summary>
  318. /// 窗体加载事件
  319. /// </summary>
  320. /// <param name="sender"></param>
  321. /// <param name="e"></param>
  322. private void F_PM_0901_Load(object sender, System.EventArgs e)
  323. {
  324. try
  325. {
  326. this.btnCancel.CausesValidation = false;
  327. this.dgvProductionData.AutoGenerateColumns = false;
  328. this.dgvProductionData.DataSource = TableProductionData;
  329. this.dgvDefect.AutoGenerateColumns = false;
  330. this.dgvDefectStaff.AutoGenerateColumns = false;
  331. // 加载权限
  332. FormPermissionManager.FormPermissionControl(this.Name, this,
  333. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  334. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  335. // 获取工序明细数据
  336. ProcedureEntity procedureDataEntity = (ProcedureEntity)DoAsync(new BaseAsyncMethod(() =>
  337. {
  338. return PMModuleProxy.Service.GetProcedureDataEntityByID(this._procedureID);
  339. }));
  340. this._procedureDataEntity = procedureDataEntity;
  341. if (this._procedureDataEntity.NodeType == 1)//开始结点
  342. {
  343. this.DefectProcedureName.Visible = false;
  344. this.DefectUserName.Visible = false;
  345. this.JobsText.Visible = false;
  346. this.tabPage3.Parent = null;
  347. }
  348. // 缺陷数据源
  349. DataSet dsGoodsLevel = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  350. {
  351. return SystemModuleProxy.Service.GetGoodsLevel(1);//半成品检验
  352. }));
  353. if (dsGoodsLevel != null && dsGoodsLevel.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  354. {
  355. this._dsGoodsLevel = dsGoodsLevel;
  356. }
  357. // 设置控件禁用或启用
  358. SetControlEnable();
  359. #region wangx 2012-12-28 add
  360. if (this._productionDataID != null)
  361. {
  362. //加载数据源
  363. this.txtUserCode.Enabled = false;
  364. this.txtBarCode.Enabled = false;
  365. this.tsbtnAdd.Enabled = true;
  366. // 此工号是否能生产工序
  367. CheckProcedureUserResult checkProcedureUser = (CheckProcedureUserResult)DoAsync(new BaseAsyncMethod(() =>
  368. {
  369. return PMModuleProxy.Service.CheckProcedureUser(this._procedureID,
  370. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserCode);
  371. }));
  372. if (checkProcedureUser != null)
  373. {
  374. if (!string.IsNullOrEmpty(checkProcedureUser.ErrMsg))
  375. {
  376. // 此工号不允许生产工序
  377. MessageBox.Show(checkProcedureUser.ErrMsg,
  378. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  379. this.Close();
  380. return;
  381. }
  382. }
  383. UserID = checkProcedureUser.UserID;
  384. UserCode = checkProcedureUser.UserCode;
  385. UserName = checkProcedureUser.UserName;
  386. this.txtUserCode.Text = UserCode;
  387. DataSet dsProductionDataByID = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  388. {
  389. return PMModuleProxy.Service.GetProductionDataByID(Convert.ToInt32(this._productionDataID));
  390. }));
  391. if (dsProductionDataByID != null && dsProductionDataByID.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  392. {
  393. // 干补标识
  394. int SpecialRepairflag = (int)DoAsync(new BaseAsyncMethod(() =>
  395. {
  396. return PMModuleProxy.Service.GetSpecialRepairflagByBarcode(dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString());
  397. }));
  398. // 产品数据
  399. DataRow drNew = TableProductionData.NewRow();
  400. drNew["ProductionDataID"] = this._productionDataID;
  401. drNew["BarCode"] = dsProductionDataByID.Tables[0].Rows[0]["BarCode"];
  402. drNew["GoodsID"] = dsProductionDataByID.Tables[0].Rows[0]["GoodsID"];
  403. drNew["GoodsCode"] = dsProductionDataByID.Tables[0].Rows[0]["GoodsCode"];
  404. drNew["GoodsName"] = dsProductionDataByID.Tables[0].Rows[0]["GoodsName"];
  405. drNew["DefectFlagID"] = dsProductionDataByID.Tables[0].Rows[0]["DefectFlagID"];
  406. drNew["ReworkProcedureID"] = dsProductionDataByID.Tables[0].Rows[0]["ReworkProcedureID"];
  407. drNew["Remarks"] = dsProductionDataByID.Tables[0].Rows[0]["Remarks"];
  408. drNew["UserID"] = dsProductionDataByID.Tables[0].Rows[0]["UserID"];
  409. drNew["KilnCarCode"] = dsProductionDataByID.Tables[0].Rows[0]["KilnCarCode"];
  410. drNew["KilnCode"] = dsProductionDataByID.Tables[0].Rows[0]["KilnCode"];
  411. drNew["Dictionaryvalue"] = dsProductionDataByID.Tables[0].Rows[0]["Dictionaryvalue"];
  412. drNew["GoodsLevelTypeID"] = dsProductionDataByID.Tables[0].Rows[0]["GoodsLevelTypeID"];
  413. drNew["ReFine"] = 0;
  414. drNew["SpecialRepairflag"] = SpecialRepairflag.ToString() == "1" ? 1 : 0;
  415. drNew["UserCode"] = dsProductionDataByID.Tables[0].Rows[0]["UserCode"];
  416. drNew["MouldCode"] = dsProductionDataByID.Tables[0].Rows[0]["MouldCode"];
  417. drNew["GroutingDate"] = Convert.ToDateTime(dsProductionDataByID.Tables[0].Rows[0]["GroutingDate"]);
  418. drNew["GroutingUserCode"] = dsProductionDataByID.Tables[0].Rows[0]["GroutingUserCode"];
  419. drNew["IsPublicBody"] = dsProductionDataByID.Tables[0].Rows[0]["IsPublicBody"].ToString() != "1" ? 0 : 1;
  420. drNew["GroutingNum"] = dsProductionDataByID.Tables[0].Rows[0]["GroutingNum"];
  421. drNew["LogoCodeName"] = dsProductionDataByID.Tables[0].Rows[0]["LogoName"] + "[" + dsProductionDataByID.Tables[0].Rows[0]["LogoCode"] + "]";
  422. drNew["LogoId"] = dsProductionDataByID.Tables[0].Rows[0]["LogoId"];
  423. TableProductionData.Rows.Add(drNew);
  424. this.dgvProductionData.Rows[TableProductionData.Rows.Count - 1].Selected = true;
  425. this._selectedRowIndex = TableProductionData.Rows.Count - 1;
  426. this._currentBarCode = dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString();
  427. this._currentGoodsID = Convert.ToInt32(dsProductionDataByID.Tables[0].Rows[0]["GoodsID"]);
  428. if (DSTable.Tables.IndexOf(dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString()) == -Constant.INT_IS_ONE)
  429. {
  430. DataTable dtProductionDefectData = new DataTable(dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString());
  431. dtProductionDefectData.Columns.Add("BarCode");
  432. dtProductionDefectData.Columns.Add("discarde");
  433. dtProductionDefectData.Columns.Add("DefectID", typeof(decimal));
  434. dtProductionDefectData.Columns.Add("DefectName");
  435. dtProductionDefectData.Columns.Add("DefectCode");
  436. dtProductionDefectData.Columns.Add("DefectPositionID", typeof(decimal));
  437. dtProductionDefectData.Columns.Add("DefectPositionName");
  438. dtProductionDefectData.Columns.Add("DefectPositionCode");
  439. dtProductionDefectData.Columns.Add("DefectProcedureID", typeof(decimal));
  440. dtProductionDefectData.Columns.Add("DefectProcedureName");
  441. dtProductionDefectData.Columns.Add("DefectProcedureCode");
  442. dtProductionDefectData.Columns.Add("DefectUserID", typeof(decimal));//责任员工
  443. dtProductionDefectData.Columns.Add("DefectUserName");//责任员工
  444. dtProductionDefectData.Columns.Add("DefectUserCode");//
  445. dtProductionDefectData.Columns.Add("Jobs", typeof(decimal));//工种
  446. dtProductionDefectData.Columns.Add("JobsText");//工种
  447. dtProductionDefectData.Columns.Add("DefectRemarks");
  448. dtProductionDefectData.Columns.Add("TempCount");
  449. dtProductionDefectData.Columns.Add("ProductionDataID"); //生产数据ID
  450. dtProductionDefectData.Columns.Add("DefectFineID"); //缺陷扣罚ID
  451. dtProductionDefectData.Columns.Add("DefectFineValue"); //缺陷扣罚
  452. dtProductionDefectData.Columns.Add("MissedUserID"); //漏检工号ID
  453. dtProductionDefectData.Columns.Add("MissedUserCode"); //漏检工号编码
  454. dtProductionDefectData.Columns.Add("MissedUserName"); //漏检工号名称
  455. dtProductionDefectData.Columns.Add("IsAllowEdit"); //是否允许编辑 0 不允许,1允许
  456. dtProductionDefectData.Columns.Add("CheckTime"); //缺陷检验时间
  457. DSTable.Tables.Add(dtProductionDefectData);
  458. }
  459. for (int i = 0; i < dsProductionDataByID.Tables[1].Rows.Count; i++)
  460. {
  461. DataRow dr = DSTable.Tables[dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString()].NewRow();
  462. dr["BarCode"] = dsProductionDataByID.Tables[1].Rows[i]["BarCode"];
  463. dr["DefectID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectID"];
  464. dr["DefectName"] = dsProductionDataByID.Tables[1].Rows[i]["DefectName"];
  465. dr["DefectCode"] = dsProductionDataByID.Tables[1].Rows[i]["DefectCode"];
  466. dr["DefectPositionID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectPositionID"];
  467. dr["DefectPositionName"] = dsProductionDataByID.Tables[1].Rows[i]["DefectPositionName"];
  468. dr["DefectPositionCode"] = dsProductionDataByID.Tables[1].Rows[i]["DefectPositionCode"];
  469. dr["DefectProcedureID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectProcedureID"];
  470. dr["DefectProcedureName"] = dsProductionDataByID.Tables[1].Rows[i]["DefectProcedureName"];
  471. dr["DefectProcedureCode"] = dsProductionDataByID.Tables[1].Rows[i]["DefectProcedureCode"];
  472. dr["DefectUserID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectUserID"];
  473. dr["DefectUserName"] = dsProductionDataByID.Tables[1].Rows[i]["DefectUserName"];
  474. dr["DefectUserCode"] = dsProductionDataByID.Tables[1].Rows[i]["DefectUserCode"];
  475. dr["Jobs"] = dsProductionDataByID.Tables[1].Rows[i]["Jobs"];
  476. dr["JobsText"] = dsProductionDataByID.Tables[1].Rows[i]["JobsText"];
  477. dr["DefectRemarks"] = dsProductionDataByID.Tables[1].Rows[i]["DefectRemarks"];
  478. dr["TempCount"] = this._tempCount;
  479. dr["ProductionDataID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectProductionDataID"];// dsProductionDataByID.Tables[1].Rows[i]["ProductionDataID"];
  480. dr["DefectFineID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectFineID"];
  481. dr["DefectFineValue"] = dsProductionDataByID.Tables[1].Rows[i]["DefectFineValue"];
  482. dr["MissedUserID"] = dsProductionDataByID.Tables[1].Rows[i]["MissedUserID"];
  483. dr["MissedUserCode"] = dsProductionDataByID.Tables[1].Rows[i]["MissedUserCode"];
  484. dr["MissedUserName"] = dsProductionDataByID.Tables[1].Rows[i]["MissedUserName"];
  485. dr["IsAllowEdit"] = 1;
  486. dr["CheckTime"] = Convert.ToDateTime(dsProductionDataByID.Tables[1].Rows[i]["CheckTime"]);
  487. DSTable.Tables[dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString()].Rows.Add(dr);
  488. // 防止工种不选择的话,直接New一个
  489. if (!this.DSTableStaff.Tables.Contains(string.Format("TempTable{0}", this._tempCount)))
  490. {
  491. DataTable dtStaff = new DataTable(string.Format("TempTable{0}", this._tempCount));
  492. dtStaff.Columns.Add("IsSelected");
  493. dtStaff.Columns.Add("StaffID");
  494. dtStaff.Columns.Add("StaffCode");
  495. dtStaff.Columns.Add("StaffName");
  496. dtStaff.Columns.Add("StaffTempCount");
  497. dtStaff.Columns.Add("StaffStatus");
  498. this.DSTableStaff.Tables.Add(dtStaff);
  499. }
  500. // 责任员工
  501. DataRow[] drRow = dsProductionDataByID.Tables[2].Select("ProductionDefectID=" + dsProductionDataByID.Tables[1].Rows[i]["ProductionDefectID"]);
  502. if (drRow.Length > Constant.INT_IS_ZERO)
  503. {
  504. foreach (DataRow r in drRow)
  505. {
  506. DataRow drStaff = this.DSTableStaff.Tables[string.Format("TempTable{0}", this._tempCount)].NewRow();
  507. drStaff["IsSelected"] = 1;
  508. drStaff["StaffID"] = r["StaffID"];
  509. drStaff["StaffCode"] = r["StaffCode"];
  510. drStaff["StaffName"] = r["StaffName"];
  511. drStaff["StaffTempCount"] = this._tempCount;
  512. drStaff["StaffStatus"] = r["StaffStatus"];
  513. this.DSTableStaff.Tables[string.Format("TempTable{0}", this._tempCount)].Rows.Add(drStaff);
  514. }
  515. }
  516. // 漏检员工临时表
  517. if (!this.DSTableMissedStaff.Tables.Contains(string.Format("TempTable{0}", this._tempCount)))
  518. {
  519. DataTable dtMissedStaff = new DataTable(string.Format("TempTable{0}", this._tempCount));
  520. dtMissedStaff.Columns.Add("IsSelected");
  521. dtMissedStaff.Columns.Add("StaffID");
  522. dtMissedStaff.Columns.Add("StaffCode");
  523. dtMissedStaff.Columns.Add("StaffName");
  524. dtMissedStaff.Columns.Add("StaffTempCount");
  525. dtMissedStaff.Columns.Add("StaffStatus");
  526. dtMissedStaff.Columns.Add("UJobsID");
  527. dtMissedStaff.Columns.Add("SJobsID");
  528. this.DSTableMissedStaff.Tables.Add(dtMissedStaff);
  529. }
  530. //漏检员工临时表数据
  531. DataRow[] drMissedRow = dsProductionDataByID.Tables[4].Select("ProductionDefectID=" + dsProductionDataByID.Tables[1].Rows[i]["ProductionDefectID"]);
  532. if (drMissedRow.Length > Constant.INT_IS_ZERO)
  533. {
  534. foreach (DataRow r in drMissedRow)
  535. {
  536. DataRow drMissedStaff = this.DSTableMissedStaff.Tables[string.Format("TempTable{0}", this._tempCount)].NewRow();
  537. drMissedStaff["IsSelected"] = 1;
  538. drMissedStaff["StaffID"] = r["StaffID"];
  539. drMissedStaff["StaffCode"] = r["StaffCode"];
  540. drMissedStaff["StaffName"] = r["StaffName"];
  541. drMissedStaff["StaffTempCount"] = this._tempCount;
  542. drMissedStaff["StaffStatus"] = r["StaffStatus"];
  543. drMissedStaff["UJobsID"] = r["UJobsID"];
  544. drMissedStaff["SJobsID"] = r["SJobsID"];
  545. this.DSTableMissedStaff.Tables[string.Format("TempTable{0}", this._tempCount)].Rows.Add(drMissedStaff);
  546. }
  547. }
  548. if (!this.DSTableImage.Tables.Contains(string.Format("TempTable{0}", this._tempCount.ToString())))
  549. {
  550. DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._tempCount.ToString()));
  551. dtImage.Columns.Add("StaffTempCount");
  552. dtImage.Columns.Add("ImageByte", typeof(byte[]));
  553. dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
  554. this.DSTableImage.Tables.Add(dtImage);
  555. }
  556. this._currentTempSign = i.ToString();
  557. // 缺陷图片
  558. DataRow[] drImageRow = dsProductionDataByID.Tables[3].Select("ProductionDefectID=" + dsProductionDataByID.Tables[1].Rows[i]["ProductionDefectID"]);
  559. if (drImageRow.Length > Constant.INT_IS_ZERO)
  560. {
  561. foreach (DataRow r in drImageRow)
  562. {
  563. if (r["SourcePathByte"] != DBNull.Value)
  564. {
  565. byte[] orgImageByte = (byte[])r["SourcePathByte"];
  566. this._PicByte.Add(orgImageByte);
  567. //this._smallByte.Add(orgImageByte);
  568. if (!this.DSTableImage.Tables.Contains(string.Format("TempTable{0}", this._currentTempSign.ToString())))
  569. {
  570. DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._currentTempSign.ToString()));
  571. dtImage.Columns.Add("StaffTempCount");
  572. dtImage.Columns.Add("ImageByte", typeof(byte[]));
  573. dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
  574. this.DSTableImage.Tables.Add(dtImage);
  575. }
  576. DataRow drrow = DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].NewRow();
  577. drrow["StaffTempCount"] = this._currentTempSign;
  578. drrow["ImageByte"] = orgImageByte;
  579. drrow["OrgImageByte"] = orgImageByte;
  580. DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].Rows.Add(drrow);
  581. BindImg();
  582. }
  583. }
  584. }
  585. this._tempCount = this._tempCount + 1;
  586. }
  587. this.dgvDefect.DataSource = DSTable.Tables[dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString()];//根据条码产生不同数据源
  588. }
  589. }
  590. #endregion wangx 2012-12-28 add end
  591. }
  592. catch (Exception ex)
  593. {
  594. // 对异常进行共通处理
  595. ExceptionManager.HandleEventException(this.ToString(),
  596. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  597. }
  598. }
  599. /// <summary>
  600. /// 设置控件禁用或启用
  601. /// </summary>
  602. private void SetControlEnable()
  603. {
  604. if (this._procedureDataEntity != null)
  605. {
  606. if (this._procedureDataEntity.CollectType == (int)Constant.ProcedureCollectType.Togather)
  607. {
  608. this.txtUserCode.Enabled = true;
  609. this.btnSave.Visible = true;
  610. }
  611. else
  612. {
  613. this.txtUserCode.Enabled = true;
  614. this.txtUserCode.ReadOnly = true;
  615. // 此工号是否能生产工序
  616. CheckProcedureUserResult checkProcedureUser = (CheckProcedureUserResult)DoAsync(new BaseAsyncMethod(() =>
  617. {
  618. return PMModuleProxy.Service.CheckProcedureUser(this._procedureID,
  619. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserCode);
  620. }));
  621. if (checkProcedureUser != null)
  622. {
  623. if (!string.IsNullOrEmpty(checkProcedureUser.ErrMsg))
  624. {
  625. // 此工号不允许生产工序
  626. MessageBox.Show(checkProcedureUser.ErrMsg,
  627. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  628. this.Close();
  629. return;
  630. }
  631. }
  632. UserID = checkProcedureUser.UserID;
  633. UserCode = checkProcedureUser.UserCode;
  634. UserName = checkProcedureUser.UserName;
  635. }
  636. this.txtUserCode.Text = UserCode;
  637. }
  638. }
  639. /// <summary>
  640. /// 工号文本离开焦点后事件
  641. /// </summary>
  642. /// <param name="sender"></param>
  643. /// <param name="e"></par
  644. private void txtUserCode_Leave(object sender, EventArgs e)
  645. {
  646. try
  647. {
  648. if (txtUserCode.Text.Trim() == string.Empty) // 如果未添加数据,则此项获取焦点
  649. {
  650. this.txtUserCode.IsMustInput = true;
  651. this.txtUserCode.Focus();
  652. return;
  653. }
  654. else
  655. {
  656. SUserEntity userEntity = new SUserEntity();
  657. userEntity.UserCode = this.txtUserCode.Text.Trim();
  658. // 此工号是否能生产工序
  659. CheckProcedureUserResult MsgCheckProcedureUser = (CheckProcedureUserResult)DoAsync(new BaseAsyncMethod(() =>
  660. {
  661. return PMModuleProxy.Service.CheckProcedureUser(this._procedureID, this.txtUserCode.Text.Trim());
  662. }));
  663. if (MsgCheckProcedureUser != null)
  664. {
  665. if (MsgCheckProcedureUser.ErrMsg != null)
  666. {
  667. MessageBox.Show(MsgCheckProcedureUser.ErrMsg,
  668. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  669. this.txtUserCode.Focus();
  670. return;
  671. }
  672. UserID = Convert.ToInt32(MsgCheckProcedureUser.UserID);
  673. UserCode = MsgCheckProcedureUser.UserCode;
  674. UserName = MsgCheckProcedureUser.UserName;
  675. }
  676. }
  677. }
  678. catch (Exception ex)
  679. {
  680. // 对异常进行共通处理
  681. ExceptionManager.HandleEventException(this.ToString(),
  682. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  683. }
  684. }
  685. /// <summary>
  686. /// 条形码按键事件
  687. /// </summary>
  688. /// <param name="sender"></param>
  689. /// <param name="e"></param>
  690. private void txtBarCode_KeyPress(object sender, KeyPressEventArgs e)
  691. {
  692. try
  693. {
  694. if (this.txtBarCode.ReadOnly)
  695. {
  696. return;
  697. }
  698. if ((int)e.KeyChar == 13) // 按了回车键
  699. {
  700. if (this.txtUserCode.Text.Trim() == string.Empty)
  701. {
  702. this.txtUserCode.Focus();
  703. this.txtBarCode.Text = string.Empty;
  704. return;
  705. }
  706. if (this.txtBarCode.Text.Trim() == string.Empty)
  707. {
  708. this.txtBarCode.Focus();
  709. this.txtBarCode.SelectAll();
  710. return;
  711. }
  712. // 校验条码 获取校验条码信
  713. DataSet dsCheckBarcode = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  714. {
  715. return PMModuleProxy.Service.CheckBarcode(this._procedureID, this.txtBarCode.Text.Trim());
  716. }));
  717. if (dsCheckBarcode != null && dsCheckBarcode.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  718. {
  719. if (dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString() != string.Empty)
  720. {
  721. // 表示有错误
  722. //MessageBox.Show(string.Format(dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString(), this.txtBarCode.Text.Trim(), "产品条码"),
  723. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  724. //this.txtBarCode.Focus();
  725. //return;
  726. if (dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_missFlag.ToString()].ToString() == "0")
  727. {
  728. // 表示有错误
  729. MessageBox.Show(string.Format(dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString(), this.txtBarCode.Text.Trim(), "产品条码"),
  730. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  731. }
  732. else
  733. {
  734. S_CMN_020 frmscmn020 = new S_CMN_020(Convert.ToInt32(dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_missFlag.ToString()])
  735. , dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString());
  736. frmscmn020.ShowDialog();
  737. }
  738. this.txtBarCode.Focus();
  739. this.txtBarCode.SelectAll();
  740. return;
  741. }
  742. else
  743. {
  744. BindProductionData(dsCheckBarcode);
  745. this._currentBarCode = txtBarCode.Text.Trim();
  746. this.txtBarCode.Text = string.Empty;
  747. }
  748. }
  749. }
  750. }
  751. catch (Exception ex)
  752. {
  753. // 对异常进行共通处理
  754. ExceptionManager.HandleEventException(this.ToString(),
  755. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  756. }
  757. }
  758. /// <summary>
  759. /// 生产数据下拉列表改变事件
  760. /// </summary>
  761. /// <param name="sender"></param>
  762. /// <param name="e"></param>
  763. private void dataGridViewComboBox_SelectionChangeCommitted(object sender, EventArgs e)
  764. {
  765. this._currentDefectFlag = Convert.ToInt32(((ComboBox)sender).SelectedValue.ToString());//当前缺陷类型
  766. SetGridView(Convert.ToInt32(((ComboBox)sender).SelectedValue.ToString()));
  767. }
  768. /// <summary>
  769. /// 产品数据单元格进入事件
  770. /// </summary>
  771. /// <param name="sender"></param>
  772. /// <param name="e"></param>
  773. private void dgvProductionData_CellEnter(object sender, DataGridViewCellEventArgs e)
  774. {
  775. try
  776. {
  777. if (this.dgvProductionData.CurrentCell != null)
  778. {
  779. // 记录最后选择行
  780. this._selectedRowIndex = this.dgvProductionData.CurrentCell.RowIndex;
  781. this._currentBarCode = this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString();
  782. this._C_DGV_Cell_ListBoxComboBox = dgvProductionData.Rows[_selectedRowIndex].Cells[4] as C_DGV_Cell_ListBoxComboBox;
  783. DataSet ds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  784. {
  785. return PMModuleProxy.Service.GetReworkProcedureByBarcode(this._procedureID, this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString());
  786. }));
  787. this._currentGoodsID = Convert.ToInt32(this.dgvProductionData.Rows[_selectedRowIndex].Cells["GoodsID"].Value);
  788. this._currentBarCode = this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString();
  789. this._C_DGV_Cell_ListBoxComboBox.DisplayMember = "ReworkProcedureName";
  790. this._C_DGV_Cell_ListBoxComboBox.ValueMember = "ReworkProcedureID";
  791. this._C_DGV_Cell_ListBoxComboBox.DataSource = ds.Tables[0];
  792. }
  793. }
  794. catch (Exception ex)
  795. {
  796. // 对异常进行共通处理
  797. ExceptionManager.HandleEventException(this.ToString(),
  798. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  799. }
  800. }
  801. /// <summary>
  802. /// 产品数据选定项改变事件
  803. /// </summary>
  804. /// <param name="sender"></param>
  805. /// <param name="e"></param>
  806. private void dgvProductionData_SelectionChanged(object sender, EventArgs e)
  807. {
  808. try
  809. {
  810. if (this.dgvProductionData.CurrentCell != null)
  811. {
  812. this._selectedRowIndex = this.dgvProductionData.CurrentCell.RowIndex;
  813. // 有无缺陷 0无缺陷 1有缺陷
  814. this._currentDefectFlag = Convert.ToInt32(this.dgvProductionData.Rows[_selectedRowIndex].Cells["DefectFlag"].Value.ToString());
  815. this._currentGoodsID = Convert.ToInt32(this.dgvProductionData.Rows[_selectedRowIndex].Cells["GoodsID"].Value);
  816. this._currentBarCode = this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString();
  817. this.dgvDefect.DataSource = DSTable.Tables[this._currentBarCode];
  818. this.dgvDefectStaff.CurrentCell = null;
  819. this.dgvDefectStaff.DataSource = null;
  820. this._smallByte.Clear();//防止重复绑定图片
  821. this.lvPic.Clear();//
  822. }
  823. }
  824. catch (Exception ex)
  825. {
  826. // 对异常进行共通处理
  827. ExceptionManager.HandleEventException(this.ToString(),
  828. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  829. }
  830. }
  831. /// <summary>
  832. /// 缺陷数据源选定项改变事件
  833. /// </summary>
  834. /// <param name="sender"></param>
  835. /// <param name="e"></param>
  836. private void dgvDefect_SelectionChanged(object sender, EventArgs e)
  837. {
  838. try
  839. {
  840. if (this.dgvDefect.CurrentCell != null)
  841. {
  842. this.tsbtnEdit.Enabled = true;
  843. if (this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString() != string.Empty)
  844. {
  845. int staffTempCount = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString());
  846. this.dgvDefectStaff.DataSource = DSTableStaff.Tables[string.Format("TempTable{0}", staffTempCount.ToString())];
  847. this._currentTempSign = this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString(); //当前临时标记
  848. this._smallByte.Clear();//防止重复绑定图片
  849. BindByteImage(DSTableImage.Tables[string.Format("TempTable{0}", staffTempCount.ToString())]);
  850. }
  851. else
  852. {
  853. this.dgvDefectStaff.DataSource = null;
  854. this._smallByte.Clear();//防止重复绑定图片
  855. this.lvPic.Clear();//
  856. }
  857. }
  858. }
  859. catch (Exception ex)
  860. {
  861. // 对异常进行共通处理
  862. ExceptionManager.HandleEventException(this.ToString(),
  863. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  864. }
  865. }
  866. /// <summary>
  867. /// 单元格CheckBox事件
  868. /// </summary>
  869. /// <param name="sender"></param>
  870. /// <param name="e"></param>
  871. private void dgvDefect_CellContentClick(object sender, DataGridViewCellEventArgs e)
  872. {
  873. if (e.ColumnIndex == Constant.INT_IS_ZERO && e.RowIndex != -Constant.INT_IS_ONE)
  874. {
  875. int checkValue = Convert.ToInt32(this.dgvDefect.Rows[e.RowIndex].Cells[0].EditedFormattedValue);
  876. if (checkValue == Constant.INT_IS_ZERO)
  877. {
  878. SetCheckBoxSelected(checkValue, e.RowIndex);
  879. }
  880. else
  881. {
  882. this.dgvDefect.Rows[e.RowIndex].Cells[0].Value = 0;
  883. }
  884. }
  885. }
  886. /// <summary>
  887. /// 上传图片按钮事件
  888. /// </summary>
  889. /// <param name="sender"></param>
  890. /// <param name="e"></param>
  891. private void btnUpload_Click(object sender, EventArgs e)
  892. {
  893. try
  894. {
  895. this.odlgFile.Filter = Constant.FILTER_PIC;
  896. this.odlgFile.FilterIndex = Constant.INT_IS_ZERO;
  897. this.odlgFile.RestoreDirectory = true;
  898. this.odlgFile.Title = "选择缺陷图片";
  899. this.odlgFile.FileName = null;
  900. this.odlgFile.RestoreDirectory = true;
  901. if (this.odlgFile.ShowDialog() == DialogResult.OK)
  902. {
  903. FileInfo file = new FileInfo(odlgFile.FileName);
  904. if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
  905. {
  906. MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "缺陷图片", "大小", "1M"),
  907. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  908. }
  909. else
  910. {
  911. Image PicImage = Image.FromStream(file.OpenRead());
  912. byte[] orgImageByte = ImageToByte(PicImage);
  913. this._PicByte.Add(orgImageByte);
  914. GetThumbnail(file, orgImageByte);
  915. BindImg();
  916. }
  917. }
  918. }
  919. catch (Exception ex)
  920. {
  921. // 对异常进行共通处理
  922. ExceptionManager.HandleEventException(this.ToString(),
  923. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  924. }
  925. }
  926. /// <summary>
  927. /// 删除图片按钮事件
  928. /// </summary>
  929. /// <param name="sender"></param>
  930. /// <param name="e"></param>
  931. private void btnDelete_Click(object sender, EventArgs e)
  932. {
  933. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  934. {
  935. int index = lvSelect.Index;
  936. if (index < Constant.INT_IS_ZERO)
  937. {
  938. index = Constant.INT_IS_ZERO;
  939. }
  940. if (this._currentTempSign != string.Empty)
  941. {
  942. DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].Rows.RemoveAt(lvSelect.Index);
  943. DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].AcceptChanges();
  944. }
  945. BindByteImage(DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)]);
  946. }
  947. }
  948. /// <summary>
  949. /// 关闭按钮事件
  950. /// </summary>
  951. /// <param name="sender"></param>
  952. /// <param name="e"></param>
  953. private void tsbtnClose_Click(object sender, EventArgs e)
  954. {
  955. this.Close();
  956. }
  957. /// <summary>
  958. /// 产品条码列表删除事件
  959. /// </summary>
  960. /// <param name="sender"></param>
  961. /// <param name="e"></param>
  962. private void dgvProductionData_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  963. {
  964. try
  965. {
  966. string BarCode = this.dgvProductionData.Rows[e.Row.Index].Cells["BarCode"].Value.ToString();
  967. DSTable.Tables[BarCode].Rows.Clear();//清空行
  968. this.dgvDefectStaff.DataSource = null;
  969. this.lvPic.Clear();
  970. }
  971. catch (Exception ex)
  972. {
  973. throw ex;
  974. }
  975. }
  976. /// <summary>
  977. /// 产品缺陷删除行事件
  978. /// </summary>
  979. /// <param name="sender"></param>
  980. /// <param name="e"></param>
  981. private void dgvDefect_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  982. {
  983. try
  984. {
  985. string TempCount = this.dgvDefect.Rows[e.Row.Index].Cells["TempCount"].Value.ToString();
  986. DSTableStaff.Tables[string.Format("TempTable{0}", TempCount.ToString())].Rows.Clear();//清空行
  987. this.dgvDefectStaff.DataSource = null;
  988. this.lvPic.Clear();
  989. }
  990. catch (Exception ex)
  991. {
  992. throw ex;
  993. }
  994. }
  995. /// <summary>
  996. /// 新建按钮事件
  997. /// </summary>
  998. /// <param name="sender"></param>
  999. /// <param name="e"></param>
  1000. private void tsbtnAdd_Click(object sender, EventArgs e)
  1001. {
  1002. if (this.TableProductionData.Rows.Count > Constant.INT_IS_ZERO)
  1003. {
  1004. if (this._procedureDataEntity.NodeType != Constant.INT_IS_ONE)
  1005. {
  1006. F_PM_0904 frm0904 = new F_PM_0904(
  1007. DSTable.Tables[this._currentBarCode], this._currentBarCode,
  1008. this._currentGoodsID, this._tempCount, this._procedureID, this.Text, false, this, this.DSTableStaff, this.DSTableImage, this._PicByte, this._smallByte, -1);
  1009. frm0904.ShowDialog();
  1010. }
  1011. else
  1012. {
  1013. F_PM_0905 frm0904 = new F_PM_0905(
  1014. DSTable.Tables[this._currentBarCode], this._currentBarCode,
  1015. this._currentGoodsID, this._tempCount, this._procedureID, this.Text, false, this, this.DSTableStaff, this.DSTableImage, this._PicByte, this._smallByte, -1);
  1016. frm0904.ShowDialog();
  1017. }
  1018. }
  1019. }
  1020. /// <summary>
  1021. /// 编辑按钮事件
  1022. /// </summary>
  1023. /// <param name="sender"></param>
  1024. /// <param name="e"></param>
  1025. private void tsbtnEdit_Click(object sender, EventArgs e)
  1026. {
  1027. if (this.dgvDefect.CurrentCell != null)
  1028. {
  1029. string barcode = this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["ProductionBarCode"].Value.ToString();
  1030. int tempcount = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString());
  1031. int goodsID = 0;
  1032. DataRow[] dr = this.TableProductionData.Select("BarCode='" + barcode + "'");
  1033. if (dr.Length > Constant.INT_IS_ZERO)
  1034. {
  1035. goodsID = Convert.ToInt32(dr[0]["GoodsID"]);
  1036. }
  1037. if (this._procedureDataEntity.NodeType != Constant.INT_IS_ONE)
  1038. {
  1039. F_PM_0904 frm0904 = new F_PM_0904(
  1040. DSTable.Tables[barcode], barcode,
  1041. goodsID, tempcount, this._procedureID, this.Text, true, this, this.DSTableStaff, this.DSTableImage, this._PicByte, this._smallByte, this.dgvDefect.CurrentCell.RowIndex);
  1042. frm0904.ShowDialog();
  1043. }
  1044. else
  1045. {
  1046. F_PM_0905 frm0904 = new F_PM_0905(
  1047. DSTable.Tables[this._currentBarCode], this._currentBarCode,
  1048. goodsID, tempcount, this._procedureID, this.Text, true, this, this.DSTableStaff, this.DSTableImage, this._PicByte, this._smallByte, this.dgvDefect.CurrentCell.RowIndex);
  1049. frm0904.ShowDialog();
  1050. }
  1051. }
  1052. }
  1053. /// <summary>
  1054. /// 保存按钮事件
  1055. /// </summary>
  1056. /// <param name="sender"></param>
  1057. /// <param name="e"></param>
  1058. private void btnSave_Click(object sender, EventArgs e)
  1059. {
  1060. try
  1061. {
  1062. ProductionDataEntity[] productionDataEntitys = new ProductionDataEntity[this.TableProductionData.Rows.Count];
  1063. bool isError = false; // 是否存在缺陷员工
  1064. int ErrorNumber = -1;//错误编码
  1065. for (int i = 0; i < this.TableProductionData.Rows.Count; i++)
  1066. {
  1067. ProductionDataEntity productionDataEntity = new ProductionDataEntity();
  1068. productionDataEntity.ProductionDataID = this._productionDataID == null ? 0 : Convert.ToInt32(this._productionDataID);
  1069. productionDataEntity.Barcode = this.TableProductionData.Rows[i]["BarCode"].ToString();
  1070. productionDataEntity.UserID = UserID;
  1071. productionDataEntity.UserCode = UserCode;
  1072. productionDataEntity.UserName = UserName;
  1073. if (this.DSTable.Tables[productionDataEntity.Barcode].Rows.Count == 0)
  1074. {
  1075. productionDataEntity.DefectFlag = Constant.GoodsLevelType.NoDefects.GetHashCode();
  1076. productionDataEntity.GoodsLevelTypeID = Constant.GoodsLevelType.NoDefects.GetHashCode();
  1077. }
  1078. else
  1079. {
  1080. productionDataEntity.DefectFlag = Constant.GoodsLevelType.Defect.GetHashCode();
  1081. DataRow[] drSelected = this.DSTable.Tables[productionDataEntity.Barcode].Select("discarde=1");
  1082. if (drSelected.Length == 0)
  1083. {
  1084. productionDataEntity.GoodsLevelTypeID = Constant.GoodsLevelType.Defect.GetHashCode();
  1085. }
  1086. else
  1087. {
  1088. productionDataEntity.GoodsLevelTypeID = Constant.GoodsLevelType.Waste.GetHashCode();//废品
  1089. }
  1090. if (this._dsGoodsLevel != null)
  1091. {
  1092. DataRow[] dr = this._dsGoodsLevel.Tables[0].Select("GoodsLevelTypeID=" + productionDataEntity.GoodsLevelTypeID);
  1093. if (dr.Length > 0)
  1094. {
  1095. productionDataEntity.GoodsLevelID = Convert.ToInt32(dr[0]["DefectFlagID"]);
  1096. }
  1097. }
  1098. }
  1099. productionDataEntity.Remarks = this.TableProductionData.Rows[i]["Remarks"].ToString();
  1100. if (this.TableProductionData.Rows[i]["LogoID"].ToString()!="")
  1101. {
  1102. productionDataEntity.LogoID = Convert.ToInt32(this.TableProductionData.Rows[i]["LogoID"]);
  1103. }
  1104. productionDataEntitys[i] = productionDataEntity;
  1105. List<ProductionDefectEntity> productionDefectEntitys = new List<ProductionDefectEntity>();
  1106. ProductionDefectEntity productionDefectEntity = null;
  1107. for (int j = 0; j < this.DSTable.Tables[productionDataEntity.Barcode].Rows.Count; j++) //缺陷列表
  1108. {
  1109. productionDefectEntity = new ProductionDefectEntity();
  1110. productionDefectEntity.ScrapFlag = Convert.ToBoolean(
  1111. Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["discarde"].ToString() == "" ? 0 : this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["discarde"]));
  1112. productionDefectEntity.ScrapResponFlag =
  1113. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["discarde"].ToString();
  1114. productionDefectEntity.DefectID =
  1115. Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectID"]);
  1116. productionDefectEntity.DefectCode =
  1117. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectCode"].ToString();
  1118. //productionDefectEntity.DefectName =
  1119. // this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectName"].ToString();
  1120. productionDefectEntity.DefectName =
  1121. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectName"].ToString().Replace(productionDefectEntity.DefectCode + "->", "");
  1122. productionDefectEntity.DefectPositionID =
  1123. Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectPositionID"]);
  1124. productionDefectEntity.DefectPositionCode =
  1125. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectPositionCode"].ToString();
  1126. //productionDefectEntity.DefectPositionName =
  1127. // this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectPositionName"].ToString();
  1128. productionDefectEntity.DefectPositionName =
  1129. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectPositionName"].ToString().Replace(productionDefectEntity.DefectPositionCode + "->", "");
  1130. if (this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectFineID"].ToString() != "-1"
  1131. && this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectFineID"].ToString() != string.Empty)
  1132. {
  1133. productionDefectEntity.DefectFine = Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectFineID"]);
  1134. }
  1135. if (this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["CheckTime"].ToString() != string.Empty)
  1136. {
  1137. productionDefectEntity.CheckTime = Convert.ToDateTime(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["CheckTime"]);
  1138. }
  1139. if (this._procedureDataEntity.NodeType != 1)
  1140. {
  1141. productionDefectEntity.DefectProductionDataID =
  1142. Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["ProductionDataID"].ToString());
  1143. productionDefectEntity.DefectProcedureID =
  1144. Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectProcedureID"]);
  1145. productionDefectEntity.DefectProcedureCode =
  1146. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectProcedureCode"].ToString();
  1147. productionDefectEntity.DefectProcedureName =
  1148. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectProcedureName"].ToString();
  1149. productionDefectEntity.DefectUserID =
  1150. Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectUserID"]);
  1151. productionDefectEntity.DefectUserCode =
  1152. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectUserCode"].ToString();
  1153. productionDefectEntity.DefectUserName =
  1154. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectUserName"].ToString();
  1155. productionDefectEntity.DefectJobs =
  1156. Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["Jobs"].ToString());
  1157. productionDefectEntity.Remarks =
  1158. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectRemarks"].ToString();
  1159. }
  1160. // 遍历责任员工
  1161. List<DefectResponsibleEntity> DefectResponsibles = new List<DefectResponsibleEntity>();
  1162. if (this.DSTableStaff.Tables.Contains(string.Format("TempTable{0}",
  1163. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())))
  1164. {
  1165. DefectResponsibleEntity defectResponsibleEntity = null;
  1166. DataTable dtTemp = this.DSTableStaff.Tables[string.Format("TempTable{0}",
  1167. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())];
  1168. foreach (DataRow drStaff in dtTemp.Rows)
  1169. {
  1170. if (Convert.ToInt32(drStaff["IsSelected"]) == 1)
  1171. {
  1172. defectResponsibleEntity = new DefectResponsibleEntity();
  1173. defectResponsibleEntity.StaffID = Convert.ToInt32(drStaff["StaffID"]);
  1174. defectResponsibleEntity.UserID = Convert.ToInt32(productionDefectEntity.DefectUserID);
  1175. defectResponsibleEntity.UserCode = productionDefectEntity.DefectUserCode;
  1176. defectResponsibleEntity.UJobsID =
  1177. Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["Jobs"].ToString());
  1178. defectResponsibleEntity.SJobsID = Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["Jobs"].ToString());
  1179. defectResponsibleEntity.StaffStatus = Convert.ToInt32(drStaff["StaffStatus"]);
  1180. DefectResponsibles.Add(defectResponsibleEntity);
  1181. }
  1182. }
  1183. //productionDefectEntity.DefectResponsibles = DefectResponsibles.ToArray();//每个缺陷对应的责任员工
  1184. productionDefectEntity.DefectResponsibles = DefectResponsibles;//每个缺陷对应的责任员工
  1185. }
  1186. if (this._procedureDataEntity.NodeType != 1) // 不是开始工序,不能没有责任员工
  1187. {
  1188. if (DefectResponsibles.Count == 0) // 并没有责任员工
  1189. {
  1190. isError = true;
  1191. this.dgvDefect.DataSource = this.DSTable.Tables[productionDataEntity.Barcode];
  1192. this.dgvDefect.CurrentCell = null;
  1193. this.dgvDefect.Rows[j].Selected = true;
  1194. if (this.DSTableStaff.Tables.Contains(string.Format("TempTable{0}",
  1195. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())))
  1196. {
  1197. this.dgvDefectStaff.DataSource = this.DSTableStaff.Tables[string.Format("TempTable{0}",
  1198. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())];
  1199. }
  1200. else
  1201. {
  1202. this.dgvDefectStaff.DataSource = null;
  1203. }
  1204. break;
  1205. }
  1206. }
  1207. // 遍历缺陷图片
  1208. if (this.DSTableImage.Tables.Contains(string.Format("TempTable{0}",
  1209. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())))
  1210. {
  1211. List<DefectImageEntity> defectImageEntitys = new List<DefectImageEntity>();
  1212. DefectImageEntity defectImageEntity = null;
  1213. DataTable dtTemp = this.DSTableImage.Tables[string.Format("TempTable{0}",
  1214. this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())];
  1215. foreach (DataRow drImage in dtTemp.Rows)
  1216. {
  1217. defectImageEntity = new DefectImageEntity();
  1218. defectImageEntity.Thumbnail = (byte[])drImage["ImageByte"];
  1219. defectImageEntity.Image = (byte[])drImage["orgImageByte"];
  1220. defectImageEntitys.Add(defectImageEntity);
  1221. }
  1222. //productionDefectEntity.DefectImages = defectImageEntitys.ToArray();
  1223. productionDefectEntity.DefectImages = defectImageEntitys;
  1224. }
  1225. productionDefectEntitys.Add(productionDefectEntity);
  1226. }
  1227. if (isError)
  1228. {
  1229. break;
  1230. }
  1231. //productionDataEntitys[i].ProductionDefects = productionDefectEntitys.ToArray();
  1232. productionDataEntitys[i].ProductionDefects = productionDefectEntitys;
  1233. }
  1234. if (isError && ErrorNumber == -Constant.INT_IS_ONE)
  1235. {
  1236. // 提示信息
  1237. MessageBox.Show(Messages.MSG_PM_W002,
  1238. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1239. return;
  1240. }
  1241. else if (isError && ErrorNumber == -Constant.INT_IS_TWO)
  1242. {
  1243. // 提示信息
  1244. MessageBox.Show(Messages.MSG_PM_W013,
  1245. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1246. return;
  1247. }
  1248. if (productionDataEntitys.Length > Constant.INT_IS_ZERO)
  1249. {
  1250. //// 最外层For循环结束
  1251. string returnValue = (string)DoAsync(new BaseAsyncMethod(() =>
  1252. {
  1253. return PMModuleProxy.Service.AddCheckBarcode(this._procedureID, productionDataEntitys);
  1254. }));
  1255. if (string.IsNullOrEmpty(returnValue))//成功
  1256. {
  1257. // 提示信息
  1258. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新建" + this.Text, "保存"),
  1259. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  1260. this.TableProductionData.Rows.Clear();
  1261. this.dgvProductionData.DataSource = TableProductionData;
  1262. for (int table = 0; table < DSTable.Tables.Count; table++)
  1263. {
  1264. this.DSTable.Tables.Remove(DSTable.Tables[table].TableName);
  1265. }
  1266. this.DSTable.AcceptChanges();
  1267. this.dgvDefect.DataSource = null;
  1268. this.DSTableStaff.Tables.Clear();
  1269. this.dgvDefectStaff.DataSource = null;
  1270. this.DSTableImage.Tables.Clear();
  1271. this.lvPic.Clear();
  1272. this._PicByte.Clear();
  1273. this._smallByte.Clear();
  1274. if (this._procedureDataEntity.CollectType == (int)Constant.ProcedureCollectType.Togather)
  1275. {
  1276. this.txtUserCode.Text = string.Empty;
  1277. this.txtUserCode.ReadOnly = false;
  1278. }
  1279. this.DSREWORK.Tables.Clear();
  1280. }
  1281. else
  1282. {
  1283. // 提示信息
  1284. MessageBox.Show(returnValue,
  1285. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1286. }
  1287. }
  1288. }
  1289. catch (Exception ex)
  1290. {
  1291. // 对异常进行共通处理
  1292. ExceptionManager.HandleEventException(this.ToString(),
  1293. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1294. }
  1295. }
  1296. /// <summary>
  1297. /// 关闭按钮事件
  1298. /// </summary>
  1299. /// <param name="sender"></param>
  1300. /// <param name="e"></param>
  1301. private void tsbCloseTop_Click(object sender, EventArgs e)
  1302. {
  1303. this.Close();
  1304. }
  1305. /// <summary>
  1306. /// 用户编码验证事件
  1307. /// </summary>
  1308. /// <param name="sender"></param>
  1309. /// <param name="e"></param>
  1310. private void txtUserCode_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  1311. {
  1312. try
  1313. {
  1314. if (txtUserCode.Text.Trim() == string.Empty) // 如果未添加数据,则此项获取焦点
  1315. {
  1316. this.txtUserCode.IsMustInput = true;
  1317. this.txtUserCode.SelectAll();
  1318. e.Cancel = true;
  1319. return;
  1320. }
  1321. else if (!this.txtUserCode.ReadOnly)
  1322. {
  1323. SUserEntity userEntity = new SUserEntity();
  1324. userEntity.UserCode = this.txtUserCode.Text.Trim();
  1325. // 此工号是否能生产工序
  1326. CheckProcedureUserResult MsgCheckProcedureUser = (CheckProcedureUserResult)DoAsync(new BaseAsyncMethod(() =>
  1327. {
  1328. return PMModuleProxy.Service.CheckProcedureUser(this._procedureID, this.txtUserCode.Text.Trim());
  1329. }));
  1330. if (MsgCheckProcedureUser != null)
  1331. {
  1332. if (MsgCheckProcedureUser.ErrMsg != null)
  1333. {
  1334. MessageBox.Show(MsgCheckProcedureUser.ErrMsg,
  1335. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  1336. this.txtUserCode.SelectAll();
  1337. e.Cancel = true;
  1338. return;
  1339. }
  1340. UserID = Convert.ToInt32(MsgCheckProcedureUser.UserID);
  1341. UserCode = MsgCheckProcedureUser.UserCode;
  1342. UserName = MsgCheckProcedureUser.UserName;
  1343. this.txtUserCode.ReadOnly = true;
  1344. }
  1345. }
  1346. }
  1347. catch (Exception ex)
  1348. {
  1349. // 对异常进行共通处理
  1350. ExceptionManager.HandleEventException(this.ToString(),
  1351. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1352. }
  1353. }
  1354. /// <summary>
  1355. /// 取消按钮事件
  1356. /// </summary>
  1357. /// <param name="sender"></param>
  1358. /// <param name="e"></param>
  1359. private void btnCancel_Click(object sender, EventArgs e)
  1360. {
  1361. this.Close();
  1362. }
  1363. /// <summary>
  1364. /// 鼠标单击事件
  1365. /// </summary>
  1366. /// <param name="sender"></param>
  1367. /// <param name="e"></param>
  1368. private void txtUserCode_MouseClick(object sender, MouseEventArgs e)
  1369. {
  1370. if (this.txtUserCode.Text.Trim() != string.Empty)
  1371. {
  1372. this.txtUserCode.SelectAll();
  1373. }
  1374. }
  1375. #endregion
  1376. #region 私有方法
  1377. /// <summary>
  1378. /// 设置数据源
  1379. /// </summary>
  1380. /// <param name="tempCount"></param>
  1381. public void SetDataSource(int tempCount)
  1382. {
  1383. this.dgvDefect.DataSource = DSTable.Tables[this._currentBarCode];
  1384. this.dgvDefectStaff.DataSource = DSTableStaff.Tables[string.Format("TempTable{0}", this._tempCount.ToString())];
  1385. this._tempCount = tempCount;
  1386. }
  1387. /// <summary>
  1388. /// 绑定到第一个DataGriwView数据源
  1389. /// </summary>
  1390. private void BindProductionData(DataSet dsCheckBarcode)
  1391. {
  1392. try
  1393. {
  1394. DataRow[] dr = TableProductionData.Select("BarCode='" + this.txtBarCode.Text.Trim() + "'");
  1395. if (dr.Length > Constant.INT_IS_ZERO)
  1396. {
  1397. // 不允许重复添加
  1398. return;
  1399. }
  1400. DataRow drNew = TableProductionData.NewRow();
  1401. drNew["BarCode"] = this.txtBarCode.Text.Trim();
  1402. drNew["GoodsID"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_goodsID.ToString()];
  1403. drNew["GoodsCode"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_goodsCode.ToString()];
  1404. drNew["GoodsName"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_goodsName.ToString()];
  1405. drNew["DefectFlagID"] = Constant.GoodsLevelType.NoDefects;
  1406. drNew["ReworkProcedureID"] = DBNull.Value;
  1407. drNew["Remarks"] = "";
  1408. drNew["UserID"] = UserID;
  1409. drNew["GoodsLevelTypeID"] = DBNull.Value;
  1410. drNew["UserCode"] = this.txtUserCode.Text.Trim();
  1411. string KilnCarCode = string.Empty;
  1412. string KilnCode = string.Empty;
  1413. string Dictionaryvalue = string.Empty;
  1414. DataSet dsKilnCar = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1415. {
  1416. return PMModuleProxy.Service.GetKilnCarByBarCode(txtBarCode.Text.Trim());
  1417. }));
  1418. if (dsKilnCar != null && dsKilnCar.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  1419. {
  1420. KilnCarCode = dsKilnCar.Tables[0].Rows[0]["KilnCarCode"].ToString();
  1421. KilnCode = dsKilnCar.Tables[0].Rows[0]["KilnCode"].ToString();
  1422. Dictionaryvalue = dsKilnCar.Tables[0].Rows[0]["Dictionaryvalue"].ToString();
  1423. }
  1424. drNew["KilnCarCode"] = KilnCarCode;
  1425. drNew["KilnCode"] = KilnCode;
  1426. drNew["Dictionaryvalue"] = Dictionaryvalue;
  1427. // 由产品条码获取注浆信息
  1428. //DataSet dsGroutingProduct = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1429. //{
  1430. // return PMModuleProxy.Service.GetGroutingProducttByBarCode(txtBarCode.Text.Trim());
  1431. //}));
  1432. drNew["MouldCode"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_mouldCode.ToString()];
  1433. drNew["GroutingUserCode"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_groutingUserCode.ToString()];
  1434. drNew["GroutingNum"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_groutingNum.ToString()];
  1435. drNew["GroutingDate"] = Convert.ToDateTime(dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_groutingdate.ToString()]);
  1436. drNew["LogoCodeName"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_logoName.ToString()]
  1437. + "[" + dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_logoCode.ToString()] + "]";
  1438. drNew["LogoID"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_logoID.ToString()];
  1439. TableProductionData.Rows.Add(drNew);
  1440. if (DSTable.Tables.IndexOf(this.txtBarCode.Text.Trim()) == -1)
  1441. {
  1442. DataTable dtProductionDefectData = new DataTable(this.txtBarCode.Text.Trim());
  1443. dtProductionDefectData.Columns.Add("BarCode");
  1444. dtProductionDefectData.Columns.Add("discarde");
  1445. dtProductionDefectData.Columns.Add("DefectID", typeof(decimal));
  1446. dtProductionDefectData.Columns.Add("DefectName");
  1447. dtProductionDefectData.Columns.Add("DefectCode");
  1448. dtProductionDefectData.Columns.Add("DefectPositionID", typeof(decimal));
  1449. dtProductionDefectData.Columns.Add("DefectPositionName");
  1450. dtProductionDefectData.Columns.Add("DefectPositionCode");
  1451. dtProductionDefectData.Columns.Add("DefectProcedureID", typeof(decimal));
  1452. dtProductionDefectData.Columns.Add("DefectProcedureName");
  1453. dtProductionDefectData.Columns.Add("DefectProcedureCode");
  1454. dtProductionDefectData.Columns.Add("DefectUserID", typeof(decimal));//责任员工
  1455. dtProductionDefectData.Columns.Add("DefectUserName");//责任员工
  1456. dtProductionDefectData.Columns.Add("DefectUserCode");//
  1457. dtProductionDefectData.Columns.Add("Jobs", typeof(decimal));//工种
  1458. dtProductionDefectData.Columns.Add("JobsText");//工种
  1459. dtProductionDefectData.Columns.Add("DefectRemarks");
  1460. dtProductionDefectData.Columns.Add("TempCount");
  1461. dtProductionDefectData.Columns.Add("ProductionDataID"); //生产数据ID
  1462. dtProductionDefectData.Columns.Add("DefectFineID"); //缺席扣罚ID
  1463. dtProductionDefectData.Columns.Add("DefectFineValue"); //缺席扣罚
  1464. dtProductionDefectData.Columns.Add("CheckTime"); //缺陷检验时间
  1465. DSTable.Tables.Add(dtProductionDefectData);
  1466. }
  1467. this.dgvDefect.DataSource = DSTable.Tables[this.txtBarCode.Text.Trim()];//根据条码产生不同数据源
  1468. this.dgvProductionData.CurrentCell = null;
  1469. this.dgvProductionData.Rows[TableProductionData.Rows.Count - 1].Selected = true;
  1470. this.dgvDefect.DataSource = null;
  1471. this.dgvDefectStaff.DataSource = null;
  1472. this.lvPic.Clear();
  1473. // 添加一个产品条码时除了第一个显示在数据表中,其它的全部清空
  1474. this.tsbtnAdd.Enabled = true;//添加完条码后,可以新建其它信息
  1475. this._selectedRowIndex = TableProductionData.Rows.Count - 1;
  1476. //DataSet ds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  1477. //{
  1478. // return PMModuleProxy.Service.GetReworkProcedureByBarcode(this._procedureID, this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString());
  1479. //}));
  1480. //ds.Tables[0].TableName = this.txtBarCode.Text.Trim();
  1481. //if (this.DSREWORK == null)
  1482. //{
  1483. // this.DSREWORK = new DataSet();
  1484. //}
  1485. //this.DSREWORK.Tables.Add(ds.Tables[0].Copy());
  1486. //C_DGV_Cell_ListBoxComboBox C_DGV_Cell_ListBoxComboBox = dgvProductionData.Rows[_selectedRowIndex].Cells[4] as C_DGV_Cell_ListBoxComboBox;
  1487. //C_DGV_Cell_ListBoxComboBox.DataSource = ds.Tables[0];
  1488. //C_DGV_Cell_ListBoxComboBox.DisplayMember = "ReworkProcedureName";
  1489. //C_DGV_Cell_ListBoxComboBox.ValueMember = "ReworkProcedureID";
  1490. }
  1491. catch (Exception ex)
  1492. {
  1493. throw ex;
  1494. }
  1495. }
  1496. /// <summary>
  1497. /// 通过是否有缺陷来启用或禁用
  1498. /// </summary>
  1499. /// <param name="GoodsLevelID"></param>
  1500. private void SetGridView(int GoodsLevelID)
  1501. {
  1502. DataTable dtDefectFlag = this.DefectFlag.DataSource as DataTable;//获取缺陷数据源
  1503. int GoodsLevelTypeID = -1;
  1504. DataRow[] dr = dtDefectFlag.Select("DefectFlagID=" + GoodsLevelID);
  1505. if (dr.Length > 0)
  1506. {
  1507. GoodsLevelTypeID = Convert.ToInt32(dr[0]["GoodsLevelTypeID"]);
  1508. this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["GoodsLevelTypeID"].Value = GoodsLevelTypeID;
  1509. }
  1510. if (GoodsLevelTypeID != -1)
  1511. {
  1512. if (GoodsLevelTypeID == (int)Constant.GoodsLevelType.NoDefects) //没有缺陷
  1513. {
  1514. try
  1515. {
  1516. this.dgvDefect.ReadOnly = true;
  1517. this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureID"].Value = null;
  1518. this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureCode"].Value = string.Empty;
  1519. this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureName"].Value = string.Empty;
  1520. this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureID"].ReadOnly = true;
  1521. string BarCode = this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["BarCode"].Value.ToString();
  1522. if (DSTable.Tables.Contains(BarCode))
  1523. {
  1524. DSTable.Tables[BarCode].Rows.Clear();//清空行
  1525. }
  1526. this.dgvDefectStaff.DataSource = null;
  1527. this.lvPic.Clear();
  1528. }
  1529. catch (Exception ex)
  1530. {
  1531. throw ex;
  1532. }
  1533. }
  1534. else if (GoodsLevelTypeID == (int)Constant.GoodsLevelType.Defect) //有缺陷
  1535. {
  1536. this.dgvDefect.ReadOnly = true;
  1537. this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureID"].ReadOnly = false;
  1538. }
  1539. else if (GoodsLevelTypeID == (int)Constant.GoodsLevelType.Waste) //废品
  1540. {
  1541. this.dgvDefect.ReadOnly = false;
  1542. }
  1543. }
  1544. }
  1545. /// <summary>
  1546. /// 清空以前所选中的缺陷
  1547. /// </summary>
  1548. /// <param name="checkValue"></param>
  1549. private void SetCheckBoxSelected(int checkValue, int rowIndex)
  1550. {
  1551. DataTable dtOrgDataSource = this.dgvDefect.DataSource as DataTable;
  1552. for (int i = 0; i < DSTable.Tables[dtOrgDataSource.TableName].Rows.Count; i++)
  1553. {
  1554. if (i == rowIndex)
  1555. {
  1556. dtOrgDataSource.Rows[i]["discarde"] = 1;
  1557. }
  1558. else
  1559. {
  1560. dtOrgDataSource.Rows[i]["discarde"] = 0;
  1561. }
  1562. }
  1563. }
  1564. /// <summary>
  1565. /// 绑定并显示图片
  1566. /// </summary>
  1567. /// <param name="ImageData"></param>
  1568. public void BindByteImage(DataTable ImageData)
  1569. {
  1570. this._smallByte.Clear();
  1571. foreach (DataRow dr in ImageData.Rows)
  1572. {
  1573. //将数据库中的缩略图取出
  1574. this._smallByte.Add((byte[])dr[1]);
  1575. }
  1576. //绑定缩略图
  1577. BindImg();
  1578. }
  1579. /// <summary>
  1580. /// 将图片文件转换成二进制
  1581. /// </summary>
  1582. /// <param name="img"></param>
  1583. /// <returns></returns>
  1584. public static byte[] ImageToByte(Image img)
  1585. {
  1586. byte[] smallbuffer = null;
  1587. using (MemoryStream ms = new MemoryStream())
  1588. {
  1589. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1590. ms.Position = Constant.INT_IS_ZERO;
  1591. smallbuffer = new byte[ms.Length];
  1592. ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
  1593. ms.Flush();
  1594. }
  1595. return smallbuffer;
  1596. }
  1597. /// <SUMMARY>
  1598. /// 重绘缩略图并把缩略图转为二进制储存
  1599. /// </SUMMARY>
  1600. /// <PARAM name="sourceFile">图片源路径</PARAM>
  1601. /// <PARAM name="destHeight">缩放后图片高度</PARAM>
  1602. /// <PARAM name="destWidth">缩放后图片宽度</PARAM>
  1603. /// <RETURNS></RETURNS>
  1604. public void GetThumbnail(FileInfo sourceFile, byte[] orgImageByte)
  1605. {
  1606. Image imgSource = Image.FromStream(sourceFile.OpenRead());
  1607. ImageFormat thisFormat = imgSource.RawFormat;
  1608. int sW = 0, sH = 0;
  1609. // 按比例缩放
  1610. int sWidth = imgSource.Width;
  1611. int sHeight = imgSource.Height;
  1612. int destWidth = 100;
  1613. int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
  1614. if (sHeight > destHeight || sWidth > destWidth)
  1615. {
  1616. if ((sWidth * destHeight) > (sHeight * destWidth))
  1617. {
  1618. sW = destWidth;
  1619. sH = (destWidth * sHeight) / sWidth;
  1620. }
  1621. else
  1622. {
  1623. sH = destHeight;
  1624. sW = (sWidth * destHeight) / sHeight;
  1625. }
  1626. }
  1627. else
  1628. {
  1629. sW = sWidth;
  1630. sH = sHeight;
  1631. }
  1632. Bitmap outBmp = new Bitmap(destWidth, destHeight);
  1633. Graphics g = Graphics.FromImage(outBmp);
  1634. g.Clear(Color.Black);
  1635. // 设置画布的描绘质量
  1636. g.CompositingQuality = CompositingQuality.HighQuality;
  1637. g.SmoothingMode = SmoothingMode.HighQuality;
  1638. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  1639. g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
  1640. g.Dispose();
  1641. //将重绘的图片转为二进制并保存
  1642. Image image = (Image)outBmp;
  1643. byte[] smallbuffer = ImageToByte(image);
  1644. if (this._currentTempSign != string.Empty)
  1645. {
  1646. if (!this.DSTableImage.Tables.Contains(string.Format("TempTable{0}", this._currentTempSign.ToString())))
  1647. {
  1648. DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._currentTempSign.ToString()));
  1649. dtImage.Columns.Add("StaffTempCount");
  1650. dtImage.Columns.Add("ImageByte", typeof(byte[]));
  1651. dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
  1652. this.DSTableImage.Tables.Add(dtImage);
  1653. }
  1654. DataRow dr = DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].NewRow();
  1655. dr["StaffTempCount"] = this._currentTempSign;
  1656. dr["ImageByte"] = smallbuffer;
  1657. dr["OrgImageByte"] = orgImageByte;
  1658. DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].Rows.Add(dr);
  1659. }
  1660. this._smallByte.Add(smallbuffer);
  1661. imgSource.Dispose();
  1662. outBmp.Dispose();
  1663. }
  1664. /// <summary>
  1665. /// 根据原图片宽高比获取缩略图的高(根据宽)
  1666. /// </summary>
  1667. /// <param name="BigWidth"></param>
  1668. /// <param name="BigHeight"></param>
  1669. /// <param name="SmallWidth"></param>
  1670. /// <returns></returns>
  1671. protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
  1672. {
  1673. decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
  1674. return Convert.ToInt32(SmallWidth / scale);
  1675. }
  1676. /// <summary>
  1677. /// 绑定缩略图到控件中
  1678. /// </summary>
  1679. protected void BindImg()
  1680. {
  1681. ImageList ilPic = new ImageList();
  1682. //每次绑定要清空数据源
  1683. ilPic.Images.Clear();
  1684. //将缩略图二进制集合中的数据转换成图片文件
  1685. List<Image> LSImageList = new List<Image>();
  1686. foreach (byte[] smallby in this._smallByte)
  1687. {
  1688. LSImageList.Add(byteArrayToImage(smallby));
  1689. }
  1690. //添加数据源
  1691. foreach (Image img in LSImageList)
  1692. {
  1693. ilPic.Images.Add(img);
  1694. }
  1695. ilPic.ImageSize = new Size(100, 100);
  1696. this.lvPic.LargeImageList = ilPic;
  1697. this.lvPic.BeginUpdate();
  1698. //清空列表的数据源
  1699. lvPic.Items.Clear();
  1700. //添加列表的数据源
  1701. for (int i = 0; i < ilPic.Images.Count; i++)
  1702. {
  1703. ListViewItem lvi = new ListViewItem();
  1704. lvi.ImageIndex = i;
  1705. this.lvPic.Items.Add(lvi);
  1706. }
  1707. this.lvPic.EndUpdate();
  1708. }
  1709. /// <summary>
  1710. /// 将数据库中的二进制转换成图片
  1711. /// </summary>
  1712. /// <param name="data"></param>
  1713. /// <returns></returns>
  1714. public static Image byteArrayToImage(object data)
  1715. {
  1716. System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
  1717. System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
  1718. return returnImage;
  1719. }
  1720. #endregion
  1721. }
  1722. }