| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_PM_2203.cs
- * 2.功能描述:半成品检验-新增、编辑
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 王鑫 2016/06/28 1.00 新建
- *******************************************************************************/
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Imaging;
- using System.IO;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- namespace Dongke.IBOSS.PRD.Client.PMModule
- {
- public partial class F_PM_2203 : FormBase
- {
- #region 成员变量
- // 当前操作数据表
- private DataTable _dtBarCode = null;
- // 当前产品条码
- private string _barcode;
- // 当前产品ID
- private int _goodsID = 0;
- // 当前工序ID
- private int _procedureID = 0;
- // 当前是否为编辑 true
- private bool _isEdit = false;
- // 临时数
- private int _tempcount = 0;
- // 调用实例对象
- F_PM_2202 _frm1202 = null;
- // 员工数据集
- private DataSet _dsStaff = null;
- // 漏检员工数据集
- private DataSet _dsMissedStaff = null;
- // 图片数据集
- private DataSet _dsImage = null;
- // 生产数据ID
- private int _productionDataID = 0;
- // 缺陷生产数据ID
- private int _defectProductionDataID = 0;
- // 图片字节集
- private List<byte[]> _PicByte = new List<byte[]>();
- // 缩略图片字节集
- private List<byte[]> _smallByte = new List<byte[]>();
- // 行索引
- private int _rowIndex = 0;
- // 当前缺陷编码
- private string _currentDutyCode = "";
- // 当前缺陷位置编码
- private string _currentDefectPositionCode = "";
- // 当前缺陷责任工序编码
- private string _currentDefectProcedureCode = "";
- // 当前缺陷工号编码
- private string _currentDefectUserCode = "";
- // 当前漏检工号
- private string _currentMissedUserCode = "";
- // 默认责任工号数据源
- private DataTable _dtDutyProcedureUser = null;
- // 是否干补
- private int SpecialRepairflag = 0;//0未干补 1干补
- //默认缺陷对应的工种
- private DataTable _defaultJobsID = null;
- // 缺陷扣罚关系所有数据源
- private DataTable _dtDefectFineRelation = null;
- // 缺陷扣除数关系所有数据源
- private DataTable _dtDefectDeductionRelation = null;
- // 默认缺陷扣罚关系所有数据源
- private DataTable _dtDefaultDefectFineRelation = null;
- // 默认缺陷扣除数关系所有数据源
- private DataTable _dtDefaultDefectDeductionRelation = null;
- private int? _reworkprocedure = null;
- #endregion
- #region 构造函数
- public F_PM_2203()
- {
- InitializeComponent();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="dtBarCode">当前操作的数据表</param>
- /// <param name="barcode">当前产品条码</param>
- /// <param name="goodsID">当前产品ID</param>
- /// <param name="tempcount">当前累加数,防止重复</param>
- /// <param name="procedureID">当前工序</param>
- /// <param name="titleText">当前窗体名称</param>
- /// <param name="isEdit">false 新建 true编辑</param>
- /// <param name="frm1202">调用实例对象</param>
- /// <param name="dsStaff">员工数据集</param>
- /// <param name="dsImage">图片数据集</param>
- /// <param name="picByte">原图字节数组</param>
- /// <param name="smallByte">缩略图字节数组</param>
- /// <param name="rowIndex">编辑行号标识</param>
- public F_PM_2203(DataTable dtBarCode
- , string barcode
- , int goodsID
- , int tempcount
- , int procedureID
- , string titleText
- , bool isEdit
- , F_PM_2202 frm1202
- , DataSet dsStaff
- , DataSet dsMissedStaff
- , DataSet dsImage
- , List<byte[]> picByte
- , List<byte[]> smallByte
- , int rowIndex
- , int? reworkprocedure)
- {
- InitializeComponent();
- this.Text = titleText;
- this._dtBarCode = dtBarCode;
- this._barcode = barcode;
- this._goodsID = goodsID;
- this._procedureID = procedureID;
- this._isEdit = isEdit;
- this._tempcount = tempcount;
- this._frm1202 = frm1202;
- this._dsStaff = dsStaff;
- this._dsMissedStaff = dsMissedStaff;
- this._dsImage = dsImage;
- this._rowIndex = rowIndex;
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- this._reworkprocedure = reworkprocedure;
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_PM_1203_Load(object sender, EventArgs e)
- {
- try
- {
- this.dgvDefectStaff.AutoGenerateColumns = false;
- #region 加载缺陷
- DataSet dsResultDefect = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetAllSemicheckDefect();
- }));
- if (dsResultDefect != null && dsResultDefect.Tables[0].Rows.Count > 0)
- {
- DataView dv = dsResultDefect.Tables[0].DefaultView;
- dv.RowFilter = "ValueFlag='1'";
- this.dropDuty.DisplayMember = "DefectFlagName";
- this.dropDuty.ValueMember = "DEFECTID";
- this.dropDuty.DataSource = dv.ToTable();
- }
- #endregion 加载缺陷和缺陷位置 end
- #region 加载缺陷位置
- DataSet dsResultPosition = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetAllScdefectPosition();
- }));
- if (dsResultPosition != null && dsResultPosition.Tables[0].Rows.Count > 0)
- {
- DataView dv = dsResultPosition.Tables[0].DefaultView;
- dv.RowFilter = "ValueFlag='1'";
- this.dropDefectLocation.DisplayMember = "DefectPositionFlagName";
- this.dropDefectLocation.ValueMember = "DEFECTPOSITIONID";
- this.dropDefectLocation.DataSource = dv.ToTable();
- }
- #endregion 加载缺陷位置 end
- #region 加载条码对应的返工工序
- DataSet dsProcedure = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxy.Service.GetSemiCheckPassProcedure(this._barcode);
- }));
- if (dsProcedure != null && dsProcedure.Tables[0].Rows.Count > 0)
- {
- DataTable dtProcedure = dsProcedure.Tables[0];
- DataRow dr = dtProcedure.NewRow();
- dr["ProcedureName"] = "";
- dr["ProcedureID"] = -1;
- dtProcedure.Rows.InsertAt(dr, 0);
- this.dropDutyProcedure.DataSource = dtProcedure;
- this.dropDutyProcedure.DisplayMember = "ProcedureName";
- this.dropDutyProcedure.ValueMember = "ProcedureID";
- }
- #endregion
- #region 加载责任工号
- this.dropDutyUser.DisplayMember = "UserCode";
- this.dropDutyUser.ValueMember = "UserID";
- this.dropDutyUser.DataSource = GetDutyProcedureUser();
- #endregion
- if (this._reworkprocedure != null && this._reworkprocedure != -1)
- {
- this.dropDutyProcedure.SelectedValue = this._reworkprocedure;
- dropDutyProcedure_Validating(null, null);
- }
- ////漏检工号数据源
- //this.dropMissUser.DisplayMember = "UserCode";
- //this.dropMissUser.ValueMember = "UserID";
- //this.dropMissUser.DataSource = this._dtDutyProcedureUser;
- //this.dropJobs.DisplayMember = "JobsName";
- //this.dropJobs.ValueMember = "Jobs";
- //this.dropJobs.DataSource = GetDutyProcedureJobs(); // 默认空数据源,随着责任工号而改变
- // 缺陷扣罚
- //DataSet dsDefectFine = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- //{
- // return SystemModuleProxy.Service.GetDictionaryData(0, "ASE002");
- //}));
- //DataRow dr = dsDefectFine.Tables[0].NewRow();
- //dr["DictionaryID"] = -1;
- //dr["DictionaryValue"] = "";
- //dsDefectFine.Tables[0].Rows.InsertAt(dr, 0);
- //dsDefectFine.Tables[0].AcceptChanges();
- //this.cmbDefectFine.DisplayMember = "DictionaryValue";
- //this.cmbDefectFine.ValueMember = "DictionaryID";
- //this.cmbDefectFine.DataSource = dsDefectFine.Tables[0];
- if (this._isEdit)
- {
- this.dropDuty.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectID"].ToString();
- this._currentDutyCode = this._dtBarCode.Rows[this._rowIndex]["DefectCode"].ToString();
- // add 2016/01/06 wangx
- //if (this._dtDefectFineRelation != null)
- //{
- // DataRow[] r7 = this._dtDefectFineRelation.Select("defectid=" + this.dropDuty.SelectedValue);
- // if (r7.Length > 0)
- // {
- // DataTable dtNew = r7.CopyToDataTable();
- // DataRow dr = dtNew.NewRow();
- // dr["DefectFineID"] = -1;
- // dr["DefectFineCode"] = "";
- // dtNew.Rows.InsertAt(dr, 0);
- // dtNew.AcceptChanges();
- // //this.cmbDefectFine.DisplayMember = "DefectFineCode";
- // //this.cmbDefectFine.ValueMember = "DefectFineID";
- // //this.cmbDefectFine.DataSource = dtNew;
- // }
- // else
- // {
- // //this.cmbDefectFine.DisplayMember = "DefectFineCode";
- // //this.cmbDefectFine.ValueMember = "DefectFineID";
- // //this.cmbDefectFine.DataSource = this._dtDefaultDefectFineRelation;
- // }
- //}
- //if (this._dtDefectDeductionRelation != null)
- //{
- // DataRow[] r7 = this._dtDefectDeductionRelation.Select("defectid=" + this.dropDuty.SelectedValue);
- // if (r7.Length > 0)
- // {
- // DataTable dtNew = r7.CopyToDataTable();
- // DataRow dr = dtNew.NewRow();
- // dr["DefectDeductionID"] = -1;
- // //dr["DefectDeductionNum"] = "";
- // dtNew.Rows.InsertAt(dr, 0);
- // dtNew.AcceptChanges();
- // //this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
- // //this.cmbDefectDeduction.ValueMember = "DefectDeductionNum";
- // //this.cmbDefectDeduction.DataSource = dtNew;
- // }
- // else
- // {
- // //this.cmbDefectDeduction.DisplayMember = "DefectDeductionNum";
- // //this.cmbDefectDeduction.ValueMember = "DefectDeductionNum";
- // //this.cmbDefectDeduction.DataSource = this._dtDefaultDefectDeductionRelation;
- // }
- //}
- // add end
- // 缺陷选定后事件
- //BindDutyDefect(this._barcode, Convert.ToInt32(this.dropDuty.SelectedValue));
- // 缺陷位置
- this.dropDefectLocation.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectPositionID"].ToString();
- this._currentDefectPositionCode = this._dtBarCode.Rows[this._rowIndex]["DefectPositionCode"].ToString();
- // 责任工序
- if (this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"].ToString() != Constant.INT_IS_ZERO.ToString()
- && this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"].ToString() != string.Empty)
- {
- this.dropDutyProcedure.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"].ToString();
- this.dropDutyProcedure.Text = this._dtBarCode.Rows[this._rowIndex]["DefectProcedureName"].ToString();
- this._currentDefectProcedureCode = this._dtBarCode.Rows[this._rowIndex]["DefectProcedureCode"].ToString();
- this._defectProductionDataID = Convert.ToInt32(this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"]);
- // 责任工种
- //SetDutyCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
- string DutyProcedure = this.dropDutyProcedure.SelectedValue.ToString();
- DataTable dtDutyProcedureCode = this.dropDutyProcedure.DataSource as DataTable;
- if (dtDutyProcedureCode.Rows.Count > Constant.INT_IS_ZERO)
- {
- DataRow[] drJobs = dtDutyProcedureCode.Select("ProcedureID=" + DutyProcedure);
- if (drJobs.Length > Constant.INT_IS_ZERO)
- {
- this._currentDefectProcedureCode = drJobs[0]["ProcedureCode"].ToString();
- }
- }
- //DataSet dsDutyCode = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- //{
- // return PMModuleProxy.Service.GetDutyProcedureCodeByBarCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
- //}));
- //if (dsDutyCode != null && dsDutyCode.Tables.Count > Constant.INT_IS_ZERO
- // && dsDutyCode.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- //{
- // this.dropDutyUser.DisplayMember = "UserCode";
- // this.dropDutyUser.ValueMember = "UserID";
- // this.dropDutyUser.DataSource = dsDutyCode.Tables[0];
- this.dropDutyUser.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectUserID"].ToString();
- // this._currentDefectUserCode = this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"].ToString();
- this._productionDataID = Convert.ToInt32(this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"].ToString());
- // DataSet dsDutyJobs = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- // {
- // return PMModuleProxy.Service.GetDutyJobsCodeByUser(Convert.ToInt32(this.dropDutyUser.SelectedValue), this._productionDataID);
- // }));
- // if (dsDutyJobs != null && dsDutyJobs.Tables.Count > Constant.INT_IS_ZERO
- // && dsDutyJobs.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- // {
- // //this.dropJobs.DisplayMember = "JobsName";
- // //this.dropJobs.ValueMember = "JobsID";
- // //this.dropJobs.DataSource = dsDutyJobs.Tables[0];
- // //this.dropJobs.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["Jobs"].ToString();
- // }
- //}
- }
- else
- {
- this.dropDutyProcedure.SelectedValue = null;
- this.dropDutyProcedure.Text = "";
- this._currentDefectProcedureCode = "";
- // 没有责任工序,获取号及工种
- if (this._dtDutyProcedureUser != null && this._dtDutyProcedureUser.Rows.Count > Constant.INT_IS_ZERO)
- {
- this.dropDutyUser.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectUserID"].ToString();
- this._currentDefectUserCode = this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"].ToString();
- this._productionDataID = Convert.ToInt32(this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"].ToString());
- //DataSet dsDutyJobs = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- //{
- // return SystemModuleProxy.Service.GetAllJobsByUserID(Convert.ToInt32(this.dropDutyUser.SelectedValue));
- //}));
- //if (dsDutyJobs != null && dsDutyJobs.Tables.Count > Constant.INT_IS_ZERO
- // && dsDutyJobs.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- //{
- // //this.dropJobs.DisplayMember = "JobsName";
- // //this.dropJobs.ValueMember = "Jobs";
- // //this.dropJobs.DataSource = dsDutyJobs.Tables[0];
- // //this.dropJobs.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["Jobs"].ToString();
- //}
- }
- }
- // 漏检工号
- //if (this._dtBarCode.Rows[this._rowIndex]["MissedUserID"].ToString() != "-1")
- //{
- // //this.dropMissUser.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["MissedUserID"].ToString();
- // //this.dropMissUser.Text = this._dtBarCode.Rows[this._rowIndex]["MissedUserName"].ToString();
- // //this._currentMissedUserCode = this._dtBarCode.Rows[this._rowIndex]["MissedUserCode"].ToString();
- //}
- this.txtRemarks.Text = this._dtBarCode.Rows[this._rowIndex]["DefectRemarks"].ToString();
- this.dgvDefectStaff.DataSource = this._dsStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())];
- // BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount.ToString())]);
- //if (this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString() != "-1"
- // && this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString() != string.Empty)
- //{
- // // this.cmbDefectFine.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectFineID"].ToString();
- //}
- //if (this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"].ToString() != "-1"
- // && this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"].ToString() != string.Empty)
- //{
- // //this.cmbDefectDeduction.SelectedValue = this._dtBarCode.Rows[this._rowIndex]["DefectDeductionNum"].ToString();
- //}
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 缺陷验证事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dropDuty_Validating(object sender, System.ComponentModel.CancelEventArgs e)
- {
- try
- {
- if (this.dropDuty.SelectedValue != null && this.dropDuty.SelectedValue.ToString() != string.Empty)
- {
- if (!this.dropDuty.ReadOnly)
- {
- //选定缺陷值
- string DutyValue = this.dropDuty.SelectedValue.ToString();
- DataTable dtDuty = this.dropDuty.DataSource as DataTable;
- string newDefectCode = "";
- if (dtDuty.Rows.Count > Constant.INT_IS_ZERO)
- {
- DataRow[] dr = dtDuty.Select("DefectID=" + DutyValue);
- if (dr.Length > Constant.INT_IS_ZERO)
- {
- newDefectCode = dr[0]["DefectCode"].ToString();
- //当前缺陷编码
- this._currentDutyCode = dr[0]["DefectCode"].ToString();
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 责任工序验证事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dropDutyProcedure_Validating(object sender, System.ComponentModel.CancelEventArgs e)
- {
- try
- {
- //if (this.dropDutyProcedure.SelectedValue != null && this.dropDutyProcedure.SelectedValue.ToString() != string.Empty)
- //{
- // if (!this.txtRemarks.ReadOnly)
- // {
- // string DutyProcedure = this.dropDutyProcedure.SelectedValue.ToString();
- // DataTable dtDutyProcedureCode = this.dropDutyProcedure.DataSource as DataTable;
- // string newDutyProcedureCode = "";
- // if (dtDutyProcedureCode.Rows.Count > Constant.INT_IS_ZERO)
- // {
- // DataRow[] dr = dtDutyProcedureCode.Select("DutyProcedureID=" + DutyProcedure);
- // if (dr.Length > Constant.INT_IS_ZERO)
- // {
- // newDutyProcedureCode = dr[0]["DutyProcedureCode"].ToString();
- // //this._currentDefectProcedureCode = dr[0]["DutyProcedureCode"].ToString();
- // }
- // }
- // if (newDutyProcedureCode != this._currentDefectProcedureCode)
- // {
- // this._currentDefectProcedureCode = newDutyProcedureCode;
- // SetDutyCode(this._barcode, Convert.ToInt32(this.dropDutyProcedure.SelectedValue));
- // }
- // this.txtRemarks.Focus();
- // }
- //}
- //else
- //{
- // if (this._currentDefectProcedureCode == "")
- // return;
- // //当前责任工序编码为空串
- // this._currentDefectProcedureCode = "";
- // //责任工序为空串时,责任工号为当前账套所有生产工号
- // this._currentDefectUserCode = "";
- // this.dropDutyUser.DataSource = null;
- // this.dropDutyUser.DisplayMember = "UserCode";
- // this.dropDutyUser.ValueMember = "UserID";
- // this.dropDutyUser.DataSource = this._dtDutyProcedureUser;
- // this.dropDutyUser.Text = "";
- // //责任工序为空串时,责任工种置回空数据源
- // //this.dropJobs.DataSource = null;
- // //this.dropJobs.DisplayMember = "JobsName";
- // //this.dropJobs.ValueMember = "Jobs";
- // //this.dropJobs.DataSource = GetDutyProcedureJobs();
- // //this.dropJobs.Text = string.Empty;
- // //清空缺陷责任员工
- // if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", this._tempcount.ToString())))
- // {
- // DataTable dtStaff = new DataTable(string.Format("TempTable{0}", this._tempcount.ToString()));
- // dtStaff.Columns.Add("IsSelected");
- // dtStaff.Columns.Add("StaffID");
- // dtStaff.Columns.Add("StaffCode");
- // dtStaff.Columns.Add("StaffName");
- // dtStaff.Columns.Add("StaffTempCount");
- // dtStaff.Columns.Add("StaffStatus");
- // this._dsStaff.Tables.Add(dtStaff);
- // }
- // // 获取临时表是否有数据,如果有行,则删除,
- // DataTable dtTemp = this._dsStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())];
- // if (dtTemp != null)
- // {
- // // 清空临时表数据
- // this._dsStaff.Tables[string.Format("TempTable{0}", this._tempcount.ToString())].Clear();
- // }
- //}
- if (this.dropDutyProcedure.SelectedValue != null && this.dropDutyProcedure.SelectedValue.ToString() != "-1")
- {
- if (!this.txtRemarks.ReadOnly)
- {
- string DutyProcedure = this.dropDutyProcedure.SelectedValue.ToString();
- DataTable dtDutyProcedureCode = this.dropDutyProcedure.DataSource as DataTable;
- if (dtDutyProcedureCode.Rows.Count > Constant.INT_IS_ZERO)
- {
- DataRow[] dr = dtDutyProcedureCode.Select("ProcedureID=" + DutyProcedure);
- if (dr.Length > Constant.INT_IS_ZERO)
- {
- this.dropDutyUser.SelectedValue = dr[0]["UserID"].ToString();
- this._currentDefectUserCode = dr[0]["UserCode"].ToString();
- this._currentDefectProcedureCode = dr[0]["ProcedureCode"].ToString();
- this._defectProductionDataID = Convert.ToInt32(dr[0]["ProductionDataID"]);
- // 工号带出所有责任人,默认全部选中
- BindNoProcedureDutyStaff(this._tempcount);
- }
- }
- }
- }
- else
- {
- //默认加载全部生产工号
- this.dropDutyUser.DisplayMember = "UserCode";
- this.dropDutyUser.ValueMember = "UserID";
- this.dropDutyUser.DataSource = this._dtDutyProcedureUser;
- this.dropDutyUser.SelectedValue = -1;
- this._currentDefectProcedureCode = "";
- this._defectProductionDataID = 0;
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 保存按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.dropDuty.SelectedValue == null || this.dropDuty.SelectedValue.ToString() == string.Empty)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (this.dropDefectLocation.SelectedValue == null || this.dropDefectLocation.SelectedValue.ToString() == string.Empty)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "缺陷位置"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (this.dropDutyUser.SelectedValue == null || this.dropDutyUser.SelectedValue.ToString() == "-1")
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "责任工号"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- //if (this.dropJobs.SelectedValue == null || this.dropJobs.SelectedValue.ToString() == string.Empty)
- //{
- // MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "工种"),
- // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- // return;
- //}
- if (dropDutyUser.ListBox != null)
- {
- DataRowView drv = dropDutyUser.ListBox.SelectedItem as DataRowView;
- if (drv != null)
- {
- this._currentDefectUserCode = drv["UserCode"].ToString();
- }
- }
- if (!this._isEdit)
- {
- // 每次添加不能重复
- //if (this._dtBarCode != null && this._dtBarCode.Rows.Count > Constant.INT_IS_ZERO)
- //{
- // DataRow[] drExist = this._dtBarCode.Select(
- // string.Format("DefectID={0} and DefectPositionID={1} and DefectUserID={2}",
- // this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue,
- // this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue,
- // this.dropDutyUser.SelectedValue.ToString() == string.Empty ? 0 : this.dropDutyUser.SelectedValue
- // )
- // );
- // if (drExist.Length > Constant.INT_IS_ZERO)
- // {
- // // 提示信息
- // MessageBox.Show(Messages.MSG_PM_W001,
- // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- // return;
- // }
- //}
- DataRow dr = this._dtBarCode.NewRow();
- dr["BarCode"] = this._dtBarCode;
- dr["DefectID"] = this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue;
- dr["DefectName"] = this.dropDuty.Text;
- dr["DefectCode"] = this._currentDutyCode;
- dr["DefectPositionID"] = this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue;
- dr["DefectPositionName"] = this.dropDefectLocation.Text;
- dr["DefectPositionCode"] = this._currentDefectPositionCode;
- dr["DefectProcedureID"] = (this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : this.dropDutyProcedure.SelectedValue;
- dr["DefectProcedureName"] = this.dropDutyProcedure.Text;
- dr["DefectProcedureCode"] = this._currentDefectProcedureCode;
- dr["DefectUserID"] = this.dropDutyUser.SelectedValue.ToString() == string.Empty ? 0 : this.dropDutyUser.SelectedValue;
- dr["DefectUserName"] = this.dropDutyUser.Text;
- dr["DefectUserCode"] = this._currentDefectUserCode;
- //dr["Jobs"] = this.dropJobs.SelectedValue.ToString() == string.Empty ? 0 : this.dropJobs.SelectedValue;
- //dr["JobsText"] = this.dropJobs.Text;
- dr["DefectRemarks"] = this.txtRemarks.Text;
- dr["TempCount"] = this._tempcount;
- dr["ProductionDataID"] = this._productionDataID;
- dr["ProductionDataID"] = this._defectProductionDataID;
- //if (this.cmbDefectFine.SelectedValue != null && this.cmbDefectFine.SelectedValue.ToString() != "-1")
- //{
- // dr["DefectFineID"] = this.cmbDefectFine.SelectedValue;
- // dr["DefectFineValue"] = this.cmbDefectFine.Text;
- //}
- //else
- //{
- // dr["DefectFineID"] = -1;
- // dr["DefectFineValue"] = string.Empty;
- //}
- //dr["MissedUserID"] = (this.dropMissUser.SelectedValue == null || this.dropMissUser.SelectedValue.ToString() == string.Empty) ? -1 : this.dropMissUser.SelectedValue;
- //dr["MissedUserCode"] = this._currentMissedUserCode;
- //dr["MissedUserName"] = this.dropMissUser.Text;
- dr["IsAllowEdit"] = 1;
- //if (this.cmbDefectDeduction.SelectedValue != null && this.cmbDefectDeduction.SelectedValue.ToString() != "-1")
- //{
- // dr["DefectDeductionID"] = this.cmbDefectDeduction.SelectedValue;
- // dr["DefectDeductionNum"] = this.cmbDefectDeduction.Text;
- //}
- //else
- //{
- // dr["DefectDeductionID"] = -1;
- // dr["DefectDeductionNum"] = string.Empty;
- //}
- //dr["IsOtherDefect"] = this.chkDefect.Checked ? 1 : 0;
- this._dtBarCode.Rows.Add(dr);
- }
- else
- {
- if (this._dtBarCode != null && this._dtBarCode.Rows.Count > Constant.INT_IS_ZERO)
- {
- int currentRowIndex = -1; // 用来匹配是否编辑自己
- for (int i = 0; i < this._dtBarCode.Rows.Count; i++)
- {
- if (Convert.ToInt32(this._dtBarCode.Rows[i]["DefectID"]) ==
- (this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : Convert.ToInt32(this.dropDuty.SelectedValue))
- &&
- Convert.ToInt32(this._dtBarCode.Rows[i]["DefectPositionID"]) ==
- (this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : Convert.ToInt32(this.dropDefectLocation.SelectedValue))
- &&
- Convert.ToInt32(this._dtBarCode.Rows[i]["DefectProcedureID"].ToString() == "" ? 0 : this._dtBarCode.Rows[i]["DefectProcedureID"]) ==
- ((this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : Convert.ToInt32(this.dropDutyProcedure.SelectedValue))
- )
- {
- currentRowIndex = i;
- break;
- }
- }
- if (currentRowIndex != -Constant.INT_IS_ONE && currentRowIndex != this._rowIndex) // 更新后会有重复
- {
- // 提示信息
- MessageBox.Show(Messages.MSG_PM_W001,
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- this._dtBarCode.Rows[this._rowIndex]["BarCode"] = this._dtBarCode;
- this._dtBarCode.Rows[this._rowIndex]["DefectID"] = this.dropDuty.SelectedValue.ToString() == string.Empty ? 0 : this.dropDuty.SelectedValue;
- this._dtBarCode.Rows[this._rowIndex]["DefectName"] = this.dropDuty.Text;
- this._dtBarCode.Rows[this._rowIndex]["DefectCode"] = this._currentDutyCode;
- this._dtBarCode.Rows[this._rowIndex]["DefectPositionID"] = this.dropDefectLocation.SelectedValue.ToString() == string.Empty ? 0 : this.dropDefectLocation.SelectedValue;
- this._dtBarCode.Rows[this._rowIndex]["DefectPositionName"] = this.dropDefectLocation.Text;
- this._dtBarCode.Rows[this._rowIndex]["DefectPositionCode"] = this._currentDefectPositionCode;
- this._dtBarCode.Rows[this._rowIndex]["DefectProcedureID"] = (this.dropDutyProcedure.SelectedValue == null || this.dropDutyProcedure.SelectedValue.ToString() == string.Empty) ? 0 : this.dropDutyProcedure.SelectedValue;
- this._dtBarCode.Rows[this._rowIndex]["DefectProcedureName"] = this.dropDutyProcedure.Text;
- this._dtBarCode.Rows[this._rowIndex]["DefectProcedureCode"] = this._currentDefectProcedureCode;
- this._dtBarCode.Rows[this._rowIndex]["DefectUserID"] = this.dropDutyUser.SelectedValue.ToString() == string.Empty ? 0 : this.dropDutyUser.SelectedValue;
- this._dtBarCode.Rows[this._rowIndex]["DefectUserName"] = this.dropDutyUser.Text;
- this._dtBarCode.Rows[this._rowIndex]["DefectUserCode"] = this._currentDefectUserCode;
- //this._dtBarCode.Rows[this._rowIndex]["Jobs"] = this.dropJobs.SelectedValue.ToString() == string.Empty ? 0 : this.dropJobs.SelectedValue;
- //this._dtBarCode.Rows[this._rowIndex]["JobsText"] = this.dropJobs.Text;
- this._dtBarCode.Rows[this._rowIndex]["DefectRemarks"] = this.txtRemarks.Text;
- this._dtBarCode.Rows[this._rowIndex]["TempCount"] = this._tempcount;
- this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"] = this._productionDataID;
- this._dtBarCode.Rows[this._rowIndex]["ProductionDataID"] = this._defectProductionDataID;
- this._dtBarCode.AcceptChanges();
- }
- // 防止工种不选择的话,直接New一个
- if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", _tempcount.ToString())))
- {
- DataTable dtStaff = new DataTable(string.Format("TempTable{0}", _tempcount.ToString()));
- dtStaff.Columns.Add("IsSelected");
- dtStaff.Columns.Add("StaffID");
- dtStaff.Columns.Add("StaffCode");
- dtStaff.Columns.Add("StaffName");
- dtStaff.Columns.Add("StaffTempCount");
- dtStaff.Columns.Add("StaffStatus");
- dtStaff.Columns.Add("UjobsID");
- dtStaff.Columns.Add("SjobsID");
- this._dsStaff.Tables.Add(dtStaff);
- }
- ////// 防止工种不选择的话,直接New一个
- ////if (!this._dsMissedStaff.Tables.Contains(string.Format("TempTable{0}", _tempcount.ToString())))
- ////{
- //// DataTable dtMissedStaff = new DataTable(string.Format("TempTable{0}", _tempcount.ToString()));
- //// dtMissedStaff.Columns.Add("IsSelected");
- //// dtMissedStaff.Columns.Add("StaffID");
- //// dtMissedStaff.Columns.Add("StaffCode");
- //// dtMissedStaff.Columns.Add("StaffName");
- //// dtMissedStaff.Columns.Add("StaffTempCount");
- //// dtMissedStaff.Columns.Add("StaffStatus");
- //// dtMissedStaff.Columns.Add("UJobsID");
- //// dtMissedStaff.Columns.Add("SJobsID");
- //// this._dsMissedStaff.Tables.Add(dtMissedStaff);
- ////}
- //if (!this._dsImage.Tables.Contains(string.Format("TempTable{0}", this._tempcount.ToString())))
- //{
- // DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._tempcount.ToString()));
- // dtImage.Columns.Add("StaffTempCount");
- // dtImage.Columns.Add("ImageByte", typeof(byte[]));
- // dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
- // this._dsImage.Tables.Add(dtImage);
- //}
- //this._frm1202.BindByteImage(this._dsImage.Tables[string.Format("TempTable{0}", _tempcount.ToString())]);
- this._tempcount = _tempcount + 1;
- this._frm1202.SetDataSource(_tempcount);
- ClearText();
- if (this._isEdit)
- {
- // 保存后如果是编辑进来的,更改后可以继续录入,当前改为插入了
- this._isEdit = false;
- }
- this.Close();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 缺陷位置验证事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dropDefectLocation_Validating(object sender, System.ComponentModel.CancelEventArgs e)
- {
- try
- {
- if (this.dropDefectLocation.SelectedValue != null && this.dropDefectLocation.SelectedValue.ToString() != string.Empty)
- {
- string DefectLocationCode = this.dropDefectLocation.SelectedValue.ToString();
- DataTable dtDefectLocationCode = this.dropDefectLocation.DataSource as DataTable;
- if (dtDefectLocationCode.Rows.Count > Constant.INT_IS_ZERO)
- {
- DataRow[] dr = dtDefectLocationCode.Select("DefectPositionID=" + DefectLocationCode);
- if (dr.Length > Constant.INT_IS_ZERO)
- {
- this._currentDefectPositionCode = dr[0]["DefectPositionCode"].ToString();
- }
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 工号验证事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dropDutyUser_Validating(object sender, System.ComponentModel.CancelEventArgs e)
- {
- try
- {
- if (this.dropDutyUser.SelectedValue != null && this.dropDutyUser.SelectedValue.ToString() != string.Empty)
- {
- if (!this.txtRemarks.ReadOnly)
- {
- string DutyUserID = this.dropDutyUser.SelectedValue.ToString();
- DataTable dtDutyUserCode = this.dropDutyUser.DataSource as DataTable;
- if (dtDutyUserCode.Rows.Count > Constant.INT_IS_ZERO)
- {
- DataRow[] dr = dtDutyUserCode.Select("UserID=" + DutyUserID);
- if (dr.Length > Constant.INT_IS_ZERO)
- {
- this._currentDefectUserCode = dr[0]["UserCode"].ToString();
- }
- }
- BindNoProcedureDutyStaff(this._tempcount);
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 无责任工序下绑定缺陷责任员工
- /// </summary>
- /// <param name="productionDataID">生产数据ID</param>
- /// <param name="userID">用户ID</param>
- /// <param name="jobs">工种ID</param>
- /// <param name="StaffTempCount">唯一标识</param>
- private void BindNoProcedureDutyStaff(int StaffTempCount)
- {
- if (!this._dsStaff.Tables.Contains(string.Format("TempTable{0}", StaffTempCount.ToString())))
- {
- DataTable dtStaff = new DataTable(string.Format("TempTable{0}", StaffTempCount.ToString()));
- dtStaff.Columns.Add("IsSelected");
- dtStaff.Columns.Add("StaffID");
- dtStaff.Columns.Add("StaffCode");
- dtStaff.Columns.Add("StaffName");
- dtStaff.Columns.Add("StaffTempCount");
- dtStaff.Columns.Add("StaffStatus");
- dtStaff.Columns.Add("UjobsID");
- dtStaff.Columns.Add("SjobsID");
- this._dsStaff.Tables.Add(dtStaff);
- }
- // 获取临时表是否有数据,如果有行,则删除,
- DataTable dtTemp = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
- if (dtTemp.Rows.Count > Constant.INT_IS_ZERO)
- {
- // 清空临时表数据
- this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Clear();
- }
- int UserID = Convert.ToInt32(dropDutyUser.SelectedValue);
- DataSet dsDutyStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxy.Service.GetSemiCheckDefectStaffByUserID(UserID);
- }));
- if (dsDutyStaff != null && dsDutyStaff.Tables.Count > Constant.INT_IS_ZERO
- && dsDutyStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- foreach (DataRow dr in dsDutyStaff.Tables[0].Rows)
- {
- DataRow addDr = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].NewRow();
- addDr["IsSelected"] = 1;
- addDr["StaffID"] = dr["StaffID"];
- addDr["StaffCode"] = dr["StaffCode"];
- addDr["StaffName"] = dr["StaffName"];
- addDr["StaffTempCount"] = StaffTempCount;
- addDr["StaffStatus"] = dr["StaffStatus"];
- addDr["UjobsID"] = dr["UjobsID"];
- addDr["SjobsID"] = dr["SjobsID"];
- this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Rows.Add(addDr);
- }
- this.dgvDefectStaff.DataSource = this._dsStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
- }
- }
- /// <summary>
- /// 关闭按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 责任工号数据表 责任工序不选择时,默认数据源
- /// </summary>
- /// <returns></returns>
- private DataTable GetDutyProcedureUser()
- {
- SUserEntity userEntity = new SUserEntity();
- userEntity.IsWorker = 1;//生产工号
- DataSet dsDutyProcedureUser = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.SearchUserData(userEntity);
- }));
- DataRow dr = dsDutyProcedureUser.Tables[0].NewRow();
- dr["UserID"] = -1;
- dr["UserCode"] = "";
- dr["UserName"] = "";
- dsDutyProcedureUser.Tables[0].Rows.InsertAt(dr, 0);
- dsDutyProcedureUser.Tables[0].AcceptChanges();
- this._dtDutyProcedureUser = dsDutyProcedureUser.Tables[0];
- return dsDutyProcedureUser.Tables[0];
- }
- /// <summary>
- /// 保存后界面数据初始化
- /// </summary>
- private void ClearText()
- {
- this.dropDuty.SelectedValue = string.Empty;
- this.dropDuty.Text = string.Empty;
- this.dropDefectLocation.SelectedValue = string.Empty;
- this.dropDefectLocation.Text = string.Empty;
- this.dropDutyProcedure.SelectedValue = null;
- this.dropDutyProcedure.Text = string.Empty;
- this.dropDutyUser.SelectedValue = null;
- this.dropDutyUser.Text = string.Empty;
- //this.dropJobs.SelectedValue = null;
- //this.dropJobs.Text = string.Empty;
- this.txtRemarks.Text = string.Empty;
- this.dgvDefectStaff.DataSource = null;
- //this.cmbDefectFine.SelectedValue = -1;
- //this.dropMissUser.SelectedValue = null;
- //this.dropMissUser.Text = string.Empty;
- }
- /// <summary>
- /// 将图片文件转换成二进制
- /// </summary>
- /// <param name="img"></param>
- /// <returns></returns>
- public static byte[] ImageToByte(Image img)
- {
- byte[] smallbuffer = null;
- using (MemoryStream ms = new MemoryStream())
- {
- img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
- ms.Position = Constant.INT_IS_ZERO;
- smallbuffer = new byte[ms.Length];
- ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
- ms.Flush();
- }
- return smallbuffer;
- }
- /// <SUMMARY>
- /// 重绘缩略图并把缩略图转为二进制储存
- /// </SUMMARY>
- /// <PARAM name="sourceFile">图片源路径</PARAM>
- /// <PARAM name="destHeight">缩放后图片高度</PARAM>
- /// <PARAM name="destWidth">缩放后图片宽度</PARAM>
- /// <RETURNS></RETURNS>
- public void GetThumbnail(FileInfo sourceFile, byte[] orgImageByte)
- {
- Image imgSource = Image.FromStream(sourceFile.OpenRead());
- ImageFormat thisFormat = imgSource.RawFormat;
- int sW = 0, sH = 0;
- // 按比例缩放
- int sWidth = imgSource.Width;
- int sHeight = imgSource.Height;
- int destWidth = 100;
- int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
- if (sHeight > destHeight || sWidth > destWidth)
- {
- if ((sWidth * destHeight) > (sHeight * destWidth))
- {
- sW = destWidth;
- sH = (destWidth * sHeight) / sWidth;
- }
- else
- {
- sH = destHeight;
- sW = (sWidth * destHeight) / sHeight;
- }
- }
- else
- {
- sW = sWidth;
- sH = sHeight;
- }
- Bitmap outBmp = new Bitmap(destWidth, destHeight);
- Graphics g = Graphics.FromImage(outBmp);
- g.Clear(Color.Black);
- // 设置画布的描绘质量
- g.CompositingQuality = CompositingQuality.HighQuality;
- g.SmoothingMode = SmoothingMode.HighQuality;
- g.InterpolationMode = InterpolationMode.HighQualityBicubic;
- g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
- g.Dispose();
- //将重绘的图片转为二进制并保存
- Image image = (Image)outBmp;
- byte[] smallbuffer = ImageToByte(image);
- DataRow dr = this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].NewRow();
- dr["StaffTempCount"] = this._tempcount;
- dr["ImageByte"] = smallbuffer;
- dr["OrgImageByte"] = orgImageByte;
- this._dsImage.Tables[string.Format("TempTable{0}", this._tempcount)].Rows.Add(dr);
- this._smallByte.Add(smallbuffer);
- imgSource.Dispose();
- outBmp.Dispose();
- }
- /// <summary>
- /// 根据原图片宽高比获取缩略图的高(根据宽)
- /// </summary>
- /// <param name="BigWidth"></param>
- /// <param name="BigHeight"></param>
- /// <param name="SmallWidth"></param>
- /// <returns></returns>
- protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
- {
- decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
- return Convert.ToInt32(SmallWidth / scale);
- }
- /// <summary>
- /// 绑定缩略图到控件中
- /// </summary>
- protected void BindImg()
- {
- ImageList ilPic = new ImageList();
- //每次绑定要清空数据源
- ilPic.Images.Clear();
- //将缩略图二进制集合中的数据转换成图片文件
- List<Image> LSImageList = new List<Image>();
- foreach (byte[] smallby in _smallByte)
- {
- LSImageList.Add(byteArrayToImage(smallby));
- }
- //添加数据源
- foreach (Image img in LSImageList)
- {
- ilPic.Images.Add(img);
- }
- ilPic.ImageSize = new Size(100, 100);
- }
- /// <summary>
- /// 将数据库中的二进制转换成图片
- /// </summary>
- /// <param name="data"></param>
- /// <returns></returns>
- public static Image byteArrayToImage(object data)
- {
- System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
- System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
- return returnImage;
- }
- /// <summary>
- /// 绑定并显示图片
- /// </summary>
- /// <param name="ImageData"></param>
- private void BindByteImage(DataTable ImageData)
- {
- this._smallByte.Clear();
- foreach (DataRow dr in ImageData.Rows)
- {
- //将数据库中的缩略图取出
- this._smallByte.Add((byte[])dr[1]);
- }
- //绑定缩略图
- BindImg();
- }
- /// <summary>
- /// 根据漏检工号绑定漏检责任员工
- /// </summary>
- /// <param name="jobs">工种ID</param>
- /// <param name="StaffTempCount">唯一标识</param>
- private void BindMissedDutyStaff(int userid, int StaffTempCount)
- {
- if (!this._dsMissedStaff.Tables.Contains(string.Format("TempTable{0}", StaffTempCount.ToString())))
- {
- DataTable dtMissedStaff = new DataTable(string.Format("TempTable{0}", StaffTempCount.ToString()));
- dtMissedStaff.Columns.Add("IsSelected");
- dtMissedStaff.Columns.Add("StaffID");
- dtMissedStaff.Columns.Add("StaffCode");
- dtMissedStaff.Columns.Add("StaffName");
- dtMissedStaff.Columns.Add("StaffTempCount");
- dtMissedStaff.Columns.Add("StaffStatus");
- dtMissedStaff.Columns.Add("UJobsID");
- dtMissedStaff.Columns.Add("SJobsID");
- this._dsMissedStaff.Tables.Add(dtMissedStaff);
- }
- // 获取临时表是否有数据,如果有行,则删除,
- DataTable dtTemp = this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())];
- if (dtTemp.Rows.Count > Constant.INT_IS_ZERO)
- {
- // 清空临时表数据
- this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Clear();
- }
- DataSet dsMissedDutyStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return PMModuleProxy.Service.GetMissedStaffByUserID(userid);
- }));
- if (dsMissedDutyStaff != null && dsMissedDutyStaff.Tables.Count > Constant.INT_IS_ZERO
- && dsMissedDutyStaff.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- foreach (DataRow dr in dsMissedDutyStaff.Tables[0].Rows)
- {
- DataRow addDr = this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].NewRow();
- addDr["IsSelected"] = 1;
- addDr["StaffID"] = dr["StaffID"];
- addDr["StaffCode"] = dr["StaffCode"];
- addDr["StaffName"] = dr["StaffName"];
- addDr["StaffTempCount"] = StaffTempCount;
- addDr["StaffStatus"] = dr["StaffStatus"];
- addDr["UJobsID"] = dr["UJobsID"];
- addDr["SJobsID"] = dr["SJobsID"];
- this._dsMissedStaff.Tables[string.Format("TempTable{0}", StaffTempCount.ToString())].Rows.Add(addDr);
- }
- }
- }
- #endregion
- }
- }
|