| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019 |
- /*******************************************************************************
- * 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;
- }
- #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.txtPackageNum.Text = drGoods["PackageNum"].ToString();
- this.txtOutletDistance.Text = drGoods["OutletDistance"].ToString();
- this.txtMaterialCode.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(txtMaterialCode.Text))
- {
- this.txtMaterialCode.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)
- {
- // 250327 产品编码的回车和空格 去除
- if (ValidationCode(this.txtGoodsCode.Text.Trim().Replace(" ", "").Replace("\r", "").Replace("\n", "")) == false)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "产品编码"), this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- }
- //实体赋值
- if (this._thisGoodsEntity == null)
- {
- this._thisGoodsEntity = new GoodsEntity();
- }
- // 250327 产品编码的回车和空格 去除
- this._thisGoodsEntity.GoodsCode = this.txtGoodsCode.Text.Trim().Replace(" ", "").Replace("\r", "").Replace("\n", "");
- 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.txtMaterialCode.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.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.txtMaterialCode.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.txtMaterialCode.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);
- }
- }
- #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 ==null || this.ddlGlazeTypeID.SelectedValue == null)
- {
- ErrorID = 7;
- }
- if (this.txtGoodsName.Text == string.Empty)
- {
- ErrorID = 3;
- }
- if (scbGoodsType == null || scbGoodsType.SearchedItem == null)
- {
- ErrorID = 6;
- }
- if (this.txtGoodsCode.Text == string.Empty
- || String.IsNullOrEmpty(this.txtGoodsCode.Text.Trim())
- || String.IsNullOrEmpty(this.txtGoodsCode.Text.Trim().Replace(" ","").Replace("\r","").Replace("\n", ""))
- )
- {
- 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.txtMaterialCode.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.txtSAPCode.Clear();
- //this.txtSAPRemark.Clear();
- return;
- }
- try
- {
- this.txtSAPCode.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);
- }
- }
- #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);
- }
- }
- }
- }
|