F_PM_0902.cs 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_PM_0901.cs
  5. * 2.功能描述:工序检验
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2014/09/28 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.Basics.Library;
  21. using Dongke.IBOSS.PRD.Client.CommonModule;
  22. using Dongke.IBOSS.PRD.WCF.DataModels;
  23. using Dongke.IBOSS.PRD.WCF.Proxys;
  24. using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
  25. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  26. namespace Dongke.IBOSS.PRD.Client.PMModule
  27. {
  28. /// <summary>
  29. /// 工序检验一览
  30. /// </summary>
  31. public partial class F_PM_0902 : FormBase
  32. {
  33. #region 成员变量
  34. // 工序ID
  35. private int _procedureID;
  36. // 生产工号
  37. private int _userID = -1;
  38. // 生产编号
  39. private string _userCode;
  40. // 生产名称
  41. private string _userName;
  42. // 工序实体类
  43. ProcedureEntity _procedureDataEntity;
  44. // 产品数据表
  45. DataTable _dtProductionData = null;
  46. // 产品缺陷数据表
  47. DataTable _dtProductionDefectData = null;
  48. // 当前选择的行
  49. private int _selectedRowIndex;
  50. // ComBoxEditingControl
  51. private DataGridViewComboBoxEditingControl _dataGridViewComboBox = null;
  52. // 当前产品条码的产品ID,用来查询缺陷位置
  53. private int _currentGoodsID = 0;
  54. // 当前产品条码,用来切换筛选列表数据
  55. private string _currentBarCode = "";
  56. // 返工工序搜索列表对象
  57. C_DGV_Cell_ListBoxComboBox _C_DGV_Cell_ListBoxComboBox = null;
  58. // 过滤结果集
  59. private DataSet _ds = null;
  60. // 过滤员工结果集
  61. private DataSet _dsStaff = null;
  62. // 过滤缺陷图片
  63. private DataSet _dsImage = null;
  64. // 临时数,用来过滤责任员工数据源标识
  65. private int _tempCount = 0;
  66. // 当前临时标记
  67. private string _currentTempSign = "";
  68. // 图片字节集
  69. private List<byte[]> _PicByte = new List<byte[]>();
  70. // 缩略图片字节集
  71. private List<byte[]> _smallByte = new List<byte[]>();
  72. #endregion
  73. #region 属性
  74. /// <summary>
  75. /// 生产工号
  76. /// </summary>
  77. public int UserID
  78. {
  79. set
  80. {
  81. _userID = value;
  82. }
  83. get
  84. {
  85. return _userID;
  86. }
  87. }
  88. /// <summary>
  89. /// 生产编号
  90. /// </summary>
  91. public string UserCode
  92. {
  93. set
  94. {
  95. _userCode = value;
  96. }
  97. get
  98. {
  99. return _userCode;
  100. }
  101. }
  102. /// <summary>
  103. /// 用户名称
  104. /// </summary>
  105. public string UserName
  106. {
  107. set
  108. {
  109. _userName = value;
  110. }
  111. get
  112. {
  113. return _userName;
  114. }
  115. }
  116. /// <summary>
  117. /// 产品数据表
  118. /// </summary>
  119. public DataTable TableProductionData
  120. {
  121. set
  122. {
  123. _dtProductionData = value;
  124. }
  125. get
  126. {
  127. if (_dtProductionData == null)
  128. {
  129. _dtProductionData = new DataTable("ProductionData");
  130. _dtProductionData.Columns.Add("BarCode");
  131. _dtProductionData.Columns.Add("GoodsID");
  132. _dtProductionData.Columns.Add("GoodsCode");
  133. _dtProductionData.Columns.Add("GoodsName");
  134. _dtProductionData.Columns.Add("DefectFlagID");
  135. _dtProductionData.Columns.Add("ReworkProcedureID");
  136. _dtProductionData.Columns.Add("Remarks");
  137. _dtProductionData.Columns.Add("UserID");
  138. return _dtProductionData;
  139. }
  140. else
  141. {
  142. return _dtProductionData;
  143. }
  144. }
  145. }
  146. /// <summary>
  147. /// 产品缺陷表
  148. /// </summary>
  149. public DataTable TableProductionDefectData
  150. {
  151. set
  152. {
  153. _dtProductionDefectData = value;
  154. }
  155. get
  156. {
  157. if (_dtProductionDefectData == null)
  158. {
  159. _dtProductionDefectData = new DataTable("ProductionDefectData");
  160. _dtProductionDefectData.Columns.Add("ProductionBarCode");
  161. _dtProductionDefectData.Columns.Add("discarde");
  162. _dtProductionDefectData.Columns.Add("DefectFlag", typeof(decimal));
  163. _dtProductionDefectData.Columns.Add("DefectLocation", typeof(decimal));
  164. _dtProductionDefectData.Columns.Add("DutyProcedureUserID", typeof(decimal));
  165. _dtProductionDefectData.Columns.Add("DutyUserCode");
  166. _dtProductionDefectData.Columns.Add("DefectRemarks");
  167. return _dtProductionDefectData;
  168. }
  169. else
  170. {
  171. return _dtProductionDefectData;
  172. }
  173. }
  174. }
  175. /// <summary>
  176. /// 缺陷数据集
  177. /// </summary>
  178. public DataSet DSTable
  179. {
  180. set
  181. {
  182. _ds = value;
  183. }
  184. get
  185. {
  186. if (_ds == null)
  187. {
  188. _ds = new DataSet();
  189. return _ds;
  190. }
  191. else
  192. {
  193. return _ds;
  194. }
  195. }
  196. }
  197. /// <summary>
  198. /// 员工数据集
  199. /// </summary>
  200. public DataSet DSTableStaff
  201. {
  202. set
  203. {
  204. _dsStaff = value;
  205. }
  206. get
  207. {
  208. if (_dsStaff == null)
  209. {
  210. _dsStaff = new DataSet();
  211. return _dsStaff;
  212. }
  213. else
  214. {
  215. return _dsStaff;
  216. }
  217. }
  218. }
  219. /// <summary>
  220. /// 缺陷图片
  221. /// </summary>
  222. public DataSet DSTableImage
  223. {
  224. set
  225. {
  226. _dsImage = value;
  227. }
  228. get
  229. {
  230. if (_dsImage == null)
  231. {
  232. _dsImage = new DataSet();
  233. return _dsImage;
  234. }
  235. else
  236. {
  237. return _dsImage;
  238. }
  239. }
  240. }
  241. #endregion
  242. #region 构造函数
  243. public F_PM_0902()
  244. {
  245. InitializeComponent();
  246. }
  247. public F_PM_0902(int procedureID, string fromTitle)
  248. {
  249. InitializeComponent();
  250. this._procedureID = procedureID;
  251. this.Text = fromTitle;
  252. //this.tsbtnDelete.Text = Constant.BUTTON_TEXT_DELETE;
  253. //自动适应列宽
  254. //this.tsbtnAdaptive.Text = Constant.TOOLBAR_BUTTON_TEXT_AUTOCOLUMNWIDTH;
  255. //关闭
  256. //this.tsbtnClose.Text = Constant.TOOLBAR_BUTTON_TEXT_CLOSE;
  257. //this.btnSave.Text = Constant.BUTTON_TEXT_SAVE;
  258. //this.btnCancel.Text = Constant.BUTTON_TEXT_CANCEL;
  259. }
  260. #endregion
  261. #region 事件
  262. /// <summary>
  263. /// 窗体加载事件
  264. /// </summary>
  265. /// <param name="sender"></param>
  266. /// <param name="e"></param>
  267. private void F_PM_0901_Load(object sender, System.EventArgs e)
  268. {
  269. try
  270. {
  271. this.dgvProductionData.AutoGenerateColumns = false;
  272. this.dgvProductionData.DataSource = TableProductionData;
  273. this.dgvDefect.AutoGenerateColumns = false;
  274. this.dgvDefectStaff.AutoGenerateColumns = false;
  275. // 加载权限
  276. FormPermissionManager.FormPermissionControl(this.Name, this,
  277. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  278. Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  279. // 获取工序明细数据
  280. ProcedureEntity procedureDataEntity = (ProcedureEntity)DoAsync(new BaseAsyncMethod(() =>
  281. {
  282. return PMModuleProxy.Service.GetProcedureDataEntityByID(this._procedureID);
  283. }));
  284. this._procedureDataEntity = procedureDataEntity;
  285. DataSet dsDefectByProcedure = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  286. {
  287. return PMModuleProxy.Service.GetDefectByProcedure(this._procedureID);
  288. }));
  289. if (dsDefectByProcedure != null && dsDefectByProcedure.Tables.Count > 0
  290. && dsDefectByProcedure.Tables[0].Rows.Count > 0)
  291. {
  292. this.Column1.DisplayMember = "DEFECTFLAGNAME";
  293. this.Column1.ValueMember = "DEFECTFLAGID";
  294. this.Column1.DataSource = dsDefectByProcedure.Tables[0].Copy();
  295. }
  296. // 缺陷数据源
  297. this.DefectFlag.DisplayMember = "DefectFlagName";
  298. this.DefectFlag.ValueMember = "DefectFlagID";
  299. this.DefectFlag.DataSource = CreateDataSource.GetDefectFlagTable();
  300. //DataTable dtReworkProcedure = new DataTable(); // 默认返回工序数据源,为空
  301. //dtReworkProcedure.Columns.Add("ReworkProcedureID", typeof(decimal));
  302. //dtReworkProcedure.Columns.Add("ReworkProcedureName");
  303. //this.ReworkProcedureID.DisplayMember = "ReworkProcedureName";
  304. //this.ReworkProcedureID.ValueMember = "ReworkProcedureID";
  305. //this.ReworkProcedureID.DataSource = dtReworkProcedure;
  306. }
  307. catch (Exception ex)
  308. {
  309. // 对异常进行共通处理
  310. ExceptionManager.HandleEventException(this.ToString(),
  311. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  312. }
  313. }
  314. /// <summary>
  315. /// 工号文本离开焦点后事件
  316. /// </summary>
  317. /// <param name="sender"></param>
  318. /// <param name="e"></par
  319. private void txtUserCode_Leave(object sender, EventArgs e)
  320. {
  321. try
  322. {
  323. if (txtUserCode.Text.Trim() == string.Empty) // 如果未添加数据,则此项获取焦点
  324. {
  325. this.txtUserCode.IsMustInput = true;
  326. this.txtUserCode.Focus();
  327. return;
  328. }
  329. else
  330. {
  331. SUserEntity userEntity = new SUserEntity();
  332. userEntity.UserCode = this.txtUserCode.Text.Trim();
  333. // 此工号是否能生产工序
  334. CheckProcedureUserResult MsgCheckProcedureUser = (CheckProcedureUserResult)DoAsync(new BaseAsyncMethod(() =>
  335. {
  336. return PMModuleProxy.Service.CheckProcedureUser(this._procedureID, this.txtUserCode.Text.Trim());
  337. }));
  338. if (MsgCheckProcedureUser != null)
  339. {
  340. if (MsgCheckProcedureUser.ErrMsg != null)
  341. {
  342. MessageBox.Show(MsgCheckProcedureUser.ErrMsg,
  343. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  344. this.txtUserCode.Focus();
  345. return;
  346. }
  347. UserID = Convert.ToInt32(MsgCheckProcedureUser.UserID);
  348. UserCode = MsgCheckProcedureUser.UserCode;
  349. UserName = MsgCheckProcedureUser.UserName;
  350. }
  351. }
  352. }
  353. catch (Exception ex)
  354. {
  355. // 对异常进行共通处理
  356. ExceptionManager.HandleEventException(this.ToString(),
  357. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  358. }
  359. }
  360. /// <summary>
  361. /// 条形码按键事件
  362. /// </summary>
  363. /// <param name="sender"></param>
  364. /// <param name="e"></param>
  365. private void txtBarCode_KeyPress(object sender, KeyPressEventArgs e)
  366. {
  367. try
  368. {
  369. if ((int)e.KeyChar == 13) // 按了回车键
  370. {
  371. if (this.txtBarCode.Text.Trim() == string.Empty)
  372. {
  373. this.txtBarCode.Focus();
  374. return;
  375. }
  376. // 校验条码 获取校验条码信
  377. DataSet dsCheckBarcode = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  378. {
  379. return PMModuleProxy.Service.CheckBarcode(this._procedureID, this.txtBarCode.Text.Trim());
  380. }));
  381. if (dsCheckBarcode != null && dsCheckBarcode.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  382. {
  383. if (dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString() != string.Empty)
  384. {
  385. // 表示有错误
  386. MessageBox.Show(string.Format(dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString(), this.txtBarCode.Text.Trim(), "产品条码"),
  387. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  388. this.txtBarCode.Focus();
  389. return;
  390. }
  391. else
  392. {
  393. BindProductionData(dsCheckBarcode);
  394. this._currentBarCode = txtBarCode.Text.Trim();
  395. BindDefectLocation(); // 绑定缺陷位置
  396. this.txtBarCode.Text = string.Empty;
  397. FilterTableRow();
  398. }
  399. }
  400. }
  401. }
  402. catch (Exception ex)
  403. {
  404. // 对异常进行共通处理
  405. ExceptionManager.HandleEventException(this.ToString(),
  406. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  407. }
  408. }
  409. #endregion
  410. #region 绑定到第一个DataGriwView数据源
  411. /// <summary>
  412. /// 绑定到第一个DataGriwView数据源
  413. /// </summary>
  414. private void BindProductionData(DataSet dsCheckBarcode)
  415. {
  416. try
  417. {
  418. DataRow[] dr = TableProductionData.Select("BarCode='" + this.txtBarCode.Text.Trim() + "'");
  419. if (dr.Length > 0)
  420. {
  421. // 不允许重复添加
  422. return;
  423. }
  424. DataRow drNew = TableProductionData.NewRow();
  425. drNew["BarCode"] = this.txtBarCode.Text.Trim();
  426. drNew["GoodsID"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_goodsID.ToString()];
  427. drNew["GoodsCode"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_goodsCode.ToString()];
  428. drNew["GoodsName"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_goodsName.ToString()];
  429. drNew["DefectFlagID"] = 0; ;
  430. // drNew["ReworkProcedureID"] = 0;
  431. drNew["ReworkProcedureID"] = null;
  432. drNew["Remarks"] = "";
  433. drNew["UserID"] = UserID;
  434. TableProductionData.Rows.Add(drNew);
  435. if (DSTable.Tables.IndexOf(this.txtBarCode.Text.Trim()) == -1)
  436. {
  437. DataTable dtProductionDefectData = new DataTable(this.txtBarCode.Text.Trim());
  438. dtProductionDefectData.Columns.Add("ProductionBarCode");
  439. dtProductionDefectData.Columns.Add("discarde");
  440. dtProductionDefectData.Columns.Add("DefectFlag", typeof(decimal));
  441. dtProductionDefectData.Columns.Add("DefectLocation", typeof(decimal));
  442. dtProductionDefectData.Columns.Add("DutyProcedureID", typeof(decimal));
  443. dtProductionDefectData.Columns.Add("DutyProcedureUserID", typeof(decimal));//责任员工
  444. dtProductionDefectData.Columns.Add("Jobs", typeof(decimal));//工种
  445. dtProductionDefectData.Columns.Add("DefectRemarks");
  446. dtProductionDefectData.Columns.Add("TempCount");
  447. dtProductionDefectData.Columns.Add("ProductionDataID"); //生产数据ID
  448. DSTable.Tables.Add(dtProductionDefectData);
  449. }
  450. this.dgvDefect.DataSource = DSTable.Tables[this.txtBarCode.Text.Trim()];
  451. this.dgvProductionData.CurrentCell = null;
  452. this.dgvProductionData.Rows[dgvProductionData.RowCount - 1].Selected = true;
  453. this.dgvDefect.ReadOnly = true;
  454. this.dgvDefectStaff.ReadOnly = true;
  455. }
  456. catch (Exception ex)
  457. {
  458. throw ex;
  459. }
  460. }
  461. #endregion
  462. #region 私有方法
  463. /// <summary>
  464. /// 通过是否有缺陷来启用或禁用
  465. /// </summary>
  466. /// <param name="DefectFlag"></param>
  467. private void SetGridView(int DefectFlag)
  468. {
  469. if (DefectFlag == 0) //没有缺陷
  470. {
  471. dgvDefect.ReadOnly = true;
  472. dgvDefectStaff.ReadOnly = true;
  473. }
  474. else
  475. {
  476. dgvDefect.ReadOnly = false; ;
  477. dgvDefectStaff.ReadOnly = false;
  478. }
  479. }
  480. #endregion
  481. /// <summary>
  482. /// 生产数据编辑控件显示事件
  483. /// </summary>
  484. /// <param name="sender"></param>
  485. /// <param name="e"></param>
  486. private void dgvProductionData_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  487. {
  488. if (e.Control is DataGridViewComboBoxEditingControl
  489. && this.dgvProductionData.CurrentCell.ColumnIndex == 3
  490. && this.dgvProductionData.CurrentCell.RowIndex != -1)
  491. {
  492. this._dataGridViewComboBox = (DataGridViewComboBoxEditingControl)e.Control;
  493. //增加委托处理
  494. _dataGridViewComboBox.SelectionChangeCommitted += new EventHandler(this.dataGridViewComboBox_SelectionChangeCommitted);
  495. }
  496. }
  497. /// <summary>
  498. /// 生产数据下拉列表改变事件
  499. /// </summary>
  500. /// <param name="sender"></param>
  501. /// <param name="e"></param>
  502. private void dataGridViewComboBox_SelectionChangeCommitted(object sender, EventArgs e)
  503. {
  504. SetGridView(Convert.ToInt32(((ComboBox)sender).SelectedValue.ToString()));
  505. }
  506. /// <summary>
  507. /// 产品数据单元格进入事件
  508. /// </summary>
  509. /// <param name="sender"></param>
  510. /// <param name="e"></param>
  511. private void dgvProductionData_CellEnter(object sender, DataGridViewCellEventArgs e)
  512. {
  513. try
  514. {
  515. if (this.dgvProductionData.CurrentCell != null)
  516. {
  517. // 记录最后选择行
  518. this._selectedRowIndex = this.dgvProductionData.CurrentCell.RowIndex;
  519. _currentBarCode = this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString();
  520. _C_DGV_Cell_ListBoxComboBox = dgvProductionData.Rows[_selectedRowIndex].Cells[4] as C_DGV_Cell_ListBoxComboBox;
  521. DataSet ds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  522. {
  523. return PMModuleProxy.Service.GetReworkProcedureByBarcode(this._procedureID, this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString());
  524. }));
  525. _currentGoodsID = Convert.ToInt32(this.dgvProductionData.Rows[_selectedRowIndex].Cells["GoodsID"].Value);
  526. _currentBarCode = this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString();
  527. _C_DGV_Cell_ListBoxComboBox.DisplayMember = "ReworkProcedureName";
  528. _C_DGV_Cell_ListBoxComboBox.ValueMember = "ReworkProcedureID";
  529. _C_DGV_Cell_ListBoxComboBox.DataSource = ds.Tables[0];
  530. }
  531. }
  532. catch (Exception ex)
  533. {
  534. // 对异常进行共通处理
  535. ExceptionManager.HandleEventException(this.ToString(),
  536. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  537. }
  538. }
  539. /// <summary>
  540. /// 产品数据选定项改变事件
  541. /// </summary>
  542. /// <param name="sender"></param>
  543. /// <param name="e"></param>
  544. private void dgvProductionData_SelectionChanged(object sender, EventArgs e)
  545. {
  546. try
  547. {
  548. if (this.dgvProductionData.CurrentCell != null)
  549. {
  550. SetGridView(Convert.ToInt32(this.dgvProductionData.Rows[_selectedRowIndex].Cells["DefectFlag"].Value));
  551. FilterTableRow();
  552. BindDefectLocation();
  553. this.dgvDefectStaff.DataSource = null;
  554. _smallByte.Clear();//防止重复绑定图片
  555. this.lvPic.Clear();//
  556. }
  557. }
  558. catch (Exception ex)
  559. {
  560. // 对异常进行共通处理
  561. ExceptionManager.HandleEventException(this.ToString(),
  562. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  563. }
  564. }
  565. /// <summary>
  566. /// 保存按钮事件
  567. /// </summary>
  568. /// <param name="sender"></param>
  569. /// <param name="e"></param>
  570. private void btnSave_Click(object sender, EventArgs e)
  571. {
  572. DataTable dt = this.TableProductionData;
  573. DataTable dt2 = this.TableProductionDefectData;
  574. DataSet ds = DSTable;
  575. }
  576. /// <summary>
  577. /// 绑定缺陷数据源
  578. /// </summary>
  579. private void BindDefectDataSource()
  580. {
  581. try
  582. {
  583. DataSet dsDefectByProcedure = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  584. {
  585. return PMModuleProxy.Service.GetDefectByProcedure(this._procedureID);
  586. }));
  587. if (dsDefectByProcedure != null && dsDefectByProcedure.Tables.Count > 0
  588. && dsDefectByProcedure.Tables[0].Rows.Count > 0)
  589. {
  590. // 缺陷数据源
  591. this.Column1.DisplayMember = "DefectFlagName";
  592. this.Column1.ValueMember = "DefectFlagID";
  593. this.Column1.DataSource = dsDefectByProcedure.Tables[0];
  594. }
  595. }
  596. catch (Exception ex)
  597. {
  598. // 对异常进行共通处理
  599. ExceptionManager.HandleEventException(this.ToString(),
  600. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  601. }
  602. }
  603. /// <summary>
  604. ///
  605. /// </summary>
  606. private void FilterTableRow()
  607. {
  608. this.dgvDefect.DataSource = DSTable.Tables[_currentBarCode];
  609. if (this.dgvDefect.DataSource != null)
  610. {
  611. if (DSTable.Tables[_currentBarCode].Rows.Count > 0)
  612. {
  613. for (int i = 0; i < DSTable.Tables[_currentBarCode].Rows.Count; i++)
  614. {
  615. string currentBarCode = DSTable.Tables[_currentBarCode].Rows[i]["ProductionBarCode"].ToString();
  616. if (DSTable.Tables[_currentBarCode].Rows[i]["DefectFlag"].ToString() != "")
  617. {
  618. int defectid = Convert.ToInt32(DSTable.Tables[_currentBarCode].Rows[i]["DefectFlag"].ToString());
  619. DataGridViewComboBoxCell aa = dgvDefect.Rows[i].Cells[3] as DataGridViewComboBoxCell;
  620. DataSet dsDutyDefect = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  621. {
  622. return PMModuleProxy.Service.GetDutyProcedureByBarCode(currentBarCode, defectid);
  623. }));
  624. aa.DisplayMember = "DutyProcedureName";
  625. aa.ValueMember = "DutyProcedureID";
  626. aa.DataSource = dsDutyDefect.Tables[0];
  627. }
  628. }
  629. }
  630. }
  631. }
  632. private void dgvDefect_UserAddedRow(object sender, DataGridViewRowEventArgs e)
  633. {
  634. this.dgvDefect.Rows[e.Row.Index - 1].Cells["ProductionBarCode"].Value = _currentBarCode;
  635. this.dgvDefect.Rows[e.Row.Index - 1].Cells["TempCount"].Value = (this._tempCount++);
  636. // 添加行后,默认创建对应的临时表
  637. DataTable dtStaff = new DataTable(string.Format("TempTable{0}", this.dgvDefect.Rows[e.Row.Index - 1].Cells["TempCount"].Value.ToString()));
  638. dtStaff.Columns.Add("IsSelected");
  639. dtStaff.Columns.Add("StaffID");
  640. dtStaff.Columns.Add("StaffCode");
  641. dtStaff.Columns.Add("StaffName");
  642. dtStaff.Columns.Add("StaffTempCount");
  643. DSTableStaff.Tables.Add(dtStaff);
  644. this.dgvDefectStaff.DataSource = null; // 创建新行后,责任员工列表清空
  645. // 添加行后,默认创建对应的缺陷图片临时表
  646. DataTable dtImage = new DataTable(string.Format("TempTable{0}", this.dgvDefect.Rows[e.Row.Index - 1].Cells["TempCount"].Value.ToString()));
  647. dtImage.Columns.Add("StaffTempCount");
  648. dtImage.Columns.Add("ImageByte", typeof(byte[]));
  649. DSTableImage.Tables.Add(dtImage);
  650. this.lvPic.Items.Clear();//当前上传的图片显示清空
  651. }
  652. /// <summary>
  653. /// 单元格CheckBox事件
  654. /// </summary>
  655. /// <param name="sender"></param>
  656. /// <param name="e"></param>
  657. private void dgvDefect_CellContentClick(object sender, DataGridViewCellEventArgs e)
  658. {
  659. if (e.ColumnIndex == 0 && e.RowIndex != -1)
  660. {
  661. int checkValue = Convert.ToInt32(this.dgvDefect.Rows[e.RowIndex].Cells[0].EditedFormattedValue);
  662. SetCheckBoxSelected(checkValue, e.RowIndex);
  663. }
  664. }
  665. /// <summary>
  666. /// 清空以前所选中的缺陷
  667. /// </summary>
  668. /// <param name="checkValue"></param>
  669. private void SetCheckBoxSelected(int checkValue, int rowIndex)
  670. {
  671. DataTable dtOrgDataSource = this.dgvDefect.DataSource as DataTable;
  672. for (int i = 0; i < DSTable.Tables[dtOrgDataSource.TableName].Rows.Count; i++)
  673. {
  674. if (i == rowIndex)
  675. {
  676. dtOrgDataSource.Rows[i]["discarde"] = 1;
  677. }
  678. else
  679. {
  680. dtOrgDataSource.Rows[i]["discarde"] = 0;
  681. }
  682. }
  683. }
  684. /// <summary>
  685. /// 绑定缺陷位置
  686. /// </summary>
  687. private void BindDefectLocation()
  688. {
  689. int goodsID = 0;
  690. DataRow[] dr = TableProductionData.Select("BarCode='" + this._currentBarCode + "'");
  691. if (dr.Length > 0)
  692. {
  693. goodsID = Convert.ToInt32(dr[0]["GoodsID"]);
  694. }
  695. DataSet dsDefectLocation = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  696. {
  697. return PMModuleProxy.Service.GetDefectLocaionByGoodsID(goodsID);
  698. }));
  699. this.DefectLocationColumn.DisplayMember = "DEFECTPOSITIONNAME";
  700. this.DefectLocationColumn.ValueMember = "DEFECTPOSITIONID";
  701. this.DefectLocationColumn.DataSource = dsDefectLocation.Tables[0];
  702. }
  703. /// <summary>
  704. /// 绑定责任工序
  705. /// </summary>
  706. /// <param name="barcode">产品条码</param>
  707. /// <param name="defectid">责任工序</param>
  708. private void BindDutyDefect(string barcode, int defectid)
  709. {
  710. DataSet dsDutyDefect = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  711. {
  712. return PMModuleProxy.Service.GetDutyProcedureByBarCode(barcode, defectid);
  713. }));
  714. if (dsDutyDefect != null && dsDutyDefect.Tables.Count > 0
  715. && dsDutyDefect.Tables[0].Rows.Count > 0)
  716. {
  717. this.DutyProcedureIDLocation.DisplayMember = "ProcedureName";
  718. this.DutyProcedureIDLocation.ValueMember = "ProcedureID";
  719. this.DutyProcedureIDLocation.DataSource = dsDutyDefect.Tables[0];//DutyProcedure
  720. }
  721. }
  722. /// <summary>
  723. /// 缺陷数据下拉列表改变事件
  724. /// </summary>
  725. /// <param name="sender"></param>
  726. /// <param name="e"></param>
  727. private void dataGridViewComboBox_DutyDefect_SelectionChangeCommitted(object sender, EventArgs e)
  728. {
  729. if (((ComboBox)sender).SelectedValue != null)
  730. {
  731. BindDutyDefect(_currentBarCode, Convert.ToInt32(((ComboBox)sender).SelectedValue.ToString()));
  732. }
  733. }
  734. /// <summary>
  735. /// 缺陷产品单元格进入事件
  736. /// </summary>
  737. /// <param name="sender"></param>
  738. /// <param name="e"></param>
  739. private void dgvDefect_CellEnter(object sender, DataGridViewCellEventArgs e)
  740. {
  741. try
  742. {
  743. if (this.dgvDefect.CurrentCell != null)
  744. {
  745. // 记录最后选择行
  746. //this.dgvDefect.CurrentCell.RowIndex;
  747. if (this.dgvDefect.CurrentCell.ColumnIndex == 3
  748. && this.dgvDefect.CurrentCell.RowIndex != -1)
  749. {
  750. string currentBarCode = this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["ProductionBarCode"].Value.ToString();
  751. if (this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["Column1"].Value.ToString() != "")
  752. {
  753. int defectid = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["Column1"].Value.ToString());
  754. DataGridViewComboBoxCell aa = dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells[3] as DataGridViewComboBoxCell;
  755. DataSet dsDutyDefect = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  756. {
  757. return PMModuleProxy.Service.GetDutyProcedureByBarCode(currentBarCode, defectid);
  758. }));
  759. aa.DisplayMember = "DutyProcedureName";
  760. aa.ValueMember = "DutyProcedureID";
  761. aa.DataSource = dsDutyDefect.Tables[0];
  762. }
  763. }
  764. }
  765. }
  766. catch (Exception ex)
  767. {
  768. // 对异常进行共通处理
  769. ExceptionManager.HandleEventException(this.ToString(),
  770. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  771. }
  772. }
  773. /// <summary>
  774. /// 根据责任工序读出责任员工,并绑定到数据源
  775. /// </summary>
  776. /// <param name="barcode"></param>
  777. /// <param name="dutyProcedureID"></param>
  778. private void SetDutyCode(string barcode, int dutyProcedureID, int rowIndex)
  779. {
  780. DataSet dsDutyCode = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  781. {
  782. return PMModuleProxy.Service.GetDutyProcedureCodeByBarCode(barcode, dutyProcedureID);
  783. }));
  784. if (dsDutyCode != null && dsDutyCode.Tables.Count > 0
  785. && dsDutyCode.Tables[0].Rows.Count > 0)
  786. {
  787. this.DutyProcedureCodeLocation.DisplayMember = "UserCode";
  788. this.DutyProcedureCodeLocation.ValueMember = "UserID";
  789. this.DutyProcedureCodeLocation.DataSource = dsDutyCode.Tables[0];
  790. this.dgvDefect.CurrentCell = null;
  791. this.dgvDefect.Rows[rowIndex].Cells["DutyProcedureCodeLocation"].Value = dsDutyCode.Tables[0].Rows[0]["UserID"].ToString();
  792. this.dgvDefect.Rows[rowIndex].Cells["ProductionDataID"].Value = dsDutyCode.Tables[0].Rows[0]["ProductionDataID"].ToString();
  793. SetDutyJobs(Convert.ToInt32(dsDutyCode.Tables[0].Rows[0]["UserID"]), dutyProcedureID, rowIndex, Convert.ToInt32(dsDutyCode.Tables[0].Rows[0]["ProductionDataID"]));
  794. }
  795. }
  796. /// <summary>
  797. /// 根据责任工序读出工种,并绑定到数据源
  798. /// </summary>
  799. private void SetDutyJobs(int UserID, int dutyProcedureID, int rowIndex, int ProductionDataID)
  800. {
  801. DataSet dsDutyJobs = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  802. {
  803. return PMModuleProxy.Service.GetDutyJobsCodeByUser(UserID, ProductionDataID);
  804. }));
  805. if (dsDutyJobs != null && dsDutyJobs.Tables.Count > 0
  806. && dsDutyJobs.Tables[0].Rows.Count > 0)
  807. {
  808. this.JobsLocation.DisplayMember = "JobsName";
  809. this.JobsLocation.ValueMember = "JobsID";
  810. this.JobsLocation.DataSource = dsDutyJobs.Tables[0];
  811. this.dgvDefect.CurrentCell = null;
  812. this.dgvDefect.Rows[rowIndex].Cells["JobsLocation"].Value = dsDutyJobs.Tables[0].Rows[0]["JobsID"].ToString();
  813. _currentTempSign = this.dgvDefect.Rows[rowIndex].Cells["TempCount"].Value.ToString(); //当前临时标记
  814. // 通过工种来搜索缺陷责任员工列表
  815. BindDutyStaff(ProductionDataID, UserID, Convert.ToInt32(dsDutyJobs.Tables[0].Rows[0]["JobsID"]), Convert.ToInt32(this.dgvDefect.Rows[rowIndex].Cells["TempCount"].Value));
  816. }
  817. }
  818. /// <summary>
  819. /// 缺陷产品当前是否有未提交数据事件
  820. /// </summary>
  821. /// <param name="sender"></param>
  822. /// <param name="e"></param>
  823. private void dgvDefect_CurrentCellDirtyStateChanged(object sender, EventArgs e)
  824. {
  825. try
  826. {
  827. if (this.dgvDefect.CurrentCell != null)
  828. {
  829. // 记录最后选择行
  830. if (this.dgvDefect.CurrentCell.ColumnIndex == 3
  831. && this.dgvDefect.CurrentCell.RowIndex != -1)
  832. {
  833. if (dgvDefect.IsCurrentCellDirty)
  834. {
  835. dgvDefect.CommitEdit(DataGridViewDataErrorContexts.Commit);
  836. }
  837. }
  838. }
  839. }
  840. catch (Exception ex)
  841. {
  842. // 对异常进行共通处理
  843. ExceptionManager.HandleEventException(this.ToString(),
  844. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  845. }
  846. }
  847. /// <summary>
  848. /// 缺陷单元格值改变事件
  849. /// </summary>
  850. /// <param name="sender"></param>
  851. /// <param name="e"></param>
  852. private void dgvDefect_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  853. {
  854. try
  855. {
  856. if (this.dgvDefect.CurrentCell != null)
  857. {
  858. if (this.dgvDefect.CurrentCell.ColumnIndex == 3
  859. && this.dgvDefect.CurrentCell.RowIndex != -1)
  860. {
  861. string currentBarCode = this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["ProductionBarCode"].Value.ToString();
  862. if (this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["DutyProcedureIDLocation"].Value.ToString() != "")
  863. {
  864. int dutyProcedureID = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["DutyProcedureIDLocation"].Value.ToString());
  865. SetDutyCode(currentBarCode, dutyProcedureID, this.dgvDefect.CurrentCell.RowIndex);
  866. }
  867. }
  868. else if (this.dgvDefect.CurrentCell.ColumnIndex == 4
  869. && this.dgvDefect.CurrentCell.RowIndex != -1)
  870. {
  871. if (this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["DutyProcedureIDLocation"].Value.ToString() != ""
  872. && this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["DutyProcedureCodeLocation"].Value.ToString() != "")
  873. {
  874. int userID = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["DutyProcedureCodeLocation"].Value.ToString());
  875. int dutyProcedureID = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["DutyProcedureIDLocation"].Value.ToString());
  876. int productionDataID = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["ProductionDataID"].Value.ToString());
  877. SetDutyJobs(userID, dutyProcedureID, this.dgvDefect.CurrentCell.RowIndex, productionDataID);
  878. }
  879. }
  880. }
  881. }
  882. catch (Exception ex)
  883. {
  884. // 对异常进行共通处理
  885. ExceptionManager.HandleEventException(this.ToString(),
  886. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  887. }
  888. }
  889. /// <summary>
  890. /// 绑定缺陷责任员工
  891. /// </summary>
  892. /// <param name="productionDataID">生产数据ID</param>
  893. /// <param name="userID">用户ID</param>
  894. /// <param name="jobs">工种ID</param>
  895. /// <param name="StaffTempCount">唯一标识</param>
  896. private void BindDutyStaff(int productionDataID, int userID, int jobs, int StaffTempCount)
  897. {
  898. // 获取临时表是否有数据,如果有行,则删除,
  899. DataTable dtTemp = DSTableStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  900. if (dtTemp.Rows.Count > 0)
  901. {
  902. // 清空临时表数据
  903. DSTableStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Clear();
  904. }
  905. DataSet dsDutyStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  906. {
  907. return PMModuleProxy.Service.GetDutyStaffByUserIDAndJobs(productionDataID, userID, jobs);
  908. }));
  909. if (dsDutyStaff != null && dsDutyStaff.Tables.Count > 0
  910. && dsDutyStaff.Tables[0].Rows.Count > 0)
  911. {
  912. foreach (DataRow dr in dsDutyStaff.Tables[0].Rows)
  913. {
  914. DataRow addDr = DSTableStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].NewRow();
  915. addDr["IsSelected"] = 0;
  916. addDr["StaffID"] = dr["StaffID"];
  917. addDr["StaffCode"] = dr["StaffCode"];
  918. addDr["StaffName"] = dr["StaffName"];
  919. addDr["StaffTempCount"] = StaffTempCount;
  920. DSTableStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Rows.Add(addDr);
  921. }
  922. this.dgvDefectStaff.DataSource = DSTableStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
  923. }
  924. }
  925. /// <summary>
  926. /// 缺陷数据源选定项改变事件
  927. /// </summary>
  928. /// <param name="sender"></param>
  929. /// <param name="e"></param>
  930. private void dgvDefect_SelectionChanged(object sender, EventArgs e)
  931. {
  932. try
  933. {
  934. if (this.dgvDefect.CurrentCell != null)
  935. {
  936. if (this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString() != string.Empty)
  937. {
  938. int staffTempCount = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString());
  939. this.dgvDefectStaff.DataSource = DSTableStaff.Tables[string.Format("TempTable{0}", staffTempCount.ToString())];
  940. _currentTempSign = this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString(); //当前临时标记
  941. _smallByte.Clear();//防止重复绑定图片
  942. BindByteImage(DSTableImage.Tables[string.Format("TempTable{0}", staffTempCount.ToString())]);
  943. }
  944. else
  945. {
  946. this.dgvDefectStaff.DataSource = null;
  947. _smallByte.Clear();//防止重复绑定图片
  948. this.lvPic.Clear();//
  949. }
  950. }
  951. }
  952. catch (Exception ex)
  953. {
  954. // 对异常进行共通处理
  955. ExceptionManager.HandleEventException(this.ToString(),
  956. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  957. }
  958. }
  959. /// <summary>
  960. /// 绑定并显示图片
  961. /// </summary>
  962. /// <param name="ImageData"></param>
  963. protected void BindByteImage(DataTable ImageData)
  964. {
  965. _smallByte.Clear();
  966. foreach (DataRow dr in ImageData.Rows)
  967. {
  968. //将数据库中的缩略图取出
  969. _smallByte.Add((byte[])dr[1]);
  970. }
  971. //绑定缩略图
  972. BindImg();
  973. }
  974. /// <summary>
  975. /// 上传图片按钮事件
  976. /// </summary>
  977. /// <param name="sender"></param>
  978. /// <param name="e"></param>
  979. private void btnUpload_Click(object sender, EventArgs e)
  980. {
  981. try
  982. {
  983. this.odlgFile.Filter = Constant.FILTER_PIC;
  984. this.odlgFile.FilterIndex = Constant.INT_IS_ZERO;
  985. this.odlgFile.RestoreDirectory = true;
  986. this.odlgFile.Title = "选择缺陷图片";
  987. this.odlgFile.FileName = null;
  988. this.odlgFile.RestoreDirectory = true;
  989. if (this.odlgFile.ShowDialog() == DialogResult.OK)
  990. {
  991. FileInfo file = new FileInfo(odlgFile.FileName);
  992. if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
  993. {
  994. MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "缺陷图片", "大小", "1M"),
  995. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  996. }
  997. else
  998. {
  999. Image PicImage = Image.FromStream(file.OpenRead());
  1000. this._PicByte.Add(ImageToByte(PicImage));
  1001. GetThumbnail(file);
  1002. BindImg();
  1003. }
  1004. }
  1005. }
  1006. catch (Exception ex)
  1007. {
  1008. // 对异常进行共通处理
  1009. ExceptionManager.HandleEventException(this.ToString(),
  1010. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1011. }
  1012. }
  1013. /// <summary>
  1014. /// 将图片文件转换成二进制
  1015. /// </summary>
  1016. /// <param name="img"></param>
  1017. /// <returns></returns>
  1018. public static byte[] ImageToByte(Image img)
  1019. {
  1020. byte[] smallbuffer = null;
  1021. using (MemoryStream ms = new MemoryStream())
  1022. {
  1023. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  1024. ms.Position = Constant.INT_IS_ZERO;
  1025. smallbuffer = new byte[ms.Length];
  1026. ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
  1027. ms.Flush();
  1028. }
  1029. return smallbuffer;
  1030. }
  1031. /// <SUMMARY>
  1032. /// 重绘缩略图并把缩略图转为二进制储存
  1033. /// </SUMMARY>
  1034. /// <PARAM name="sourceFile">图片源路径</PARAM>
  1035. /// <PARAM name="destHeight">缩放后图片高度</PARAM>
  1036. /// <PARAM name="destWidth">缩放后图片宽度</PARAM>
  1037. /// <RETURNS></RETURNS>
  1038. public void GetThumbnail(FileInfo sourceFile)
  1039. {
  1040. Image imgSource = Image.FromStream(sourceFile.OpenRead());
  1041. ImageFormat thisFormat = imgSource.RawFormat;
  1042. int sW = 0, sH = 0;
  1043. // 按比例缩放
  1044. int sWidth = imgSource.Width;
  1045. int sHeight = imgSource.Height;
  1046. int destWidth = 100;
  1047. int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
  1048. if (sHeight > destHeight || sWidth > destWidth)
  1049. {
  1050. if ((sWidth * destHeight) > (sHeight * destWidth))
  1051. {
  1052. sW = destWidth;
  1053. sH = (destWidth * sHeight) / sWidth;
  1054. }
  1055. else
  1056. {
  1057. sH = destHeight;
  1058. sW = (sWidth * destHeight) / sHeight;
  1059. }
  1060. }
  1061. else
  1062. {
  1063. sW = sWidth;
  1064. sH = sHeight;
  1065. }
  1066. Bitmap outBmp = new Bitmap(destWidth, destHeight);
  1067. Graphics g = Graphics.FromImage(outBmp);
  1068. g.Clear(Color.Black);
  1069. // 设置画布的描绘质量
  1070. g.CompositingQuality = CompositingQuality.HighQuality;
  1071. g.SmoothingMode = SmoothingMode.HighQuality;
  1072. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  1073. g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
  1074. g.Dispose();
  1075. //将重绘的图片转为二进制并保存
  1076. Image image = (Image)outBmp;
  1077. byte[] smallbuffer = ImageToByte(image);
  1078. if (this._currentTempSign != "")
  1079. {
  1080. DataRow dr = DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].NewRow();
  1081. dr["StaffTempCount"] = this._currentTempSign;
  1082. dr["ImageByte"] = smallbuffer;
  1083. DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].Rows.Add(dr);
  1084. }
  1085. _smallByte.Add(smallbuffer);
  1086. imgSource.Dispose();
  1087. outBmp.Dispose();
  1088. }
  1089. /// <summary>
  1090. /// 根据原图片宽高比获取缩略图的高(根据宽)
  1091. /// </summary>
  1092. /// <param name="BigWidth"></param>
  1093. /// <param name="BigHeight"></param>
  1094. /// <param name="SmallWidth"></param>
  1095. /// <returns></returns>
  1096. protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
  1097. {
  1098. decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
  1099. return Convert.ToInt32(SmallWidth / scale);
  1100. }
  1101. /// <summary>
  1102. /// 绑定缩略图到控件中
  1103. /// </summary>
  1104. protected void BindImg()
  1105. {
  1106. ImageList ilPic = new ImageList();
  1107. //每次绑定要清空数据源
  1108. ilPic.Images.Clear();
  1109. //将缩略图二进制集合中的数据转换成图片文件
  1110. List<Image> LSImageList = new List<Image>();
  1111. foreach (byte[] smallby in _smallByte)
  1112. {
  1113. LSImageList.Add(byteArrayToImage(smallby));
  1114. }
  1115. //添加数据源
  1116. foreach (Image img in LSImageList)
  1117. {
  1118. ilPic.Images.Add(img);
  1119. }
  1120. ilPic.ImageSize = new Size(100, 100);
  1121. this.lvPic.LargeImageList = ilPic;
  1122. this.lvPic.BeginUpdate();
  1123. //清空列表的数据源
  1124. lvPic.Items.Clear();
  1125. //添加列表的数据源
  1126. for (int i = 0; i < ilPic.Images.Count; i++)
  1127. {
  1128. ListViewItem lvi = new ListViewItem();
  1129. lvi.ImageIndex = i;
  1130. this.lvPic.Items.Add(lvi);
  1131. }
  1132. this.lvPic.EndUpdate();
  1133. }
  1134. /// <summary>
  1135. /// 将数据库中的二进制转换成图片
  1136. /// </summary>
  1137. /// <param name="data"></param>
  1138. /// <returns></returns>
  1139. public static Image byteArrayToImage(object data)
  1140. {
  1141. System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
  1142. System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
  1143. return returnImage;
  1144. }
  1145. /// <summary>
  1146. /// 删除图片按钮事件
  1147. /// </summary>
  1148. /// <param name="sender"></param>
  1149. /// <param name="e"></param>
  1150. private void btnDelete_Click(object sender, EventArgs e)
  1151. {
  1152. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  1153. {
  1154. int index = lvSelect.Index;
  1155. if (index < Constant.INT_IS_ZERO)
  1156. {
  1157. index = Constant.INT_IS_ZERO;
  1158. }
  1159. if (this._currentTempSign != "")
  1160. {
  1161. DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].Rows.RemoveAt(lvSelect.Index);
  1162. DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].AcceptChanges();
  1163. }
  1164. BindByteImage(DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)]);
  1165. }
  1166. }
  1167. /// <summary>
  1168. /// 关闭按钮事件
  1169. /// </summary>
  1170. /// <param name="sender"></param>
  1171. /// <param name="e"></param>
  1172. private void tsbtnClose_Click(object sender, EventArgs e)
  1173. {
  1174. this.Close();
  1175. }
  1176. /// <summary>
  1177. /// 产品条码列表删除事件
  1178. /// </summary>
  1179. /// <param name="sender"></param>
  1180. /// <param name="e"></param>
  1181. private void dgvProductionData_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  1182. {
  1183. try
  1184. {
  1185. string BarCode = this.dgvProductionData.Rows[e.Row.Index].Cells["BarCode"].Value.ToString();
  1186. DSTable.Tables[BarCode].Rows.Clear();//清空行
  1187. this.dgvDefectStaff.DataSource = null;
  1188. this.lvPic.Clear();
  1189. }
  1190. catch (Exception ex)
  1191. {
  1192. throw ex;
  1193. }
  1194. }
  1195. /// <summary>
  1196. /// 产品缺陷删除行事件
  1197. /// </summary>
  1198. /// <param name="sender"></param>
  1199. /// <param name="e"></param>
  1200. private void dgvDefect_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
  1201. {
  1202. try
  1203. {
  1204. string TempCount = this.dgvDefect.Rows[e.Row.Index].Cells["TempCount"].Value.ToString();
  1205. DSTableStaff.Tables[string.Format("TempTable{0}", TempCount.ToString())].Rows.Clear();//清空行
  1206. this.dgvDefectStaff.DataSource = null;
  1207. this.lvPic.Clear();
  1208. }
  1209. catch (Exception ex)
  1210. {
  1211. throw ex;
  1212. }
  1213. }
  1214. }
  1215. }