F_PM_0905.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_0905.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_0905 : 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_0905()
  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_0905(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_0905_Load(object sender, EventArgs e)
  122. {
  123. DataSet dsDefectByProcedure = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  124. {
  125. return PMModuleProxy.Service.GetDefectByProcedure(this._procedureID);
  126. }));
  127. if (dsDefectByProcedure != null && dsDefectByProcedure.Tables.Count > Constant.INT_IS_ZERO
  128. && dsDefectByProcedure.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  129. {
  130. this.dropDuty.DisplayMember = "DEFECTFLAGNAME";
  131. this.dropDuty.ValueMember = "DEFECTFLAGID";
  132. this.dropDuty.DataSource = dsDefectByProcedure.Tables[0];
  133. }
  134. else
  135. {
  136. this.dropDuty.DisplayMember = "DEFECTFLAGNAME";
  137. this.dropDuty.ValueMember = "DEFECTFLAGID";
  138. this.dropDuty.DataSource = GetDuty();
  139. }
  140. // 缺陷位置
  141. DataSet dsDefectLocation = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  142. {
  143. return PMModuleProxy.Service.GetDefectLocaionByGoodsID(this._goodsID);
  144. }));
  145. this.dropDefectLocation.DisplayMember = "DEFECTPOSITIONCODEANDNAME";
  146. this.dropDefectLocation.ValueMember = "DEFECTPOSITIONID";
  147. this.dropDefectLocation.DataSource = dsDefectLocation.Tables[0];
  148. //// 缺陷扣罚
  149. //DataSet dsDefectFine = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  150. //{
  151. // return SystemModuleProxy.Service.GetDictionaryData(0, "ASE002");
  152. //}));
  153. //DataRow dr = dsDefectFine.Tables[0].NewRow();
  154. //dr["DictionaryID"] = -1;
  155. //dr["DictionaryValue"] = "";
  156. //dsDefectFine.Tables[0].Rows.InsertAt(dr, 0);
  157. //dsDefectFine.Tables[0].AcceptChanges();
  158. //this.cmbDefectFine.DisplayMember = "DictionaryValue";
  159. //this.cmbDefectFine.ValueMember = "DictionaryID";
  160. //this.cmbDefectFine.DataSource = dsDefectFine.Tables[0];
  161. DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  162. {
  163. return SystemModuleProxy.Service.GetAllDefectFine();
  164. }));
  165. if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
  166. {
  167. DataView dv = dsResultAccount.Tables[0].DefaultView;
  168. dv.RowFilter = "valueflag=1";
  169. this.cmbDefectFine.DisplayMember = "DefectFineCode";
  170. this.cmbDefectFine.ValueMember = "DefectFineID";
  171. DataTable dtNew = dv.ToTable();
  172. DataRow dr = dtNew.NewRow();
  173. dr["DefectFineID"] = -1;
  174. dr["DefectFineCode"] = "";
  175. dtNew.Rows.InsertAt(dr, 0);
  176. dtNew.AcceptChanges();
  177. this.cmbDefectFine.DisplayMember = "DefectFineCode";
  178. this.cmbDefectFine.ValueMember = "DefectFineID";
  179. this.cmbDefectFine.DataSource = dtNew;
  180. }
  181. if (this._isEdit)
  182. {
  183. this.dropDuty.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectID"].ToString();
  184. this._currentDutyCode = this._dtBarCode.Rows[this._rowIndex]["DefectCode"].ToString();
  185. // 缺陷位置
  186. this.dropDefectLocation.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectPositionID"].ToString();
  187. this._currentDefectPositionCode = this._dtBarCode.Rows[this._rowIndex]["DefectPositionCode"].ToString();
  188. this.txtRemarks.Text = this._dtBarCode.Rows[this._rowIndex]["DefectRemarks"].ToString();
  189. BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount.ToString())]);
  190. if (this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString() != "-1")
  191. {
  192. this.cmbDefectFine.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString();
  193. }
  194. }
  195. }
  196. /// <summary>
  197. /// 缺陷验证事件
  198. /// </summary>
  199. /// <param name="sender"></param>
  200. /// <param name="e"></param>
  201. private void dropDuty_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  202. {
  203. if (this.dropDuty.SelectedValue.ToString() != string.Empty)
  204. {
  205. string DutyValue = this.dropDuty.SelectedValue.ToString();
  206. DataTable dtDuty = this.dropDuty.DataSource as DataTable;
  207. if (dtDuty.Rows.Count > Constant.INT_IS_ZERO)
  208. {
  209. DataRow[] dr = dtDuty.Select("DefectFlagID=" + DutyValue);
  210. if (dr.Length > Constant.INT_IS_ZERO)
  211. {
  212. this._currentDutyCode = dr[0]["DefectCode"].ToString();
  213. }
  214. }
  215. }
  216. }
  217. /// <summary>
  218. /// 保存按钮事件
  219. /// </summary>
  220. /// <param name="sender"></param>
  221. /// <param name="e"></param>
  222. private void btnSave_Click(object sender, EventArgs e)
  223. {
  224. if (this.dropDuty.SelectedValue == null || this.dropDuty.SelectedValue.ToString() == string.Empty)
  225. {
  226. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷"),
  227. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  228. return;
  229. }
  230. if (this.dropDefectLocation.SelectedValue == null || this.dropDefectLocation.SelectedValue.ToString() == string.Empty)
  231. {
  232. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷位置"),
  233. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  234. return;
  235. }
  236. if (!this._isEdit)
  237. {
  238. // 每次添加不能重复
  239. if (this._dtBarCode != null && this._dtBarCode.Rows.Count > Constant.INT_IS_ZERO)
  240. {
  241. DataRow[] drExist = this._dtBarCode.Select(
  242. string.Format("DefectID={0} and DefectPositionID={1}",
  243. this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue,
  244. this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue
  245. )
  246. );
  247. if (drExist.Length > Constant.INT_IS_ZERO)
  248. {
  249. // 提示信息
  250. MessageBox.Show(Messages.MSG_PM_W001,
  251. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  252. return;
  253. }
  254. }
  255. DataRow dr = this._dtBarCode.NewRow();
  256. dr["BarCode"] = this._dtBarCode;
  257. dr["discarde"] = 0;
  258. dr["DefectID"] = this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue;
  259. dr["DefectName"] = this.dropDuty.Text;
  260. dr["DefectCode"] = this._currentDutyCode;
  261. dr["DefectPositionID"] = this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue;
  262. dr["DefectPositionName"] = this.dropDefectLocation.Text;
  263. dr["DefectPositionCode"] = this._currentDefectPositionCode;
  264. dr["DefectProcedureID"] = DBNull.Value;
  265. dr["DefectProcedureName"] = DBNull.Value;
  266. dr["DefectProcedureCode"] = DBNull.Value;
  267. dr["DefectUserID"] = DBNull.Value;
  268. dr["DefectUserName"] = DBNull.Value;
  269. dr["DefectUserCode"] = DBNull.Value;
  270. dr["Jobs"] = DBNull.Value;
  271. dr["JobsText"] = DBNull.Value;
  272. dr["DefectRemarks"] = this.txtRemarks.Text;
  273. dr["TempCount"] = this._tempcount;
  274. dr["ProductionDataID"] = this._productionDataID;
  275. if (this.cmbDefectFine.SelectedValue != null && this.cmbDefectFine.SelectedValue.ToString() != "-1")
  276. {
  277. dr["DefectFineID"] = this.cmbDefectFine.SelectedValue;
  278. dr["DefectFineValue"] = this.cmbDefectFine.Text; ;
  279. }
  280. else
  281. {
  282. dr["DefectFineID"] = -1;
  283. dr["DefectFineValue"] = string.Empty;
  284. }
  285. this._dtBarCode.Rows.Add(dr);
  286. }
  287. else
  288. {
  289. if (this._dtBarCode != null && this._dtBarCode.Rows.Count > Constant.INT_IS_ZERO)
  290. {
  291. int currentRowIndex = -1; // 用来匹配是否编辑自己
  292. for (int i = 0; i < this._dtBarCode.Rows.Count; i++)
  293. {
  294. if (Convert.ToInt32(this._dtBarCode.Rows[i]["DefectID"]) ==
  295. (this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : Convert.ToInt32(this.dropDuty.SelectedValue))
  296. &&
  297. Convert.ToInt32(this._dtBarCode.Rows[i]["DefectPositionID"]) ==
  298. (this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : Convert.ToInt32(this.dropDefectLocation.SelectedValue))
  299. )
  300. {
  301. currentRowIndex = i;
  302. break;
  303. }
  304. }
  305. if (currentRowIndex != -Constant.INT_IS_ONE && currentRowIndex != this._rowIndex) // 更新后会有重复
  306. {
  307. // 提示信息
  308. MessageBox.Show(Messages.MSG_PM_W001,
  309. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  310. return;
  311. }
  312. }
  313. this._dtBarCode.Rows[this._rowIndex]["BarCode"] = this._dtBarCode;
  314. this._dtBarCode.Rows[this._rowIndex]["discarde"] = 0;
  315. this._dtBarCode.Rows[this._rowIndex]["DefectID"] = this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue;
  316. this._dtBarCode.Rows[this._rowIndex]["DefectName"] = this.dropDuty.Text;
  317. this._dtBarCode.Rows[this._rowIndex]["DefectCode"] = this._currentDutyCode;
  318. this._dtBarCode.Rows[this._rowIndex]["DefectPositionID"] = this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue;
  319. this._dtBarCode.Rows[this._rowIndex]["DefectPositionName"] = this.dropDefectLocation.Text;
  320. this._dtBarCode.Rows[this._rowIndex]["DefectPositionCode"] = this._currentDefectPositionCode;
  321. this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"] = DBNull.Value;
  322. this._dtBarCode.Rows[this._rowIndex]["DefectProcedureName"] = DBNull.Value;
  323. this._dtBarCode.Rows[this._rowIndex]["DefectProcedureCode"] = DBNull.Value;
  324. this._dtBarCode.Rows[this._rowIndex]["DefectUserID"] = DBNull.Value;
  325. this._dtBarCode.Rows[this._rowIndex]["DefectUserName"] = DBNull.Value;
  326. this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"] = DBNull.Value;
  327. this._dtBarCode.Rows[this._rowIndex]["Jobs"] = DBNull.Value;
  328. this._dtBarCode.Rows[this._rowIndex]["JobsText"] = DBNull.Value;
  329. this._dtBarCode.Rows[this._rowIndex]["DefectRemarks"] = this.txtRemarks.Text;
  330. this._dtBarCode.Rows[this._rowIndex]["TempCount"] = this._tempcount;
  331. this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"] = this._productionDataID;
  332. if (this.cmbDefectFine.SelectedValue != null && this.cmbDefectFine.SelectedValue.ToString() != "-1")
  333. {
  334. this._dtBarCode.Rows[this._rowIndex]["DefectFineID"] = this.cmbDefectFine.SelectedValue;
  335. this._dtBarCode.Rows[this._rowIndex]["DefectFineValue"] = this.cmbDefectFine.Text; ;
  336. }
  337. else
  338. {
  339. this._dtBarCode.Rows[this._rowIndex]["DefectFineID"] = -1;
  340. this._dtBarCode.Rows[this._rowIndex]["DefectFineValue"] = string.Empty;
  341. }
  342. this._dtBarCode.AcceptChanges();
  343. }
  344. // 防止工种不选择的话,直接New一个
  345. if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", _tempcount.ToString())))
  346. {
  347. DataTable dtStaff = new DataTable(string.Format("TempTable{0}", _tempcount.ToString()));
  348. dtStaff.Columns.Add("IsSelected");
  349. dtStaff.Columns.Add("StaffID");
  350. dtStaff.Columns.Add("StaffCode");
  351. dtStaff.Columns.Add("StaffName");
  352. dtStaff.Columns.Add("StaffTempCount");
  353. dtStaff.Columns.Add("StaffStatus");
  354. dtStaff.Columns.Add("Jobs");
  355. this._dsStaff.Tables.Add(dtStaff);
  356. }
  357. if (!this._dsImage.Tables.Contains(string.Format("TempTable{0}", this._tempcount.ToString())))
  358. {
  359. DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._tempcount.ToString()));
  360. dtImage.Columns.Add("StaffTempCount");
  361. dtImage.Columns.Add("ImageByte", typeof(byte[]));
  362. dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
  363. this._dsImage.Tables.Add(dtImage);
  364. }
  365. this._frm0903.BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", _tempcount.ToString())]);
  366. this._tempcount = _tempcount + 1;
  367. this._frm0903.SetDataSource(_tempcount);
  368. ClearText();
  369. if (this._isEdit)
  370. {
  371. // 保存后如果是编辑进来的,更改后可以继续录入,当前改为插入了
  372. this._isEdit = false;
  373. }
  374. }
  375. /// <summary>
  376. /// 上传图片按钮事件
  377. /// </summary>
  378. /// <param name="sender"></param>
  379. /// <param name="e"></param>
  380. private void btnUpload_Click(object sender, EventArgs e)
  381. {
  382. try
  383. {
  384. if (!this._dsImage.Tables.Contains(string.Format("TempTable{0}", this._tempcount.ToString())))
  385. {
  386. DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._tempcount.ToString()));
  387. dtImage.Columns.Add("StaffTempCount");
  388. dtImage.Columns.Add("ImageByte", typeof(byte[]));
  389. dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
  390. this._dsImage.Tables.Add(dtImage);
  391. }
  392. this.odlgFile.Filter = Constant.FILTER_PIC;
  393. this.odlgFile.FilterIndex = Constant.INT_IS_ZERO;
  394. this.odlgFile.RestoreDirectory = true;
  395. this.odlgFile.Title = "选择缺陷图片";
  396. this.odlgFile.FileName = null;
  397. this.odlgFile.RestoreDirectory = true;
  398. if (this.odlgFile.ShowDialog() == DialogResult.OK)
  399. {
  400. FileInfo file = new FileInfo(odlgFile.FileName);
  401. if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
  402. {
  403. MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "缺陷图片", "大小", "1M"),
  404. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  405. }
  406. else
  407. {
  408. Image PicImage = Image.FromStream(file.OpenRead());
  409. byte[] orgImageByte = ImageToByte(PicImage);
  410. this._PicByte.Add(orgImageByte);
  411. GetThumbnail(file, orgImageByte);
  412. BindImg();
  413. }
  414. }
  415. }
  416. catch (Exception ex)
  417. {
  418. // 对异常进行共通处理
  419. ExceptionManager.HandleEventException(this.ToString(),
  420. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  421. }
  422. }
  423. /// <summary>
  424. /// 删除图片按钮事件
  425. /// </summary>
  426. /// <param name="sender"></param>
  427. /// <param name="e"></param>
  428. private void btnDelete_Click(object sender, EventArgs e)
  429. {
  430. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  431. {
  432. int index = lvSelect.Index;
  433. if (index < Constant.INT_IS_ZERO)
  434. {
  435. index = Constant.INT_IS_ZERO;
  436. }
  437. this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].Rows.RemoveAt(lvSelect.Index);
  438. this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].AcceptChanges();
  439. this._frm0903.BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)]);
  440. this.BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)]);
  441. }
  442. }
  443. /// <summary>
  444. /// 缺陷位置验证事件
  445. /// </summary>
  446. /// <param name="sender"></param>
  447. /// <param name="e"></param>
  448. private void dropDefectLocation_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  449. {
  450. if (this.dropDefectLocation.SelectedValue != null && this.dropDefectLocation.SelectedValue.ToString() != string.Empty)
  451. {
  452. string DefectLocationCode = this.dropDefectLocation.SelectedValue.ToString();
  453. DataTable dtDefectLocationCode = this.dropDefectLocation.DataSource as DataTable;
  454. if (dtDefectLocationCode.Rows.Count > Constant.INT_IS_ZERO)
  455. {
  456. DataRow[] dr = dtDefectLocationCode.Select("DefectPositionID=" + DefectLocationCode);
  457. if (dr.Length > Constant.INT_IS_ZERO)
  458. {
  459. this._currentDefectPositionCode = dr[0]["DefectPositionCode"].ToString();
  460. }
  461. }
  462. }
  463. }
  464. #endregion
  465. #region 私有方法
  466. /// <summary>
  467. /// 获取缺陷
  468. /// </summary>
  469. /// <returns></returns>
  470. private DataTable GetDuty()
  471. {
  472. DataTable dtDuty = new DataTable();
  473. dtDuty.Columns.Add("DEFECTFLAGNAME");
  474. dtDuty.Columns.Add("DEFECTFLAGID");
  475. return dtDuty;
  476. }
  477. /// <summary>
  478. /// 责任工序数据表
  479. /// </summary>
  480. /// <returns></returns>
  481. private DataTable GetDutyProcedure()
  482. {
  483. DataTable dtDutyProcedure = new DataTable();
  484. dtDutyProcedure.Columns.Add("DutyProcedureName");
  485. dtDutyProcedure.Columns.Add("DutyProcedureID");
  486. return dtDutyProcedure;
  487. }
  488. /// <summary>
  489. /// 责任工号数据表
  490. /// </summary>
  491. /// <returns></returns>
  492. private DataTable GetDutyProcedureUser()
  493. {
  494. DataTable dtDutyProcedureUser = new DataTable();
  495. dtDutyProcedureUser.Columns.Add("UserCode");
  496. dtDutyProcedureUser.Columns.Add("UserID");
  497. return dtDutyProcedureUser;
  498. }
  499. /// <summary>
  500. /// 责任工种数据表
  501. /// </summary>
  502. /// <returns></returns>
  503. private DataTable GetDutyProcedureJobs()
  504. {
  505. DataTable dtDutyProcedureJobs = new DataTable();
  506. dtDutyProcedureJobs.Columns.Add("JobsName");
  507. dtDutyProcedureJobs.Columns.Add("Jobs");
  508. return dtDutyProcedureJobs;
  509. }
  510. /// <summary>
  511. /// 获取缺陷扣罚
  512. /// </summary>
  513. /// <returns></returns>
  514. private DataTable GetDefectFine()
  515. {
  516. DataTable dtDefectFine = new DataTable();
  517. dtDefectFine.Columns.Add("DictionaryValue");
  518. dtDefectFine.Columns.Add("DictionaryID");
  519. return dtDefectFine;
  520. }
  521. /// <summary>
  522. /// 保存后界面数据初始化
  523. /// </summary>
  524. private void ClearText()
  525. {
  526. this.dropDuty.SelectedValue = string.Empty;
  527. this.dropDuty.Text = string.Empty;
  528. this.dropDefectLocation.SelectedValue = string.Empty;
  529. this.dropDefectLocation.Text = string.Empty;
  530. this.txtRemarks.Text = string.Empty;
  531. this._smallByte.Clear();
  532. this.lvPic.Clear();
  533. this.cmbDefectFine.SelectedValue = -1;
  534. }
  535. /// <summary>
  536. /// 将图片文件转换成二进制
  537. /// </summary>
  538. /// <param name="img"></param>
  539. /// <returns></returns>
  540. public static byte[] ImageToByte(Image img)
  541. {
  542. byte[] smallbuffer = null;
  543. using (MemoryStream ms = new MemoryStream())
  544. {
  545. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  546. ms.Position = Constant.INT_IS_ZERO;
  547. smallbuffer = new byte[ms.Length];
  548. ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
  549. ms.Flush();
  550. }
  551. return smallbuffer;
  552. }
  553. /// <SUMMARY>
  554. /// 重绘缩略图并把缩略图转为二进制储存
  555. /// </SUMMARY>
  556. /// <PARAM name="sourceFile">图片源路径</PARAM>
  557. /// <PARAM name="destHeight">缩放后图片高度</PARAM>
  558. /// <PARAM name="destWidth">缩放后图片宽度</PARAM>
  559. /// <RETURNS></RETURNS>
  560. public void GetThumbnail(FileInfo sourceFile, byte[] orgImageByte)
  561. {
  562. Image imgSource = Image.FromStream(sourceFile.OpenRead());
  563. ImageFormat thisFormat = imgSource.RawFormat;
  564. int sW = 0, sH = 0;
  565. // 按比例缩放
  566. int sWidth = imgSource.Width;
  567. int sHeight = imgSource.Height;
  568. int destWidth = 100;
  569. int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
  570. if (sHeight > destHeight || sWidth > destWidth)
  571. {
  572. if ((sWidth * destHeight) > (sHeight * destWidth))
  573. {
  574. sW = destWidth;
  575. sH = (destWidth * sHeight) / sWidth;
  576. }
  577. else
  578. {
  579. sH = destHeight;
  580. sW = (sWidth * destHeight) / sHeight;
  581. }
  582. }
  583. else
  584. {
  585. sW = sWidth;
  586. sH = sHeight;
  587. }
  588. Bitmap outBmp = new Bitmap(destWidth, destHeight);
  589. Graphics g = Graphics.FromImage(outBmp);
  590. g.Clear(Color.Black);
  591. // 设置画布的描绘质量
  592. g.CompositingQuality = CompositingQuality.HighQuality;
  593. g.SmoothingMode = SmoothingMode.HighQuality;
  594. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  595. g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
  596. g.Dispose();
  597. //将重绘的图片转为二进制并保存
  598. Image image = (Image)outBmp;
  599. byte[] smallbuffer = ImageToByte(image);
  600. DataRow dr = this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].NewRow();
  601. dr["StaffTempCount"] = this._tempcount;
  602. dr["ImageByte"] = smallbuffer;
  603. dr["OrgImageByte"] = orgImageByte;
  604. this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].Rows.Add(dr);
  605. _smallByte.Add(smallbuffer);
  606. imgSource.Dispose();
  607. outBmp.Dispose();
  608. }
  609. /// <summary>
  610. /// 根据原图片宽高比获取缩略图的高(根据宽)
  611. /// </summary>
  612. /// <param name="BigWidth"></param>
  613. /// <param name="BigHeight"></param>
  614. /// <param name="SmallWidth"></param>
  615. /// <returns></returns>
  616. protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
  617. {
  618. decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
  619. return Convert.ToInt32(SmallWidth / scale);
  620. }
  621. /// <summary>
  622. /// 绑定缩略图到控件中
  623. /// </summary>
  624. protected void BindImg()
  625. {
  626. ImageList ilPic = new ImageList();
  627. //每次绑定要清空数据源
  628. ilPic.Images.Clear();
  629. //将缩略图二进制集合中的数据转换成图片文件
  630. List<Image> LSImageList = new List<Image>();
  631. foreach (byte[] smallby in _smallByte)
  632. {
  633. LSImageList.Add(byteArrayToImage(smallby));
  634. }
  635. //添加数据源
  636. foreach (Image img in LSImageList)
  637. {
  638. ilPic.Images.Add(img);
  639. }
  640. ilPic.ImageSize = new Size(100, 100);
  641. this.lvPic.LargeImageList = ilPic;
  642. this.lvPic.BeginUpdate();
  643. //清空列表的数据源
  644. lvPic.Items.Clear();
  645. //添加列表的数据源
  646. for (int i = 0; i < ilPic.Images.Count; i++)
  647. {
  648. ListViewItem lvi = new ListViewItem();
  649. lvi.ImageIndex = i;
  650. this.lvPic.Items.Add(lvi);
  651. }
  652. this.lvPic.EndUpdate();
  653. }
  654. /// <summary>
  655. /// 将数据库中的二进制转换成图片
  656. /// </summary>
  657. /// <param name="data"></param>
  658. /// <returns></returns>
  659. public static Image byteArrayToImage(object data)
  660. {
  661. System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
  662. System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
  663. return returnImage;
  664. }
  665. /// <summary>
  666. /// 绑定并显示图片
  667. /// </summary>
  668. /// <param name="ImageData"></param>
  669. private void BindByteImage(DataTable ImageData)
  670. {
  671. this._smallByte.Clear();
  672. foreach (DataRow dr in ImageData.Rows)
  673. {
  674. //将数据库中的缩略图取出
  675. this._smallByte.Add((byte[])dr[1]);
  676. }
  677. //绑定缩略图
  678. BindImg();
  679. }
  680. #endregion
  681. }
  682. }