F_PM_1303.cs 49 KB

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