F_PM_0904.cs 48 KB

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