| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859 |
- /*******************************************************************************
- * 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();
- #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._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.txtPackageNum.Text = drGoods["PackageNum"].ToString();
- this.txtOutletDistance.Text = drGoods["OutletDistance"].ToString();
- this.txtMaterialCode.Text = drGoods["MaterialCode"].ToString();
- this.txtGroutmaterialcode.Text = drGoods["groutmaterialcode"].ToString();
- this.txtMaterialRemark.Text = drGoods["MaterialRemark"].ToString();
- this.txtCopies.Text = drGoods["printcopies"].ToString();
- 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);
- }
- }
- }
- 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 ((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.txtMaterialCode.Text.Trim();
- this._thisGoodsEntity.Groutmaterialcode = this.txtGroutmaterialcode.Text.Trim();
- this._thisGoodsEntity.MaterialRemark = this.txtMaterialRemark.Text;
- this._thisGoodsEntity.PrintCopies = (this.txtCopies.DataValue.HasValue ? Convert.ToInt32(this.txtCopies.DataValue) : 0);
- 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.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;
- }
- }
- 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.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.txtGroutmaterialcode.Text = "";
- this.txtMaterialRemark.Text = "";
- this.txtMouldWeight.DataValue = null;
- this.txtMouldCost.DataValue = null;
- this.txtSEATCOVERCODE.DataValue = null;
- this.chkScrapSumFlag.Checked = true;
- }
- #endregion
- }
- }
|