/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PM_1302.cs
* 2.功能描述:新建入窑前检验-新建、编辑
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2014/10/11 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.Client.Controls.FormCommon;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.PMModuleService;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
namespace Dongke.IBOSS.PRD.Client.PMModule
{
///
/// 新建入窑前检验-新建、编辑
///
public partial class F_PM_1302 : FormBase
{
#region 成员变量
// 工序ID
private int _procedureID;
// 生产工号
private int _userID = -1;
// 生产编号
private string _userCode;
// 生产名称
private string _userName;
// 工序实体类
ProcedureEntity _procedureDataEntity;
// 产品数据表
DataTable _dtProductionData = null;
// 产品缺陷数据表
DataTable _dtProductionDefectData = null;
// 当前选择的行
private int _selectedRowIndex;
// ComBoxEditingControl
private DataGridViewComboBoxEditingControl _dataGridViewComboBox = null;
// 当前产品条码的产品ID,用来查询缺陷位置
private int _currentGoodsID = 0;
// 当前产品条码,用来切换筛选列表数据
private string _currentBarCode = "";
// 当前产品缺陷
private int _currentDefectFlag = 0;
// 返工工序搜索列表对象
C_DGV_Cell_ListBoxComboBox _C_DGV_Cell_ListBoxComboBox = null;
// 过滤结果集
private DataSet _ds = null;
// 过滤员工结果集
private DataSet _dsStaff = null;
// 过滤缺陷图片
private DataSet _dsImage = null;
// 临时数,用来过滤责任员工数据源标识
private int _tempCount = 0;
// 当前临时标记
private string _currentTempSign = "";
// 图片字节集
private List _PicByte = new List();
// 缩略图片字节集
private List _smallByte = new List();
// 当前产品缺陷
private int _currentDefaultDefectFlag = 0;
// 当前默认产品分级ID
private int _currentGoodsLevelTypeID = 0;
// 返工工序数据源
private DataSet _dsRework = null;
// 产品等级数据源
private DataSet _dsGoodsLevel = null;
// 生产数据ID
private int? _productionDataID = null;
// 过滤漏检员工结果集
private DataSet _dsMissdeStaff = null;
#endregion
#region 属性
///
/// 条码返工工序数据源
///
public DataSet DSREWORK
{
set
{
_dsRework = value;
}
get
{
if (_dsRework == null)
{
return _dsRework = new DataSet();
}
return _dsRework;
}
}
///
/// 生产工号
///
public int UserID
{
set
{
_userID = value;
}
get
{
return _userID;
}
}
///
/// 生产编号
///
public string UserCode
{
set
{
_userCode = value;
}
get
{
return _userCode;
}
}
///
/// 用户名称
///
public string UserName
{
set
{
_userName = value;
}
get
{
return _userName;
}
}
///
/// 产品数据表
///
public DataTable TableProductionData
{
set
{
_dtProductionData = value;
}
get
{
if (_dtProductionData == null)
{
_dtProductionData = new DataTable("ProductionData");
_dtProductionData.Columns.Add("ProductionDataID");
_dtProductionData.Columns.Add("BarCode");
_dtProductionData.Columns.Add("GoodsID");
_dtProductionData.Columns.Add("GoodsCode");
_dtProductionData.Columns.Add("GoodsName");
_dtProductionData.Columns.Add("DefectFlagID", typeof(decimal));
_dtProductionData.Columns.Add("ReworkProcedureID", typeof(decimal));
_dtProductionData.Columns.Add("Remarks");
_dtProductionData.Columns.Add("UserID");
_dtProductionData.Columns.Add("KilnCarCode");
_dtProductionData.Columns.Add("KilnCode");
_dtProductionData.Columns.Add("Dictionaryvalue");
_dtProductionData.Columns.Add("GoodsLevelTypeID");
_dtProductionData.Columns.Add("ReFine");//重烧标识
_dtProductionData.Columns.Add("SpecialRepairflag");//干补标识
_dtProductionData.Columns.Add("SpecialRepairflagValue");//干补标识
_dtProductionData.Columns.Add("UserCode");//生产工号
_dtProductionData.Columns.Add("MouldCode");//模具编号
_dtProductionData.Columns.Add("GroutingDate", typeof(DateTime));//注浆日期
_dtProductionData.Columns.Add("GroutingUserCode");//成型工号
_dtProductionData.Columns.Add("IsPublicBody");//公坯标识
_dtProductionData.Columns.Add("GroutingNum");//注浆次数
_dtProductionData.Columns.Add("LogoID");//
_dtProductionData.Columns.Add("LogoCodeName");//
return _dtProductionData;
}
else
{
return _dtProductionData;
}
}
}
///
/// 产品缺陷表
///
public DataTable TableProductionDefectData
{
set
{
_dtProductionDefectData = value;
}
get
{
if (_dtProductionDefectData == null)
{
_dtProductionDefectData = new DataTable("ProductionDefectData");
_dtProductionDefectData.Columns.Add("ProductionBarCode");
_dtProductionDefectData.Columns.Add("DefectFlag", typeof(decimal));
_dtProductionDefectData.Columns.Add("DefectLocation", typeof(decimal));
_dtProductionDefectData.Columns.Add("DutyProcedureUserID", typeof(decimal));
_dtProductionDefectData.Columns.Add("DutyUserCode");
_dtProductionDefectData.Columns.Add("DefectRemarks");
return _dtProductionDefectData;
}
else
{
return _dtProductionDefectData;
}
}
}
///
/// 缺陷数据集
///
public DataSet DSTable
{
set
{
_ds = value;
}
get
{
if (_ds == null)
{
_ds = new DataSet();
return _ds;
}
else
{
return _ds;
}
}
}
///
/// 员工数据集
///
public DataSet DSTableStaff
{
set
{
_dsStaff = value;
}
get
{
if (_dsStaff == null)
{
_dsStaff = new DataSet();
return _dsStaff;
}
else
{
return _dsStaff;
}
}
}
///
/// 漏检员工数据集
///
public DataSet DSTableMissedStaff
{
set
{
_dsMissdeStaff = value;
}
get
{
if (_dsMissdeStaff == null)
{
_dsMissdeStaff = new DataSet();
return _dsMissdeStaff;
}
else
{
return _dsMissdeStaff;
}
}
}
///
/// 缺陷图片
///
public DataSet DSTableImage
{
set
{
_dsImage = value;
}
get
{
if (_dsImage == null)
{
_dsImage = new DataSet();
return _dsImage;
}
else
{
return _dsImage;
}
}
}
#endregion
#region 构造函数
public F_PM_1302()
{
InitializeComponent();
}
public F_PM_1302(int procedureID, string fromTitle)
{
InitializeComponent();
this._procedureID = procedureID;
this.Text = fromTitle;
this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
this.tsbtnClose.Text = ButtonText.TSBTN_TOOL_CLOSE;
this.btnUpload.Text = ButtonText.BTN_UPLOAD;
this.btnDelete.Text = ButtonText.BTN_DELETE;
}
public F_PM_1302(int procedureID, string fromTitle, int ProductionDataID)
{
InitializeComponent();
this._procedureID = procedureID;
this._productionDataID = ProductionDataID;
this.Text = fromTitle;
this.tsbtnAdd.Text = ButtonText.TSBTN_ADD;
this.tsbtnEdit.Text = ButtonText.TSBTN_EDIT;
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
this.tsbtnClose.Text = ButtonText.TSBTN_TOOL_CLOSE;
this.btnUpload.Text = ButtonText.BTN_UPLOAD;
this.btnDelete.Text = ButtonText.BTN_DELETE;
}
#endregion
#region 事件
///
/// 窗体加载事件
///
///
///
private void F_PM_1302_Load(object sender, System.EventArgs e)
{
try
{
this.dgvProductionData.AutoGenerateColumns = false;
this.dgvProductionData.DataSource = TableProductionData;
this.dgvDefect.AutoGenerateColumns = false;
this.dgvDefectStaff.AutoGenerateColumns = false;
// 加载权限
FormPermissionManager.FormPermissionControl(this.Name, this,
Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
// 获取工序明细数据
ProcedureEntity procedureDataEntity = (ProcedureEntity)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.GetProcedureDataEntityByID(this._procedureID);
}));
this._procedureDataEntity = procedureDataEntity;
// 缺陷数据源
DataSet dsGoodsLevel = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetGoodsLevel(1);//半成品检验
}));
if (dsGoodsLevel != null && dsGoodsLevel.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
this._dsGoodsLevel = dsGoodsLevel;
}
// 设置控件禁用或启用
SetControlEnable();
#region wangx 2012-12-28 add
if (this._productionDataID != null)
{
//加载数据源
this.txtUserCode.Enabled = false;
this.txtBarCode.Enabled = false;
this.tsbtnAdd.Enabled = true;
// 此工号是否能生产工序
CheckProcedureUserResult checkProcedureUser = (CheckProcedureUserResult)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.CheckProcedureUser(this._procedureID,
Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserCode);
}));
if (checkProcedureUser != null)
{
if (!string.IsNullOrEmpty(checkProcedureUser.ErrMsg))
{
// 此工号不允许生产工序
MessageBox.Show(checkProcedureUser.ErrMsg,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.Close();
return;
}
}
UserID = checkProcedureUser.UserID;
UserCode = checkProcedureUser.UserCode;
UserName = checkProcedureUser.UserName;
this.txtUserCode.Text = UserCode;
DataSet dsProductionDataByID = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.GetProductionDataByID(Convert.ToInt32(this._productionDataID));
}));
if (dsProductionDataByID != null && dsProductionDataByID.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
// 干补标识
int SpecialRepairflag = (int)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.GetSpecialRepairflagByBarcode(dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString());
}));
// 产品数据
DataRow drNew = TableProductionData.NewRow();
drNew["ProductionDataID"] = this._productionDataID;
drNew["BarCode"] = dsProductionDataByID.Tables[0].Rows[0]["BarCode"];
drNew["GoodsID"] = dsProductionDataByID.Tables[0].Rows[0]["GoodsID"];
drNew["GoodsCode"] = dsProductionDataByID.Tables[0].Rows[0]["GoodsCode"];
drNew["GoodsName"] = dsProductionDataByID.Tables[0].Rows[0]["GoodsName"];
drNew["DefectFlagID"] = dsProductionDataByID.Tables[0].Rows[0]["DefectFlagID"];
drNew["ReworkProcedureID"] = dsProductionDataByID.Tables[0].Rows[0]["ReworkProcedureID"];
drNew["Remarks"] = dsProductionDataByID.Tables[0].Rows[0]["Remarks"];
drNew["UserID"] = dsProductionDataByID.Tables[0].Rows[0]["UserID"];
drNew["KilnCarCode"] = dsProductionDataByID.Tables[0].Rows[0]["KilnCarCode"];
drNew["KilnCode"] = dsProductionDataByID.Tables[0].Rows[0]["KilnCode"];
drNew["Dictionaryvalue"] = dsProductionDataByID.Tables[0].Rows[0]["Dictionaryvalue"];
drNew["GoodsLevelTypeID"] = dsProductionDataByID.Tables[0].Rows[0]["GoodsLevelTypeID"];
drNew["ReFine"] = 0;
drNew["SpecialRepairflag"] = SpecialRepairflag.ToString() == "1" ? 1 : 0;
drNew["UserCode"] = dsProductionDataByID.Tables[0].Rows[0]["UserCode"];
drNew["MouldCode"] = dsProductionDataByID.Tables[0].Rows[0]["MouldCode"];
drNew["GroutingDate"] = Convert.ToDateTime(dsProductionDataByID.Tables[0].Rows[0]["GroutingDate"]);
drNew["GroutingUserCode"] = dsProductionDataByID.Tables[0].Rows[0]["GroutingUserCode"];
drNew["IsPublicBody"] = dsProductionDataByID.Tables[0].Rows[0]["IsPublicBody"].ToString() != "1" ? 0 : 1;
drNew["GroutingNum"] = dsProductionDataByID.Tables[0].Rows[0]["GroutingNum"];
drNew["LogoCodeName"] = dsProductionDataByID.Tables[0].Rows[0]["LogoName"] + "[" + dsProductionDataByID.Tables[0].Rows[0]["LogoCode"] + "]";
drNew["LogoId"] = dsProductionDataByID.Tables[0].Rows[0]["LogoId"];
TableProductionData.Rows.Add(drNew);
this.dgvProductionData.Rows[TableProductionData.Rows.Count - 1].Selected = true;
this._selectedRowIndex = TableProductionData.Rows.Count - 1;
this._currentBarCode = dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString();
this._currentGoodsID = Convert.ToInt32(dsProductionDataByID.Tables[0].Rows[0]["GoodsID"]);
if (DSTable.Tables.IndexOf(dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString()) == -Constant.INT_IS_ONE)
{
DataTable dtProductionDefectData = new DataTable(dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString());
dtProductionDefectData.Columns.Add("BarCode");
dtProductionDefectData.Columns.Add("discarde");
dtProductionDefectData.Columns.Add("DefectID", typeof(decimal));
dtProductionDefectData.Columns.Add("DefectName");
dtProductionDefectData.Columns.Add("DefectCode");
dtProductionDefectData.Columns.Add("DefectPositionID", typeof(decimal));
dtProductionDefectData.Columns.Add("DefectPositionName");
dtProductionDefectData.Columns.Add("DefectPositionCode");
dtProductionDefectData.Columns.Add("DefectProcedureID", typeof(decimal));
dtProductionDefectData.Columns.Add("DefectProcedureName");
dtProductionDefectData.Columns.Add("DefectProcedureCode");
dtProductionDefectData.Columns.Add("DefectUserID", typeof(decimal));//责任员工
dtProductionDefectData.Columns.Add("DefectUserName");//责任员工
dtProductionDefectData.Columns.Add("DefectUserCode");//
dtProductionDefectData.Columns.Add("Jobs", typeof(decimal));//工种
dtProductionDefectData.Columns.Add("JobsText");//工种
dtProductionDefectData.Columns.Add("DefectRemarks");
dtProductionDefectData.Columns.Add("TempCount");
dtProductionDefectData.Columns.Add("ProductionDataID"); //生产数据ID
dtProductionDefectData.Columns.Add("DefectFineID"); //缺陷扣罚ID
dtProductionDefectData.Columns.Add("DefectFineValue"); //缺陷扣罚
dtProductionDefectData.Columns.Add("MissedUserID"); //漏检工号ID
dtProductionDefectData.Columns.Add("MissedUserCode"); //漏检工号编码
dtProductionDefectData.Columns.Add("MissedUserName"); //漏检工号名称
dtProductionDefectData.Columns.Add("IsAllowEdit"); //是否允许编辑 0 不允许,1允许
dtProductionDefectData.Columns.Add("CheckTime"); //缺陷检验时间
DSTable.Tables.Add(dtProductionDefectData);
}
for (int i = 0; i < dsProductionDataByID.Tables[1].Rows.Count; i++)
{
DataRow dr = DSTable.Tables[dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString()].NewRow();
dr["BarCode"] = dsProductionDataByID.Tables[1].Rows[i]["BarCode"];
dr["DefectID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectID"];
dr["DefectName"] = dsProductionDataByID.Tables[1].Rows[i]["DefectName"];
dr["DefectCode"] = dsProductionDataByID.Tables[1].Rows[i]["DefectCode"];
dr["DefectPositionID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectPositionID"];
dr["DefectPositionName"] = dsProductionDataByID.Tables[1].Rows[i]["DefectPositionName"];
dr["DefectPositionCode"] = dsProductionDataByID.Tables[1].Rows[i]["DefectPositionCode"];
dr["DefectProcedureID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectProcedureID"];
dr["DefectProcedureName"] = dsProductionDataByID.Tables[1].Rows[i]["DefectProcedureName"];
dr["DefectProcedureCode"] = dsProductionDataByID.Tables[1].Rows[i]["DefectProcedureCode"];
dr["DefectUserID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectUserID"];
dr["DefectUserName"] = dsProductionDataByID.Tables[1].Rows[i]["DefectUserName"];
dr["DefectUserCode"] = dsProductionDataByID.Tables[1].Rows[i]["DefectUserCode"];
dr["Jobs"] = dsProductionDataByID.Tables[1].Rows[i]["Jobs"];
dr["JobsText"] = dsProductionDataByID.Tables[1].Rows[i]["JobsText"];
dr["DefectRemarks"] = dsProductionDataByID.Tables[1].Rows[i]["DefectRemarks"];
dr["TempCount"] = this._tempCount;
dr["ProductionDataID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectProductionDataID"];// dsProductionDataByID.Tables[1].Rows[i]["ProductionDataID"];
dr["DefectFineID"] = dsProductionDataByID.Tables[1].Rows[i]["DefectFineID"];
dr["DefectFineValue"] = dsProductionDataByID.Tables[1].Rows[i]["DefectFineValue"];
dr["MissedUserID"] = dsProductionDataByID.Tables[1].Rows[i]["MissedUserID"];
dr["MissedUserCode"] = dsProductionDataByID.Tables[1].Rows[i]["MissedUserCode"];
dr["MissedUserName"] = dsProductionDataByID.Tables[1].Rows[i]["MissedUserName"];
dr["IsAllowEdit"] = 1;
dr["CheckTime"] = Convert.ToDateTime(dsProductionDataByID.Tables[1].Rows[i]["CheckTime"]);
DSTable.Tables[dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString()].Rows.Add(dr);
// 防止工种不选择的话,直接New一个
if (!this.DSTableStaff.Tables.Contains(string.Format("TempTable{0}", this._tempCount)))
{
DataTable dtStaff = new DataTable(string.Format("TempTable{0}", this._tempCount));
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.DSTableStaff.Tables.Add(dtStaff);
}
// 责任员工
DataRow[] drRow = dsProductionDataByID.Tables[2].Select("ProductionDefectID=" + dsProductionDataByID.Tables[1].Rows[i]["ProductionDefectID"]);
if (drRow.Length > Constant.INT_IS_ZERO)
{
foreach (DataRow r in drRow)
{
DataRow drStaff = this.DSTableStaff.Tables[string.Format("TempTable{0}", this._tempCount)].NewRow();
drStaff["IsSelected"] = 1;
drStaff["StaffID"] = r["StaffID"];
drStaff["StaffCode"] = r["StaffCode"];
drStaff["StaffName"] = r["StaffName"];
drStaff["StaffTempCount"] = this._tempCount;
drStaff["StaffStatus"] = r["StaffStatus"];
this.DSTableStaff.Tables[string.Format("TempTable{0}", this._tempCount)].Rows.Add(drStaff);
}
}
// 漏检员工临时表
if (!this.DSTableMissedStaff.Tables.Contains(string.Format("TempTable{0}", this._tempCount)))
{
DataTable dtMissedStaff = new DataTable(string.Format("TempTable{0}", this._tempCount));
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.DSTableMissedStaff.Tables.Add(dtMissedStaff);
}
//漏检员工临时表数据
DataRow[] drMissedRow = dsProductionDataByID.Tables[4].Select("ProductionDefectID=" + dsProductionDataByID.Tables[1].Rows[i]["ProductionDefectID"]);
if (drMissedRow.Length > Constant.INT_IS_ZERO)
{
foreach (DataRow r in drMissedRow)
{
DataRow drMissedStaff = this.DSTableMissedStaff.Tables[string.Format("TempTable{0}", this._tempCount)].NewRow();
drMissedStaff["IsSelected"] = 1;
drMissedStaff["StaffID"] = r["StaffID"];
drMissedStaff["StaffCode"] = r["StaffCode"];
drMissedStaff["StaffName"] = r["StaffName"];
drMissedStaff["StaffTempCount"] = this._tempCount;
drMissedStaff["StaffStatus"] = r["StaffStatus"];
drMissedStaff["UJobsID"] = r["UJobsID"];
drMissedStaff["SJobsID"] = r["SJobsID"];
this.DSTableMissedStaff.Tables[string.Format("TempTable{0}", this._tempCount)].Rows.Add(drMissedStaff);
}
}
if (!this.DSTableImage.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.DSTableImage.Tables.Add(dtImage);
}
this._currentTempSign = i.ToString();
// 缺陷图片
DataRow[] drImageRow = dsProductionDataByID.Tables[3].Select("ProductionDefectID=" + dsProductionDataByID.Tables[1].Rows[i]["ProductionDefectID"]);
if (drImageRow.Length > Constant.INT_IS_ZERO)
{
foreach (DataRow r in drImageRow)
{
if (r["SourcePathByte"] != DBNull.Value)
{
byte[] orgImageByte = (byte[])r["SourcePathByte"];
this._PicByte.Add(orgImageByte);
//this._smallByte.Add(orgImageByte);
if (!this.DSTableImage.Tables.Contains(string.Format("TempTable{0}", this._currentTempSign.ToString())))
{
DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._currentTempSign.ToString()));
dtImage.Columns.Add("StaffTempCount");
dtImage.Columns.Add("ImageByte", typeof(byte[]));
dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
this.DSTableImage.Tables.Add(dtImage);
}
DataRow drrow = DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].NewRow();
drrow["StaffTempCount"] = this._currentTempSign;
drrow["ImageByte"] = orgImageByte;
drrow["OrgImageByte"] = orgImageByte;
DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].Rows.Add(drrow);
BindImg();
}
}
}
this._tempCount = this._tempCount + 1;
}
this.dgvDefect.DataSource = DSTable.Tables[dsProductionDataByID.Tables[0].Rows[0]["BarCode"].ToString()];//根据条码产生不同数据源
}
}
#endregion wangx 2012-12-28 add end
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 设置控件禁用或启用
///
private void SetControlEnable()
{
if (this._procedureDataEntity != null)
{
if (this._procedureDataEntity.CollectType == (int)Constant.ProcedureCollectType.Togather)
{
this.txtUserCode.Enabled = true;
this.btnSave.Visible = true;
}
else
{
this.txtUserCode.Enabled = true;
this.txtUserCode.ReadOnly = true;
// 此工号是否能生产工序
CheckProcedureUserResult checkProcedureUser = (CheckProcedureUserResult)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.CheckProcedureUser(this._procedureID,
Dongke.IBOSS.PRD.Client.DataModels.LogInUserInfo.CurrentUser.CurrentUserEntity.UserCode);
}));
if (checkProcedureUser != null)
{
if (!string.IsNullOrEmpty(checkProcedureUser.ErrMsg))
{
// 此工号不允许生产工序
MessageBox.Show(checkProcedureUser.ErrMsg,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.Close();
return;
}
}
UserID = checkProcedureUser.UserID;
UserCode = checkProcedureUser.UserCode;
UserName = checkProcedureUser.UserName;
}
this.txtUserCode.Text = UserCode;
}
}
///
/// 条形码按键事件
///
///
///
private void txtBarCode_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if (this.txtBarCode.ReadOnly)
{
return;
}
if ((int)e.KeyChar == 13) // 按了回车键
{
if (this.txtUserCode.Text.Trim() == string.Empty)
{
this.txtUserCode.Focus();
this.txtBarCode.Text = string.Empty;
return;
}
if (this.txtBarCode.Text.Trim() == string.Empty)
{
this.txtBarCode.Focus();
return;
}
// 校验条码 获取校验条码信
DataSet dsCheckBarcode = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.CheckBarcode(this._procedureID, this.txtBarCode.Text.Trim());
}));
if (dsCheckBarcode != null && dsCheckBarcode.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
if (dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString() != string.Empty)
{
// 表示有错误
//MessageBox.Show(string.Format(dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString(), this.txtBarCode.Text.Trim(), "产品条码"),
// this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
//this.txtBarCode.Focus();
//return;
if (dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_missFlag.ToString()].ToString() == "0")
{
// 表示有错误
MessageBox.Show(string.Format(dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString(), this.txtBarCode.Text.Trim(), "产品条码"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
S_CMN_020 frmscmn020 = new S_CMN_020(Convert.ToInt32(dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_missFlag.ToString()])
, dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_errMsg.ToString()].ToString());
frmscmn020.ShowDialog();
}
this.txtBarCode.Focus();
this.txtBarCode.SelectAll();
return;
}
else
{
BindProductionData(dsCheckBarcode);
this._currentBarCode = txtBarCode.Text.Trim();
this.txtBarCode.Text = string.Empty;
}
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 生产数据下拉列表改变事件
///
///
///
private void dataGridViewComboBox_SelectionChangeCommitted(object sender, EventArgs e)
{
this._currentDefectFlag = Convert.ToInt32(((ComboBox)sender).SelectedValue.ToString());//当前缺陷类型
SetGridView(Convert.ToInt32(((ComboBox)sender).SelectedValue.ToString()));
}
///
/// 产品数据单元格进入事件
///
///
///
private void dgvProductionData_CellEnter(object sender, DataGridViewCellEventArgs e)
{
try
{
if (this.dgvProductionData.CurrentCell != null)
{
// 记录最后选择行
this._selectedRowIndex = this.dgvProductionData.CurrentCell.RowIndex;
this._currentBarCode = this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString();
this._C_DGV_Cell_ListBoxComboBox = dgvProductionData.Rows[_selectedRowIndex].Cells[4] as C_DGV_Cell_ListBoxComboBox;
DataSet ds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.GetReworkProcedureByBarcode(this._procedureID, this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString());
}));
this._currentGoodsID = Convert.ToInt32(this.dgvProductionData.Rows[_selectedRowIndex].Cells["GoodsID"].Value);
this._currentBarCode = this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString();
this._C_DGV_Cell_ListBoxComboBox.DisplayMember = "ReworkProcedureName";
this._C_DGV_Cell_ListBoxComboBox.ValueMember = "ReworkProcedureID";
this._C_DGV_Cell_ListBoxComboBox.DataSource = ds.Tables[0];
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 产品数据选定项改变事件
///
///
///
private void dgvProductionData_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvProductionData.CurrentCell != null)
{
this._selectedRowIndex = this.dgvProductionData.CurrentCell.RowIndex;
// 有无缺陷 0无缺陷 1有缺陷
this._currentDefectFlag = Convert.ToInt32(this.dgvProductionData.Rows[_selectedRowIndex].Cells["DefectFlag"].Value.ToString());
this._currentGoodsID = Convert.ToInt32(this.dgvProductionData.Rows[_selectedRowIndex].Cells["GoodsID"].Value);
this._currentBarCode = this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString();
this.dgvDefect.DataSource = DSTable.Tables[this._currentBarCode];
this.dgvDefectStaff.CurrentCell = null;
this.dgvDefectStaff.DataSource = null;
this._smallByte.Clear();//防止重复绑定图片
this.lvPic.Clear();//
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 缺陷数据源选定项改变事件
///
///
///
private void dgvDefect_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvDefect.CurrentCell != null)
{
this.tsbtnEdit.Enabled = true;
if (this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString() != string.Empty)
{
int staffTempCount = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString());
this.dgvDefectStaff.DataSource = DSTableStaff.Tables[string.Format("TempTable{0}", staffTempCount.ToString())];
this._currentTempSign = this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString(); //当前临时标记
this._smallByte.Clear();//防止重复绑定图片
BindByteImage(DSTableImage.Tables[string.Format("TempTable{0}", staffTempCount.ToString())]);
}
else
{
this.dgvDefectStaff.DataSource = null;
this._smallByte.Clear();//防止重复绑定图片
this.lvPic.Clear();//
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 单元格CheckBox事件
///
///
///
private void dgvDefect_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == Constant.INT_IS_ZERO && e.RowIndex != -Constant.INT_IS_ONE)
{
int checkValue = Convert.ToInt32(this.dgvDefect.Rows[e.RowIndex].Cells[0].EditedFormattedValue);
if (checkValue == Constant.INT_IS_ZERO)
{
SetCheckBoxSelected(checkValue, e.RowIndex);
}
else
{
this.dgvDefect.Rows[e.RowIndex].Cells[0].Value = 0;
}
}
}
///
/// 上传图片按钮事件
///
///
///
private void btnUpload_Click(object sender, EventArgs e)
{
try
{
this.odlgFile.Filter = Constant.FILTER_PIC;
this.odlgFile.FilterIndex = Constant.INT_IS_ZERO;
this.odlgFile.RestoreDirectory = true;
this.odlgFile.Title = "选择缺陷图片";
this.odlgFile.FileName = null;
this.odlgFile.RestoreDirectory = true;
if (this.odlgFile.ShowDialog() == DialogResult.OK)
{
FileInfo file = new FileInfo(odlgFile.FileName);
if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "缺陷图片", "大小", "1M"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
Image PicImage = Image.FromStream(file.OpenRead());
byte[] orgImageByte = ImageToByte(PicImage);
this._PicByte.Add(orgImageByte);
GetThumbnail(file, orgImageByte);
BindImg();
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 删除图片按钮事件
///
///
///
private void btnDelete_Click(object sender, EventArgs e)
{
foreach (ListViewItem lvSelect in lvPic.SelectedItems)
{
int index = lvSelect.Index;
if (index < Constant.INT_IS_ZERO)
{
index = Constant.INT_IS_ZERO;
}
if (this._currentTempSign != string.Empty)
{
DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].Rows.RemoveAt(lvSelect.Index);
DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].AcceptChanges();
}
BindByteImage(DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)]);
}
}
///
/// 关闭按钮事件
///
///
///
private void tsbtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 产品条码列表删除事件
///
///
///
private void dgvProductionData_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
try
{
string BarCode = this.dgvProductionData.Rows[e.Row.Index].Cells["BarCode"].Value.ToString();
DSTable.Tables[BarCode].Rows.Clear();//清空行
this.dgvDefectStaff.DataSource = null;
this.lvPic.Clear();
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 产品缺陷删除行事件
///
///
///
private void dgvDefect_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
try
{
string TempCount = this.dgvDefect.Rows[e.Row.Index].Cells["TempCount"].Value.ToString();
DSTableStaff.Tables[string.Format("TempTable{0}", TempCount.ToString())].Rows.Clear();//清空行
this.dgvDefectStaff.DataSource = null;
this.lvPic.Clear();
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 新建按钮事件
///
///
///
private void tsbtnAdd_Click(object sender, EventArgs e)
{
if (this.TableProductionData.Rows.Count > 0)
{
F_PM_1303 frm1303 = new F_PM_1303(
DSTable.Tables[this._currentBarCode], this._currentBarCode,
this._currentGoodsID, this._tempCount, this._procedureID, this.Text, false, this, this.DSTableStaff, this.DSTableImage, this._PicByte, this._smallByte, -1);
frm1303.ShowDialog();
}
}
///
/// 编辑按钮事件
///
///
///
private void tsbtnEdit_Click(object sender, EventArgs e)
{
if (this.dgvDefect.CurrentCell != null)
{
string barcode = this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["ProductionBarCode"].Value.ToString();
int tempcount = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["TempCount"].Value.ToString());
int goodsID = 0;
DataRow[] dr = this.TableProductionData.Select("BarCode='" + barcode + "'");
if (dr.Length > Constant.INT_IS_ZERO)
{
goodsID = Convert.ToInt32(dr[0]["GoodsID"]);
}
F_PM_1303 frm1303 = new F_PM_1303(
DSTable.Tables[barcode], barcode,
goodsID, tempcount, this._procedureID, this.Text, true, this, this.DSTableStaff, this.DSTableImage, this._PicByte, this._smallByte, this.dgvDefect.CurrentCell.RowIndex);
frm1303.ShowDialog();
}
}
///
/// 保存按钮事件
///
///
///
private void btnSave_Click(object sender, EventArgs e)
{
try
{
ProductionDataEntity[] productionDataEntitys = new ProductionDataEntity[this.TableProductionData.Rows.Count];
bool isError = false; // 是否存在缺陷员工
int ErrorNumber = -1;//错误编码
for (int i = 0; i < this.TableProductionData.Rows.Count; i++)
{
ProductionDataEntity productionDataEntity = new ProductionDataEntity();
productionDataEntity.ProductionDataID = this._productionDataID==null?0:Convert.ToInt32(this._productionDataID);
productionDataEntity.Barcode = this.TableProductionData.Rows[i]["BarCode"].ToString();
productionDataEntity.UserID = UserID;
productionDataEntity.UserCode = UserCode;
productionDataEntity.UserName = UserName;
productionDataEntity.DefectFlag = Constant.GoodsLevelType.Defect.GetHashCode();
DataRow[] drSelected = this.DSTable.Tables[productionDataEntity.Barcode].Select("discarde=1");
if (drSelected.Length == 0)
{
productionDataEntity.GoodsLevelTypeID = Constant.GoodsLevelType.Defect.GetHashCode();
}
else
{
productionDataEntity.GoodsLevelTypeID = Constant.GoodsLevelType.Waste.GetHashCode();//废品
}
if (this._dsGoodsLevel != null)
{
DataRow[] dr = this._dsGoodsLevel.Tables[0].Select("GoodsLevelTypeID=" + productionDataEntity.GoodsLevelTypeID);
if (dr.Length > 0)
{
productionDataEntity.GoodsLevelID = Convert.ToInt32(dr[0]["DefectFlagID"]);
}
}
productionDataEntity.Remarks = this.TableProductionData.Rows[i]["Remarks"].ToString();
if (this.TableProductionData.Rows[i]["LogoID"].ToString() != "")
{
productionDataEntity.LogoID = Convert.ToInt32(this.TableProductionData.Rows[i]["LogoID"]);
}
productionDataEntitys[i] = productionDataEntity;
if (this.DSTable.Tables[productionDataEntity.Barcode].Rows.Count == 0)//但是没有缺陷数据
{
isError = true;
ErrorNumber = -2;
this.dgvProductionData.Rows[i].Selected = true;
break;
}
List productionDefectEntitys = new List();
ProductionDefectEntity productionDefectEntity = null;
for (int j = 0; j < this.DSTable.Tables[productionDataEntity.Barcode].Rows.Count; j++) //缺陷列表
{
productionDefectEntity = new ProductionDefectEntity();
productionDefectEntity.ScrapFlag = Convert.ToBoolean(
Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["discarde"].ToString() == "" ? 0 : this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["discarde"]));
productionDefectEntity.ScrapResponFlag =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["discarde"].ToString();
productionDefectEntity.DefectID =
Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectID"]);
productionDefectEntity.DefectCode =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectCode"].ToString();
//productionDefectEntity.DefectName =
// this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectName"].ToString();
productionDefectEntity.DefectName =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectName"].ToString().Replace(productionDefectEntity.DefectCode + "->", "");
productionDefectEntity.DefectPositionID =
Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectPositionID"]);
productionDefectEntity.DefectPositionCode =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectPositionCode"].ToString();
productionDefectEntity.DefectPositionName =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectPositionName"].ToString().Replace(productionDefectEntity.DefectPositionCode + "->", "");
productionDefectEntity.DefectProductionDataID =
Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["ProductionDataID"].ToString());
productionDefectEntity.DefectProcedureID =
Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectProcedureID"]);
productionDefectEntity.DefectProcedureCode =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectProcedureCode"].ToString();
productionDefectEntity.DefectProcedureName =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectProcedureName"].ToString();
productionDefectEntity.DefectUserID =
Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectUserID"]);
productionDefectEntity.DefectUserCode =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectUserCode"].ToString();
productionDefectEntity.DefectUserName =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectUserName"].ToString();
productionDefectEntity.DefectJobs =
Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["Jobs"].ToString());
productionDefectEntity.Remarks =
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectRemarks"].ToString();
if (this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectFineID"].ToString() != "-1"
&& this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectFineID"].ToString() != string.Empty)
{
productionDefectEntity.DefectFine = Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["DefectFineID"]);
}
if (this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["CheckTime"].ToString() != string.Empty)
{
productionDefectEntity.CheckTime = Convert.ToDateTime(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["CheckTime"]);
}
// 遍历责任员工
List DefectResponsibles = new List();
if (this.DSTableStaff.Tables.Contains(string.Format("TempTable{0}",
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())))
{
DefectResponsibleEntity defectResponsibleEntity = null;
DataTable dtTemp = this.DSTableStaff.Tables[string.Format("TempTable{0}",
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())];
foreach (DataRow drStaff in dtTemp.Rows)
{
if (Convert.ToInt32(drStaff["IsSelected"]) == Constant.INT_IS_ONE)
{
defectResponsibleEntity = new DefectResponsibleEntity();
defectResponsibleEntity.StaffID = Convert.ToInt32(drStaff["StaffID"]);
defectResponsibleEntity.UserID = Convert.ToInt32(productionDefectEntity.DefectUserID);
defectResponsibleEntity.UserCode = productionDefectEntity.DefectUserCode;
defectResponsibleEntity.UJobsID =
Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["Jobs"].ToString());
defectResponsibleEntity.SJobsID =
Convert.ToInt32(this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["Jobs"].ToString());
defectResponsibleEntity.StaffStatus = Convert.ToInt32(drStaff["StaffStatus"]);
DefectResponsibles.Add(defectResponsibleEntity);
}
}
//productionDefectEntity.DefectResponsibles = DefectResponsibles.ToArray();//每个缺陷对应的责任员工
productionDefectEntity.DefectResponsibles = DefectResponsibles;//每个缺陷对应的责任员工
}
if (DefectResponsibles.Count == Constant.INT_IS_ZERO) // 并没有责任员工
{
isError = true;
this.dgvDefect.DataSource = this.DSTable.Tables[productionDataEntity.Barcode];
this.dgvDefect.CurrentCell = null;
this.dgvDefect.Rows[j].Selected = true;
if (this.DSTableStaff.Tables.Contains(string.Format("TempTable{0}",
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())))
{
this.dgvDefectStaff.DataSource = this.DSTableStaff.Tables[string.Format("TempTable{0}",
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())];
}
else
{
this.dgvDefectStaff.DataSource = null;
}
break;
}
// 遍历缺陷图片
if (this.DSTableImage.Tables.Contains(string.Format("TempTable{0}",
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())))
{
List defectImageEntitys = new List();
DefectImageEntity defectImageEntity = null;
DataTable dtTemp = this.DSTableImage.Tables[string.Format("TempTable{0}",
this.DSTable.Tables[productionDataEntity.Barcode].Rows[j]["TempCount"].ToString())];
foreach (DataRow drImage in dtTemp.Rows)
{
defectImageEntity = new DefectImageEntity();
defectImageEntity.Thumbnail = (byte[])drImage["ImageByte"];
defectImageEntity.Image = (byte[])drImage["orgImageByte"];
defectImageEntitys.Add(defectImageEntity);
}
//productionDefectEntity.DefectImages = defectImageEntitys.ToArray();
productionDefectEntity.DefectImages = defectImageEntitys;
}
productionDefectEntitys.Add(productionDefectEntity);
}
if (isError)
{
break;
}
//productionDataEntitys[i].ProductionDefects = productionDefectEntitys.ToArray();
productionDataEntitys[i].ProductionDefects = productionDefectEntitys;
}
if (isError && ErrorNumber == -Constant.INT_IS_ONE)
{
// 提示信息
MessageBox.Show(Messages.MSG_PM_W002,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
else if (isError && ErrorNumber == -Constant.INT_IS_TWO)
{
// 提示信息
MessageBox.Show(Messages.MSG_PM_W013,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (productionDataEntitys.Length > Constant.INT_IS_ZERO)
{
// 最外层For循环结束
string returnValue = (string)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.AddCheckBarcode(this._procedureID, productionDataEntitys);
}));
if (string.IsNullOrEmpty(returnValue))//成功
{
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "新建" + this.Text, "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.TableProductionData.Rows.Clear();
this.dgvProductionData.DataSource = TableProductionData;
this.DSTable.Tables.Clear();
this.dgvDefect.DataSource = null;
this.DSTableStaff.Tables.Clear();
this.dgvDefectStaff.DataSource = null;
this.DSTableImage.Tables.Clear();
this.lvPic.Clear();
this._PicByte.Clear();
this._smallByte.Clear();
if (this._procedureDataEntity.CollectType == (int)Constant.ProcedureCollectType.Togather)
{
this.txtUserCode.Text = string.Empty;
this.txtUserCode.ReadOnly = false;
}
this.DSREWORK.Tables.Clear();
}
else
{
// 提示信息
MessageBox.Show(returnValue,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 关闭按钮事件
///
///
///
private void tsbCloseTop_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// 单元格开始编辑时事件
///
///
///
private void dgvProductionData_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
if (e.ColumnIndex == Constant.INT_IS_FOUR && e.RowIndex != -Constant.INT_IS_ONE)
{
DataGridView dgv = (DataGridView)sender;
string value = this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["GoodsLevelTypeID"].Value.ToString();
if (value != Convert.ToString((int)Constant.GoodsLevelType.Defect))
{
e.Cancel = true;
}
}
}
///
/// 生产工号验证事件
///
///
///
private void txtUserCode_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
if (txtUserCode.Text.Trim() == string.Empty) // 如果未添加数据,则此项获取焦点
{
this.txtUserCode.IsMustInput = true;
this.txtUserCode.SelectAll();
e.Cancel = true;
return;
}
else if (!this.txtUserCode.ReadOnly)
{
SUserEntity userEntity = new SUserEntity();
userEntity.UserCode = this.txtUserCode.Text.Trim();
// 此工号是否能生产工序
CheckProcedureUserResult MsgCheckProcedureUser = (CheckProcedureUserResult)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.CheckProcedureUser(this._procedureID, this.txtUserCode.Text.Trim());
}));
if (MsgCheckProcedureUser != null)
{
if (MsgCheckProcedureUser.ErrMsg != null)
{
MessageBox.Show(MsgCheckProcedureUser.ErrMsg,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
this.txtUserCode.SelectAll();
e.Cancel = true;
return;
}
UserID = Convert.ToInt32(MsgCheckProcedureUser.UserID);
UserCode = MsgCheckProcedureUser.UserCode;
UserName = MsgCheckProcedureUser.UserName;
this.txtUserCode.ReadOnly = true;
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 鼠标单击事件
///
///
///
private void txtUserCode_MouseClick(object sender, MouseEventArgs e)
{
if (this.txtUserCode.Text.Trim() != string.Empty)
{
this.txtUserCode.SelectAll();
}
}
#endregion
#region 私有方法
///
/// 设置数据源
///
///
public void SetDataSource(int tempCount)
{
this.dgvDefect.DataSource = DSTable.Tables[this._currentBarCode];
this.dgvDefectStaff.DataSource = DSTableStaff.Tables[string.Format("TempTable{0}", this._tempCount.ToString())];
this._tempCount = tempCount;
}
///
/// 绑定到第一个DataGriwView数据源
///
private void BindProductionData(DataSet dsCheckBarcode)
{
try
{
DataRow[] dr = TableProductionData.Select("BarCode='" + this.txtBarCode.Text.Trim() + "'");
if (dr.Length > Constant.INT_IS_ZERO)
{
// 不允许重复添加
return;
}
string KilnCarCode = string.Empty;
string KilnCode = string.Empty;
string Dictionaryvalue = string.Empty;
DataSet dsKilnCar = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.GetKilnCarByBarCode(txtBarCode.Text.Trim());
}));
if (dsKilnCar != null && dsKilnCar.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
KilnCarCode = dsKilnCar.Tables[0].Rows[0]["KilnCarCode"].ToString();
KilnCode = dsKilnCar.Tables[0].Rows[0]["KilnCode"].ToString();
Dictionaryvalue = dsKilnCar.Tables[0].Rows[0]["Dictionaryvalue"].ToString();
}
DataRow drNew = TableProductionData.NewRow();
drNew["BarCode"] = this.txtBarCode.Text.Trim();
drNew["GoodsID"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_goodsID.ToString()];
drNew["GoodsCode"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_goodsCode.ToString()];
drNew["GoodsName"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_goodsName.ToString()];
drNew["DefectFlagID"] = Constant.GoodsLevelType.Defect;
drNew["ReworkProcedureID"] = DBNull.Value;
drNew["Remarks"] = "";
drNew["UserID"] = UserID;
drNew["KilnCarCode"] = KilnCarCode;
drNew["KilnCode"] = KilnCode;
drNew["Dictionaryvalue"] = Dictionaryvalue;
drNew["GoodsLevelTypeID"] = DBNull.Value;
// 查重烧及干补标识
DataSet dsInProductionDataList = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PMModuleProxy.Service.GetInProductionDataList(this.txtBarCode.Text.Trim());
}));
if (dsInProductionDataList != null && dsInProductionDataList.Tables[0].Rows.Count > 0)
{
drNew["ReFine"] = dsInProductionDataList.Tables[0].Rows[0]["IsReFire"].ToString() == "1" ? 1 : 0;
drNew["SpecialRepairflag"] = dsInProductionDataList.Tables[0].Rows[0]["SpecialRepairflag"].ToString() == "1" ? 1 : 0;
drNew["SpecialRepairflagValue"] = dsInProductionDataList.Tables[0].Rows[0]["SpecialRepairflag"].ToString();//过滤干补标识
}
else
{
drNew["ReFine"] = 0;
drNew["SpecialRepairflag"] = 0;
drNew["SpecialRepairflagValue"] = 0;
}
drNew["UserCode"] = this.txtUserCode.Text.Trim();
// 由产品条码获取注浆信息
//DataSet dsGroutingProduct = (DataSet)DoAsync(new BaseAsyncMethod(() =>
//{
// return PMModuleProxy.Service.GetGroutingProducttByBarCode(txtBarCode.Text.Trim());
//}));
drNew["MouldCode"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_mouldCode.ToString()];
drNew["GroutingUserCode"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_groutingUserCode.ToString()];
drNew["GroutingNum"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_groutingNum.ToString()];
drNew["IsPublicBody"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_ispublicbody.ToString()].ToString() != "1" ? 0 : 1;
drNew["GroutingDate"] = Convert.ToDateTime(dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_groutingdate.ToString()]);
drNew["LogoCodeName"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_logoName.ToString()]
+ "[" + dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_logoCode.ToString()] + "]";
drNew["LogoId"] = dsCheckBarcode.Tables[0].Rows[0][Constant.BarCodeResultTableColumns.out_logoID.ToString()];
TableProductionData.Rows.Add(drNew);
if (DSTable.Tables.IndexOf(this.txtBarCode.Text.Trim()) == -Constant.INT_IS_ONE)
{
DataTable dtProductionDefectData = new DataTable(this.txtBarCode.Text.Trim());
dtProductionDefectData.Columns.Add("BarCode");
dtProductionDefectData.Columns.Add("discarde");
dtProductionDefectData.Columns.Add("DefectID", typeof(decimal));
dtProductionDefectData.Columns.Add("DefectName");
dtProductionDefectData.Columns.Add("DefectCode");
dtProductionDefectData.Columns.Add("DefectPositionID", typeof(decimal));
dtProductionDefectData.Columns.Add("DefectPositionName");
dtProductionDefectData.Columns.Add("DefectPositionCode");
dtProductionDefectData.Columns.Add("DefectProcedureID", typeof(decimal));
dtProductionDefectData.Columns.Add("DefectProcedureName");
dtProductionDefectData.Columns.Add("DefectProcedureCode");
dtProductionDefectData.Columns.Add("DefectUserID", typeof(decimal));//责任员工
dtProductionDefectData.Columns.Add("DefectUserName");//责任员工
dtProductionDefectData.Columns.Add("DefectUserCode");//
dtProductionDefectData.Columns.Add("Jobs", typeof(decimal));//工种
dtProductionDefectData.Columns.Add("JobsText");//工种
dtProductionDefectData.Columns.Add("DefectRemarks");
dtProductionDefectData.Columns.Add("TempCount");
dtProductionDefectData.Columns.Add("ProductionDataID"); //生产数据ID
dtProductionDefectData.Columns.Add("DefectFineID"); //缺席扣罚ID
dtProductionDefectData.Columns.Add("DefectFineValue"); //缺席扣罚
dtProductionDefectData.Columns.Add("CheckTime"); //缺陷检验时间
DSTable.Tables.Add(dtProductionDefectData);
}
this.dgvDefect.DataSource = DSTable.Tables[this.txtBarCode.Text.Trim()];//根据条码产生不同数据源
this.dgvProductionData.Rows[TableProductionData.Rows.Count - 1].Selected = true;
this.dgvDefect.DataSource = null;
this.dgvDefectStaff.DataSource = null;
this.lvPic.Clear();
// 添加一个产品条码时除了第一个显示在数据表中,其它的全部清空
this.tsbtnAdd.Enabled = true;//添加完条码后,可以新建其它信息
// 添加一个产品条码时除了第一个显示在数据表中,其它的全部清空
this.tsbtnAdd.Enabled = true;//添加完条码后,可以新建其它信息
this._selectedRowIndex = TableProductionData.Rows.Count - 1;
//DataSet ds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
//{
// return PMModuleProxy.Service.GetReworkProcedureByBarcode(this._procedureID, this.dgvProductionData.Rows[_selectedRowIndex].Cells["BarCode"].Value.ToString());
//}));
//ds.Tables[0].TableName = this.txtBarCode.Text.Trim();
//if (this.DSREWORK == null)
//{
// this.DSREWORK = new DataSet();
//}
//this.DSREWORK.Tables.Add(ds.Tables[0].Copy());
//C_DGV_Cell_ListBoxComboBox C_DGV_Cell_ListBoxComboBox = dgvProductionData.Rows[_selectedRowIndex].Cells[4] as C_DGV_Cell_ListBoxComboBox;
//C_DGV_Cell_ListBoxComboBox.DataSource = ds.Tables[0];
//C_DGV_Cell_ListBoxComboBox.DisplayMember = "ReworkProcedureName";
//C_DGV_Cell_ListBoxComboBox.ValueMember = "ReworkProcedureID";
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 通过是否有缺陷来启用或禁用
///
///
private void SetGridView(int GoodsLevelID)
{
DataTable dtDefectFlag = this.DefectFlag.DataSource as DataTable;//获取缺陷数据源
int GoodsLevelTypeID = -1;
DataRow[] dr = dtDefectFlag.Select("DefectFlagID=" + GoodsLevelID);
if (dr.Length > 0)
{
GoodsLevelTypeID = Convert.ToInt32(dr[0]["GoodsLevelTypeID"]);
this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["GoodsLevelTypeID"].Value = GoodsLevelTypeID;
}
if (GoodsLevelTypeID != -1)
{
if (GoodsLevelTypeID == (int)Constant.GoodsLevelType.NoDefects) //没有缺陷
{
try
{
this.dgvDefect.ReadOnly = true;
this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureID"].Value = null;
this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureCode"].Value = string.Empty;
this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureName"].Value = string.Empty;
this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureID"].ReadOnly = true;
string BarCode = this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["BarCode"].Value.ToString();
if (DSTable.Tables.Contains(BarCode))
{
DSTable.Tables[BarCode].Rows.Clear();//清空行
}
this.dgvDefectStaff.DataSource = null;
this.lvPic.Clear();
}
catch (Exception ex)
{
throw ex;
}
}
else if (GoodsLevelTypeID == (int)Constant.GoodsLevelType.Defect) //有缺陷
{
this.dgvDefect.ReadOnly = true;
this.dgvProductionData.Rows[this.dgvProductionData.CurrentCell.RowIndex].Cells["ReworkProcedureID"].ReadOnly = false;
}
else if (GoodsLevelTypeID == (int)Constant.GoodsLevelType.Waste) //废品
{
this.dgvDefect.ReadOnly = false;
}
}
}
///
/// 清空以前所选中的缺陷
///
///
private void SetCheckBoxSelected(int checkValue, int rowIndex)
{
DataTable dtOrgDataSource = this.dgvDefect.DataSource as DataTable;
for (int i = 0; i < DSTable.Tables[dtOrgDataSource.TableName].Rows.Count; i++)
{
if (i == rowIndex)
{
dtOrgDataSource.Rows[i]["discarde"] = 1;
}
else
{
dtOrgDataSource.Rows[i]["discarde"] = 0;
}
}
}
///
/// 绑定并显示图片
///
///
public void BindByteImage(DataTable ImageData)
{
this._smallByte.Clear();
foreach (DataRow dr in ImageData.Rows)
{
//将数据库中的缩略图取出
this._smallByte.Add((byte[])dr[1]);
}
//绑定缩略图
BindImg();
}
///
/// 将图片文件转换成二进制
///
///
///
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;
}
///
/// 重绘缩略图并把缩略图转为二进制储存
///
/// 图片源路径
/// 缩放后图片高度
/// 缩放后图片宽度
///
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);
if (this._currentTempSign != "")
{
if (!this.DSTableImage.Tables.Contains(string.Format("TempTable{0}", this._currentTempSign.ToString())))
{
DataTable dtImage = new DataTable(string.Format("TempTable{0}", this._currentTempSign.ToString()));
dtImage.Columns.Add("StaffTempCount");
dtImage.Columns.Add("ImageByte", typeof(byte[]));
dtImage.Columns.Add("OrgImageByte", typeof(byte[]));
this.DSTableImage.Tables.Add(dtImage);
}
DataRow dr = DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].NewRow();
dr["StaffTempCount"] = this._currentTempSign;
dr["ImageByte"] = smallbuffer;
dr["OrgImageByte"] = orgImageByte;
DSTableImage.Tables[string.Format("TempTable{0}", this._currentTempSign)].Rows.Add(dr);
}
this._smallByte.Add(smallbuffer);
imgSource.Dispose();
outBmp.Dispose();
}
///
/// 根据原图片宽高比获取缩略图的高(根据宽)
///
///
///
///
///
protected int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
{
decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
return Convert.ToInt32(SmallWidth / scale);
}
///
/// 绑定缩略图到控件中
///
protected void BindImg()
{
ImageList ilPic = new ImageList();
//每次绑定要清空数据源
ilPic.Images.Clear();
//将缩略图二进制集合中的数据转换成图片文件
List LSImageList = new List();
foreach (byte[] smallby in _smallByte)
{
LSImageList.Add(byteArrayToImage(smallby));
}
//添加数据源
foreach (Image img in LSImageList)
{
ilPic.Images.Add(img);
}
ilPic.ImageSize = new Size(100, 100);
this.lvPic.LargeImageList = ilPic;
this.lvPic.BeginUpdate();
//清空列表的数据源
lvPic.Items.Clear();
//添加列表的数据源
for (int i = 0; i < ilPic.Images.Count; i++)
{
ListViewItem lvi = new ListViewItem();
lvi.ImageIndex = i;
this.lvPic.Items.Add(lvi);
}
this.lvPic.EndUpdate();
}
///
/// 将数据库中的二进制转换成图片
///
///
///
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;
}
#endregion
}
}