| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_0502.cs
- * 2.功能描述:新建或编辑产品档案信息
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 庄天威 2014/09/13 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.CommonModule.FormCommon;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- namespace Dongke.IBOSS.PRD.Client.SystemModule
- {
- /// <summary>
- /// 新建或编辑产品档案信息
- /// </summary>
- public partial class F_MST_0502 : FormBase
- {
- #region 成员变量
- //页面状态
- private Constant.FormMode _formStatus;
- // 产品ID
- private int _formGoodsId;
- // 产品图片二进制集合
- private List<byte[]> _picByteList = new List<byte[]>();
- // 产品图片缩略图二进制集合
- private List<byte[]> _smallByteList = new List<byte[]>();
- // 产品图片实体集合
- private List<GoodsImageEntity> _imgList = new List<GoodsImageEntity>();
- // 已存在的图片实体集合(修改)
- private List<GoodsImageEntity> _updateImgList = new List<GoodsImageEntity>();
- // 产品附件实体集合
- private List<GoodsAttachmentEntity> _attList = new List<GoodsAttachmentEntity>();
- // 当前编辑实体
- private GoodsEntity _thisGoodsEntity = new GoodsEntity();
- private DataTable _sapInfo = null;
- #endregion
- #region 构造函数
- /// <summary>
- /// 新建/编辑产品档案窗体构造
- /// </summary>
- /// <param name="modelId">窗体模式,0为新建,1为编辑</param>
- /// <param name="goodsId">编辑产品ID</param>
- public F_MST_0502(Constant.FormMode status, int goodsId)
- {
- InitializeComponent();
- this.dgvGoodsSap.AutoGenerateColumns = false;
- this._formStatus = status;
- this._formGoodsId = goodsId;
- if (this._formStatus == Constant.FormMode.Add)
- {
- this.Text = FormTitles.F_MST_0502_ADD;
- }
- else
- {
- this.Text = FormTitles.F_MST_0502_EDIT;
- }
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- this.btnUpload.Text = ButtonText.BTN_UPLOAD;
- this.btnDelete.Text = ButtonText.BTN_DELETE;
- //L:立浇 G:高压 M:粘接高压(三水厂) Q:吊装线
- DataTable dt = new DataTable();
- dt.Columns.Add("key");
- dt.Columns.Add("value");
- dt.Rows.Add(new object[] { "L", "立浇" });
- dt.Rows.Add(new object[] { "G", "高压" });
- dt.Rows.Add(new object[] { "M", "粘接高压(三水厂)" });
- dt.Rows.Add(new object[] { "Q", "吊装线" });
- this.cbGLTDetail.DataSource = dt;
- this.cbGLTDetail.ValueMember = "key";
- this.cbGLTDetail.DisplayMember = "value";
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载
- /// </summary>
- private void F_MST_0702_Load(object sender, EventArgs e)
- {
- try
- {
- this.scbGoodsType.IsOnlyDisplayEnd = true;
- LoadDataSource();
- if (this._formStatus == Constant.FormMode.Edit)
- {
- // 产品编码不能编辑 add by chenxy 2016-08-16 begin
- this.txtGoodsCode.ReadOnly = true;
- // 产品编码不能编辑 add by chenxy 2016-08-16 end
- //根据goodsId查询对应的产品信息
- this._thisGoodsEntity.GoodsID = this._formGoodsId;
- DataSet updateGoods = SystemModuleProxy.Service.SerachGoods(this._thisGoodsEntity);
- if (updateGoods.Tables[0].Rows.Count != Constant.INT_IS_ZERO)
- {
- //把值绑入实体
- DataRow drGoods = updateGoods.Tables[0].Rows[0];
- this._thisGoodsEntity.GoodsCode = drGoods["GoodsCode"].ToString();
- this._thisGoodsEntity.GoodsTypeID = Convert.ToInt32(drGoods["GOODSTYPEID"]);
- this._thisGoodsEntity.GlazeTypeID = Convert.ToInt32(drGoods["GLAZETYPEID"]);
- this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(drGoods["CEASEFLAG"]);
- this._thisGoodsEntity.Remarks = drGoods["Remarks"].ToString();
- this._thisGoodsEntity.AccountID = Convert.ToInt32(drGoods["AccountID"]);
- this._thisGoodsEntity.ValueFlag = Convert.ToInt32(drGoods["ValueFlag"]);
- this._thisGoodsEntity.CreateTime = Convert.ToDateTime(drGoods["CreateTime"]);
- this._thisGoodsEntity.CreateUserID = Convert.ToInt32(drGoods["CreateUserID"]);
- this._thisGoodsEntity.UpdateTime = Convert.ToDateTime(drGoods["UpdateTime"]);
- this._thisGoodsEntity.UpdateUserID = Convert.ToInt32(drGoods["UpdateUserID"]);
- this._thisGoodsEntity.OPTimeStamp = Convert.ToDateTime(drGoods["OPTimeStamp"]);
- this._thisGoodsEntity.StartingDate = Convert.ToDateTime(drGoods["StartingDate"]);
- this._thisGoodsEntity.AutoLossCycle = Convert.ToInt32(drGoods["AutoLossCycle"]);
- this._thisGoodsEntity.DeliverLimitCycle = Convert.ToInt32(drGoods["DeliverLimitCycle"]);
- this._thisGoodsEntity.PlateLimitNum = Convert.ToInt32(drGoods["PlateLimitNum"]);
- this._thisGoodsEntity.UnitPrice = Convert.ToDecimal(drGoods["UnitPrice"]);
- this._thisGoodsEntity.ReservedDays = Convert.ToInt32(drGoods["ReservedDays"]);
- this._thisGoodsEntity.MouldOutputCount = Convert.ToInt32(drGoods["MouldOutputCount"]);
- this._thisGoodsEntity.StandardGroutingNum = Convert.ToInt32(drGoods["StandardGroutingNum"]);
- this._thisGoodsEntity.MouldMaterialCode = drGoods["MouldMaterialCode"] + "";
- this._thisGoodsEntity.WaterLabelCode = drGoods["WaterLabelCode"] + "";
- //将实体的值赋给各控件
- this.txtGoodsCode.Text = drGoods["GoodsCode"].ToString();
- this.txtGoodsName.Text = drGoods["GoodsName"].ToString();
- this.txtGoodsSpecification.Text = drGoods["GoodsSpecification"].ToString();
- this.txtGoodsModel.Text = drGoods["GoodsModel"].ToString();
- this.scbGoodsType.CheckedData = updateGoods.Tables[0];
- //this.scbGoodsType.InitValue(drGoods["GoodsTypeName"].ToString(), _thisGoodsEntity.GoodsTypeID);
- this.scbGoodsType.Text = drGoods["GoodsTypeName"].ToString();
- this.ddlGlazeTypeID.SelectedValue = _thisGoodsEntity.GlazeTypeID;
- this.txtMudWeight.Text = drGoods["MudWeight"].ToString();
- this.txtGlazeWeight.Text = drGoods["GlazeWeight"].ToString();
- this.txtLusterwareWeight.Text = drGoods["LusterwareWeight"].ToString();
- this.txtProductionCycle.Text = drGoods["ProductionCycle"].ToString();
- this.cbCeaseFlag.Checked = (_thisGoodsEntity.CeaseFlag == Constant.INT_IS_ONE);
- this.cbValueFlag.Checked = (this._thisGoodsEntity.ValueFlag == Constant.INT_IS_ONE);
- this.txtRemarks.Text = this._thisGoodsEntity.Remarks;
- this.dtpStartingDate.Value = this._thisGoodsEntity.StartingDate;
- this.txtSPM001.DataValue = this._thisGoodsEntity.AutoLossCycle;
- this.txtSPM002.DataValue = this._thisGoodsEntity.DeliverLimitCycle;
- this.txtMouldOutputCount.DataValue = this._thisGoodsEntity.MouldOutputCount;
- this.txtStandardGroutingNum.DataValue = this._thisGoodsEntity.StandardGroutingNum;
- this.txtMouldMaterialCode.Text = this._thisGoodsEntity.MouldMaterialCode;
- this.txtWaterLabelCode.Text = this._thisGoodsEntity.WaterLabelCode;
- this.txtPlateLimitNum.DataValue = this._thisGoodsEntity.PlateLimitNum;
- this.txtUnitPrice.DataValue = this._thisGoodsEntity.UnitPrice;
- this.txtReservedDays.DataValue = this._thisGoodsEntity.ReservedDays;
- this.chkGLT.Checked = (drGoods["GOODS_LINE_TYPE"] + "" == "1");
- this.cbGLTDetail.Enabled = this.chkGLT.Checked;
- this.cbGLTDetail.SelectedValue = (drGoods["GOODS_LINE_CODE"] + "");
- this.txtPackageNum.Text = drGoods["PackageNum"].ToString();
- this.txtOutletDistance.Text = drGoods["OutletDistance"].ToString();
- this.scbSAPCode1.Text = drGoods["MaterialCode"].ToString();
- this.txtMaterialRemark.Text = drGoods["MaterialRemark"].ToString();
- this.txtCopies.Text = drGoods["printcopies"].ToString();
- this.ftcLogo.InitValue(drGoods["logoname"] + "", drGoods["logoid"]);
- if (drGoods["MouldWeight"] != DBNull.Value)
- {
- this.txtMouldWeight.DataValue = Convert.ToDecimal(drGoods["MouldWeight"]);
- }
- if (drGoods["MouldCost"] != DBNull.Value)
- {
- this.txtMouldCost.DataValue = Convert.ToDecimal(drGoods["MouldCost"]);
- }
- this.chkScrapSumFlag.Checked = (drGoods["ScrapSumFlag"] + "" == "1");
- if (drGoods["SeatCoverCode"] != DBNull.Value)
- {
- this.txtSEATCOVERCODE.DataValue = Convert.ToInt32(drGoods["SeatCoverCode"]);
- }
- //查询对应的图片
- DataSet dsImg = SystemModuleProxy.Service.getImageByGoodsId(this._formGoodsId);
- BindByteImage(dsImg);
- }
- }
- // 产品物料信息
- ClientRequestEntity cre = new ClientRequestEntity();
- cre.NameSpace = "MST_Goods";
- cre.Name = "GetGoodsSAPByEdit";
- cre.Request = this._formGoodsId;
- // 调用服务器端获取数据集
- ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
- if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
- {
- this._sapInfo = sre.Data.Tables[0];
- this.dgvGoodsSap.DataSource = this._sapInfo;
- }
- this.txtGoodsCode.Focus();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 获取数据事件
- /// </summary>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- //基础数据验证
- int ErrorId = ValidationText();
- if (ErrorId != Constant.INT_IS_ZERO)
- {
- string errorAddress = "";
- switch (ErrorId)
- {
- case 1:
- this.txtGoodsCode.Focus();
- errorAddress = "产品编码";
- break;
- case 3:
- this.txtGoodsName.Focus();
- errorAddress = "产品名称";
- break;
- case 6:
- this.scbGoodsType.Focus();
- errorAddress = "产品类别";
- break;
- case 7:
- this.ddlGlazeTypeID.Focus();
- errorAddress = "釉料类别";
- break;
- default:
- break;
- };
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, errorAddress),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- return;
- }
- if (string.IsNullOrEmpty(scbSAPCode1.Text))
- {
- this.scbSAPCode1.Focus();
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "物料编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- return;
- }
- //if (string.IsNullOrEmpty(txtGroutmaterialcode.Text))
- //{
- // this.txtGroutmaterialcode.Focus();
- // MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "注浆初始物料编码"),
- // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- // return;
- //}
- if (string.IsNullOrEmpty(txtMouldMaterialCode.Text))
- {
- this.txtMouldMaterialCode.Focus();
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具物料编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- return;
- }
- if (string.IsNullOrEmpty(ftcLogo.SelectedValue+""))
- {
- this.ftcLogo.Focus();
- MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "注浆商标"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- return;
- }
- //查询产品编号唯一性
- if ((this.txtGoodsCode.Text != this._thisGoodsEntity.GoodsCode && _formStatus == Constant.FormMode.Edit)
- || this._formStatus == Constant.FormMode.Add)
- {
- if (ValidationCode(this.txtGoodsCode.Text) == false)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "产品编码"), this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- //实体赋值
- if (this._thisGoodsEntity == null)
- {
- this._thisGoodsEntity = new GoodsEntity();
- }
- this._thisGoodsEntity.GoodsCode = this.txtGoodsCode.Text;
- this._thisGoodsEntity.GoodsModel = this.txtGoodsModel.Text;
- this._thisGoodsEntity.GoodsName = this.txtGoodsName.Text;
- this._thisGoodsEntity.GoodsSpecification = this.txtGoodsSpecification.Text;
- this._thisGoodsEntity.GoodsTypeID = Convert.ToInt32(scbGoodsType.SearchedItem["GoodsTypeID"]);
- this._thisGoodsEntity.GlazeTypeID = this.ddlGlazeTypeID.SelectedValue.ToString() == "" ? null : (int?)Convert.ToInt32(this.ddlGlazeTypeID.SelectedValue);
- this._thisGoodsEntity.MudQuantity = this.txtMudWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtMudWeight.Text);
- this._thisGoodsEntity.GlazeQuantity = this.txtGlazeWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtGlazeWeight.Text);
- this._thisGoodsEntity.LusterwareWeight = this.txtLusterwareWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtLusterwareWeight.Text);
- this._thisGoodsEntity.ProductionCycle = this.txtProductionCycle.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtProductionCycle.Text);
- this._thisGoodsEntity.StartingDate = this.dtpStartingDate.Value.Date;
- this._thisGoodsEntity.AutoLossCycle = (this.txtSPM001.DataValue.HasValue ? Convert.ToInt32(this.txtSPM001.DataValue) : 0);
- this._thisGoodsEntity.DeliverLimitCycle = (this.txtSPM002.DataValue.HasValue ? Convert.ToInt32(this.txtSPM002.DataValue) : 0);
- this._thisGoodsEntity.MouldOutputCount = (this.txtMouldOutputCount.DataValue.HasValue ? Convert.ToInt32(this.txtMouldOutputCount.DataValue) : 1);
- this._thisGoodsEntity.StandardGroutingNum = (this.txtStandardGroutingNum.DataValue.HasValue ? Convert.ToInt32(this.txtStandardGroutingNum.DataValue) : 0);
- this._thisGoodsEntity.MouldMaterialCode = this.txtMouldMaterialCode.Text;
- this._thisGoodsEntity.WaterLabelCode = this.txtWaterLabelCode.Text;
- this._thisGoodsEntity.PlateLimitNum = (this.txtPlateLimitNum.DataValue.HasValue ? Convert.ToInt32(this.txtPlateLimitNum.DataValue) : 0);
- this._thisGoodsEntity.UnitPrice = (this.txtUnitPrice.DataValue.HasValue ? this.txtUnitPrice.DataValue.Value : 0);
- this._thisGoodsEntity.ReservedDays = (this.txtReservedDays.DataValue.HasValue ? Convert.ToInt32(this.txtReservedDays.DataValue) : 0);
- this._thisGoodsEntity.PackageNum = this.txtPackageNum.Text.Trim();
- this._thisGoodsEntity.OutletDistance = this.txtOutletDistance.Text.Trim();
- this._thisGoodsEntity.MaterialCode = this.scbSAPCode1.Text.Trim();
- this._thisGoodsEntity.MaterialRemark = this.txtMaterialRemark.Text;
- this._thisGoodsEntity.PrintCopies = (this.txtCopies.DataValue.HasValue ? Convert.ToInt32(this.txtCopies.DataValue) : 0);
- this._sapInfo.AcceptChanges();
- this._thisGoodsEntity.SAPInfo = this._sapInfo;
- this._thisGoodsEntity.LogoID = Convert.ToInt32(ftcLogo.SelectedValue);
- if (this.txtMouldWeight.DataValue != null)
- {
- this._thisGoodsEntity.MouldWeight = this.txtMouldWeight.DataValue;
- }
- if (this.txtMouldCost.DataValue != null)
- {
- this._thisGoodsEntity.MouldCost = this.txtMouldCost.DataValue;
- }
- if (this.txtSEATCOVERCODE.DataValue != null)
- {
- this._thisGoodsEntity.SeatCoverCode = Convert.ToInt32(this.txtSEATCOVERCODE.DataValue);
- }
- if (this.cbCeaseFlag.Checked)
- {
- this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
- }
- else
- {
- this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
- }
- if (this.cbValueFlag.Checked)
- {
- this._thisGoodsEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
- }
- else
- {
- this._thisGoodsEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
- }
- this._thisGoodsEntity.ScrapSumFlag = (this.chkScrapSumFlag.Checked ? "1" : "0");
- this._thisGoodsEntity.GoodsLineType = (this.chkGLT.Checked ? "1" : "0");
- this._thisGoodsEntity.GoodsLineCode = this.chkGLT.Checked ? this.cbGLTDetail.SelectedValue.ToString() : "L";
- this._thisGoodsEntity.Remarks = this.txtRemarks.Text;
- //首先将未修改的图片从集合中删除
- for (int i = 0; i < _imgList.Count; i++)
- {
- this._picByteList.RemoveAt(Constant.INT_IS_ZERO);
- this._smallByteList.RemoveAt(Constant.INT_IS_ZERO);
- }
- this._imgList.Clear();
- //循环插入图片
- for (int i = 0; i < _picByteList.Count; i++)
- {
- GoodsImageEntity imgEntity = new GoodsImageEntity();
- imgEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
- byte[] buffer = _picByteList[i];
- imgEntity.Image = buffer;
- imgEntity.Thumbnail = _smallByteList[i];
- this._imgList.Add(imgEntity);
- }
- //如果是编辑模式,有被删除的图片,那么要把这些图片也加入到集合中
- if (this._updateImgList.Count != Constant.INT_IS_ZERO)
- {
- for (int i = 0; i < this._updateImgList.Count; i++)
- {
- GoodsImageEntity updateImgEntity = this._updateImgList[i];
- this._imgList.Add(updateImgEntity);
- }
- }
- if (this._formGoodsId == Constant.INT_IS_ZERO)
- {
- int MyReturn = (int)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.AddGoods(this._thisGoodsEntity, this._imgList, this._attList);
- }));
- if (MyReturn > Constant.INT_IS_ZERO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品档案", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- PageInitialization();
- }
- else if (MyReturn == -10)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "物料编码"), this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.scbSAPCode1.Focus();
- return;
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品档案", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- else
- {
- int MyReturn = SystemModuleProxy.Service.UpdateGoods(_thisGoodsEntity, _imgList, _attList);
- if (MyReturn > Constant.INT_IS_ZERO)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品档案", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- this.DialogResult = DialogResult.OK;
- }
- else if (MyReturn == -10)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "物料编码"), this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- this.scbSAPCode1.Focus();
- return;
- }
- else if (MyReturn == -500)
- {
- MessageBox.Show(Messages.MSG_CMN_W012, this.Text, MessageBoxButtons.OK,
- MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
- this.DialogResult = DialogResult.OK;
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品档案", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 上传缩略图
- /// </summary>
- private void btnUpload_Click(object sender, EventArgs e)
- {
- try
- {
- odlgFile.Filter = Constant.FILTER_PIC;
- odlgFile.FilterIndex = Constant.INT_IS_ZERO;
- odlgFile.RestoreDirectory = true;
- odlgFile.Title = "选择产品图片";
- odlgFile.FileName = null;
- odlgFile.RestoreDirectory = true;
- if (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());
- this._picByteList.Add(ImageToByte(PicImage));
- GetThumbnail(file);
- BindImg();
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 删除某缩略图
- /// </summary>
- private void btnDelete_Click(object sender, EventArgs e)
- {
- try
- {
- foreach (ListViewItem lvSelect in lvPic.SelectedItems)
- {
- int index = lvSelect.Index;
- if (index < Constant.INT_IS_ZERO)
- {
- index = Constant.INT_IS_ZERO;
- }
- ilPic.Images.RemoveAt(index);
- this._picByteList.RemoveAt(index);
- this._smallByteList.RemoveAt(index);
- lvPic.Items.RemoveAt(index);
- if (index < this._imgList.Count)
- {
- if (this._imgList[index].GoodsImageID != Constant.INT_IS_ZERO)
- {
- GoodsImageEntity deleteImgEntity = this._imgList[index];
- this._imgList[index].ValueFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
- this._updateImgList.Add(deleteImgEntity);
- this._imgList.RemoveAt(index);
- }
- }
- }
- BindImg();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 关闭窗体
- /// </summary>
- private void btnCancel_Click(object sender, EventArgs e)
- {
- this.DialogResult = DialogResult.OK;
- }
- /// <summary>
- /// 查看图片
- /// </summary>
- private void lvPic_DoubleClick(object sender, EventArgs e)
- {
- try
- {
- foreach (ListViewItem lvSelect in lvPic.SelectedItems)
- {
- int index = lvSelect.Index;
- if (index < Constant.INT_IS_ZERO)
- {
- index = Constant.INT_IS_ZERO;
- }
- F_CMN_0102 addGoods = new F_CMN_0102(_picByteList[index]);
- DialogResult dialogresult = addGoods.ShowDialog();
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// SAP物料编码改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtSAPRemark_TextChanged(object sender, EventArgs e)
- {
- if (this.dgvGoodsSap.CurrentRow == null)
- {
- return;
- }
- try
- {
- DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
- if (row != null)
- {
- row["materialremark"] = txtSAPRemark.Text;
- row.EndEdit();
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 加载页面所需的数据源
- /// </summary>
- private void LoadDataSource()
- {
- try
- {
- // 绑定釉料类别
- DataTable dtGlazeType = SystemModuleProxy.Service.GetDataDictionaryByType(Constant.DictionaryType.TPC002, Constant.INT_IS_ONE);
- if (dtGlazeType != null)
- {
- ddlGlazeTypeID.DisplayMember = "DictionaryValue";
- ddlGlazeTypeID.ValueMember = "DictionaryID";
- ddlGlazeTypeID.DataSource = dtGlazeType;
- }
- DataSet logos = SystemModuleProxy.Service.GetLogoInfo();
- if (logos != null && logos.Tables.Count > 0)
- {
- ftcLogo.DisplayMember = "LogoNameCode";
- ftcLogo.ValueMember = "LogoID";
- ftcLogo.DataSource = logos.Tables[0];
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 绑定缩略图到控件中
- /// </summary>
- private void BindImg()
- {
- try
- {
- //每次绑定要清空数据源
- this.ilPic.Images.Clear();
- //将缩略图二进制集合中的数据转换成图片文件
- List<Image> LSImageList = new List<Image>();
- foreach (byte[] smallby in _smallByteList)
- {
- LSImageList.Add(byteArrayToImage(smallby));
- }
- //添加数据源
- foreach (Image img in LSImageList)
- {
- ilPic.Images.Add(img);
- }
- this.ilPic.ImageSize = new Size(Constant.INT_IS_HUNDRED, Constant.INT_IS_HUNDRED);
- this.lvPic.LargeImageList = this.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();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 重绘缩略图并把缩略图转为二进制储存在集合众
- /// </summary>
- /// <param name="sourceFile">图片实体</param>
- /// <returns></returns>
- private void GetThumbnail(FileInfo sourceFile)
- {
- try
- {
- Image imgSource = Image.FromStream(sourceFile.OpenRead());
- ImageFormat thisFormat = imgSource.RawFormat;
- int sW = Constant.INT_IS_ZERO, sH = Constant.INT_IS_ZERO;
- // 按比例缩放
- int sWidth = imgSource.Width;
- int sHeight = imgSource.Height;
- int destWidth = Constant.INT_IS_HUNDRED;
- 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) / Constant.INT_IS_TWO, (destHeight - sH) /
- Constant.INT_IS_TWO, sW, sH), Constant.INT_IS_ZERO, Constant.INT_IS_ZERO,
- imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
- g.Dispose();
- //将重绘的图片转为二进制并保存
- Image image = (Image)outBmp;
- byte[] smallbuffer = ImageToByte(image);
- this._smallByteList.Add(smallbuffer);
- imgSource.Dispose();
- outBmp.Dispose();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 根据原图片宽高比获取缩略图的高(根据宽)
- /// </summary>
- /// <param name="BigWidth">原图宽度</param>
- /// <param name="BigHeight">原图高度</param>
- /// <param name="SmallWidth">缩略图宽度</param>
- /// <returns>缩略图的高度</returns>
- private int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
- {
- try
- {
- decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
- return Convert.ToInt32(SmallWidth / scale);
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 验证添加项
- /// </summary>
- private int ValidationText()
- {
- int ErrorID = 0;
- if (this.ddlGlazeTypeID.SelectedValue.ToString() == string.Empty)
- {
- ErrorID = 7;
- }
- if (this.txtGoodsName.Text == string.Empty)
- {
- ErrorID = 3;
- }
- if (scbGoodsType.SearchedItem == null)
- {
- ErrorID = 6;
- }
- if (this.txtGoodsCode.Text == string.Empty)
- {
- ErrorID = 1;
- }
- return ErrorID;
- }
- /// <summary>
- /// 绑定缩略图到缩略图集合中
- /// </summary>
- /// <param name="ImageData">图片集合</param>
- private void BindByteImage(DataSet ImageData)
- {
- try
- {
- foreach (DataRow dr in ImageData.Tables[0].Rows)
- {
- //将数据库中的缩略图取出
- this._smallByteList.Add((byte[])dr[2]);
- this._picByteList.Add((byte[])dr[3]);
- //绑定实体到修改图片集合中
- GoodsImageEntity imgEntity = new GoodsImageEntity();
- imgEntity.GoodsImageID = Convert.ToDecimal(dr[0]);
- imgEntity.GoodsID = Convert.ToDecimal(dr[1]);
- imgEntity.Thumbnail = (byte[])dr[2];
- imgEntity.Image = (byte[])dr[3];
- imgEntity.AccountID = Convert.ToDecimal(dr[4]);
- imgEntity.ValueFlag = Convert.ToDecimal(dr[5]);
- imgEntity.CreateTime = Convert.ToDateTime(dr[6]);
- imgEntity.CreateUserID = Convert.ToDecimal(dr[7]);
- imgEntity.UpdateTime = Convert.ToDateTime(dr[8]);
- imgEntity.UpdateUserID = Convert.ToDecimal(dr[9]);
- imgEntity.OPTimeStamp = Convert.ToDateTime(dr[10]);
- this._imgList.Add(imgEntity);
- }
- //绑定缩略图
- BindImg();
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 将数据库中的二进制转换成图片
- /// </summary>
- /// <param name="data">需要转换成图片的二进制数据</param>
- /// <returns>图片文件实体</returns>
- private static Image byteArrayToImage(object data)
- {
- try
- {
- System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
- System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
- return returnImage;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 将图片文件转换成二进制
- /// </summary>
- /// <param name="img">需要转换的图片</param>
- /// <returns>图片二进制数据</returns>
- private static byte[] ImageToByte(Image img)
- {
- try
- {
- 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;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 验证产品编号唯一性
- /// </summary>
- /// <param name="goodsCode">产品编号</param>
- /// <returns>是否重复,真为不重复,可插入</returns>
- private bool ValidationCode(string goodsCode)
- {
- try
- {
- GoodsEntity vgoods = new GoodsEntity();
- vgoods.GoodsCodeOnly = goodsCode;
- int i = ((DataSet)SystemModuleProxy.Service.SerachGoods(vgoods)).Tables[0].Rows.Count;
- if (i > Constant.INT_IS_ZERO)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 页面控件初始化
- /// </summary>
- private void PageInitialization()
- {
- //页面控件初始化
- this.txtGoodsCode.Text = "";
- //this.gtsGoodaType.GoodsTypeCode = null;
- //this.gtsGoodaType.GoodsTypeID = null;
- //this.gtsGoodaType.GoodsTypeName = null;
- //this.gtsGoodaType.Text = "";
- this.scbGoodsType.ClearValue();
- this.txtGoodsName.Text = "";
- this.txtGoodsModel.Text = "";
- this.txtGoodsSpecification.Text = "";
- this.txtMudWeight.Text = "";
- this.txtGlazeWeight.Text = "";
- //this.ddlGlazeTypeID.SelectedValue = null;
- this.txtProductionCycle.Text = "";
- this.txtLusterwareWeight.Text = "";
- this.txtRemarks.Text = "";
- this.lvPic.Items.Clear();
- this.cbCeaseFlag.Checked = true;
- this.cbValueFlag.Checked = true;
- this.chkGLT.Checked = false;
- this.txtSPM001.DataValue = 0;
- this.txtSPM002.DataValue = 0;
- this.txtMouldOutputCount.DataValue = 1;
- this.txtStandardGroutingNum.DataValue = 0;
- this.dtpStartingDate.Value = DateTime.Now.Date;
- //成员变量初始化
- this._thisGoodsEntity = new GoodsEntity();
- this._picByteList = new List<byte[]>();
- this._smallByteList = new List<byte[]>();
- this._imgList = new List<GoodsImageEntity>();
- this._updateImgList = new List<GoodsImageEntity>();
- this.txtUnitPrice.DataValue = 0;
- this.txtPlateLimitNum.DataValue = 0;
- this.txtReservedDays.DataValue = 0;
- this.txtPackageNum.Text = "";
- this.txtOutletDistance.Text = "";
- this.scbSAPCode1.Text = "";
- this.txtMaterialRemark.Text = "";
- this.txtMouldWeight.DataValue = null;
- this.txtMouldCost.DataValue = null;
- this.txtSEATCOVERCODE.DataValue = null;
- this.txtWaterLabelCode.Clear();
- this.chkScrapSumFlag.Checked = true;
- this.txtMouldMaterialCode.Clear();
- foreach (DataRow row in this._sapInfo.Rows)
- {
- row["materialcode"] = DBNull.Value;
- row["materialremark"] = DBNull.Value;
- row["WaterLabelCode"] = DBNull.Value;
- }
- this._sapInfo.AcceptChanges();
- }
- #endregion
- #region SAP物料
- private void dgvGoodsSap_SelectionChanged(object sender, EventArgs e)
- {
- if (this.dgvGoodsSap.CurrentRow == null)
- {
- //this.scbSAPCode2.Clear();
- //this.txtSAPRemark.Clear();
- return;
- }
- try
- {
- this.scbSAPCode2.Text = this.dgvGoodsSap.CurrentRow.Cells["colmaterialcode"].Value + "";
- this.txtSAPRemark.Text = this.dgvGoodsSap.CurrentRow.Cells["colmaterialremark"].Value + "";
- this.txtSAPWaterLabelCode.Text = this.dgvGoodsSap.CurrentRow.Cells["colWaterLabelCode"].Value + "";
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- private void txtSAPCode_Validated(object sender, EventArgs e)
- {
- //if (this.dgvGoodsSap.CurrentRow == null)
- //{
- // return;
- //}
- //try
- //{
- // DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
- // if (row != null)
- // {
- // row["materialcode"] = txtSAPCode.Text;
- // row.EndEdit();
- // }
- //}
- //catch (Exception ex)
- //{
- // // 对异常进行共通处理
- // ExceptionManager.HandleEventException(this.ToString(),
- // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- //}
- }
- private void txtSAPRemark_Validated(object sender, EventArgs e)
- {
- //if (this.dgvGoodsSap.CurrentRow == null)
- //{
- // return;
- //}
- //try
- //{
- // DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
- // if (row != null)
- // {
- // row["materialremark"] = txtSAPRemark.Text;
- // row.EndEdit();
- // }
- //}
- //catch (Exception ex)
- //{
- // // 对异常进行共通处理
- // ExceptionManager.HandleEventException(this.ToString(),
- // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- //}
- }
- private void txtSAPWaterLabelCode_Validated(object sender, EventArgs e)
- {
- if (this.dgvGoodsSap.CurrentRow == null)
- {
- return;
- }
- try
- {
- DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
- if (row != null)
- {
- row["WaterLabelCode"] = txtSAPWaterLabelCode.Text;
- row.EndEdit();
- }
- }
- 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 scbSAPCode2_TextValueChanged(object sender, WinForm.Controls.ScbSearchBox.TextChangeEventArgs e)
- {
- if (this.dgvGoodsSap.CurrentRow == null)
- {
- return;
- }
- try
- {
- DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
- if (row != null)
- {
- row["materialcode"] = scbSAPCode2.Text;
- row.EndEdit();
- }
- }
- 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 scbSAPCode2_VisibleChanged(object sender, EventArgs e)
- //{
- // if (this.dgvGoodsSap.CurrentRow == null)
- // {
- // return;
- // }
- // try
- // {
- // DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
- // if (row != null)
- // {
- // row["materialcode"] = scbSAPCode2.Text;
- // row.EndEdit();
- // }
- // }
- // catch (Exception ex)
- // {
- // // 对异常进行共通处理
- // ExceptionManager.HandleEventException(this.ToString(),
- // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- // }
- //}
- #endregion
- private void txtMouldOutputCount_TextChanged(object sender, EventArgs e)
- {
- try
- {
- int mouldOutputCount = (this.txtMouldOutputCount.DataValue.HasValue ? Convert.ToInt32(this.txtMouldOutputCount.DataValue) : 1);
- int standardGroutingNum = (this.txtStandardGroutingNum.DataValue.HasValue ? Convert.ToInt32(this.txtStandardGroutingNum.DataValue) : 0);
- this.txtStandardGroutingSum.DataValue = mouldOutputCount * standardGroutingNum;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- private void chkGLT_Click(object sender, EventArgs e)
- {
- this.cbGLTDetail.Enabled = this.chkGLT.Checked;
- }
- }
- }
|