/*******************************************************************************
* 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
{
///
/// 新建或编辑产品档案信息
///
public partial class F_MST_0502 : FormBase
{
#region 成员变量
//页面状态
private Constant.FormMode _formStatus;
// 产品ID
private int _formGoodsId;
// 产品图片二进制集合
private List _picByteList = new List();
// 产品图片缩略图二进制集合
private List _smallByteList = new List();
// 产品图片实体集合
private List _imgList = new List();
// 已存在的图片实体集合(修改)
private List _updateImgList = new List();
// 产品附件实体集合
private List _attList = new List();
// 当前编辑实体
private GoodsEntity _thisGoodsEntity = new GoodsEntity();
#endregion
#region 构造函数
///
/// 新建/编辑产品档案窗体构造
///
/// 窗体模式,0为新建,1为编辑
/// 编辑产品ID
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 事件
///
/// 窗体加载
///
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);
}
}
///
/// 获取数据事件
///
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);
}
}
///
/// 上传缩略图
///
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);
}
}
///
/// 删除某缩略图
///
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);
}
}
///
/// 关闭窗体
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
///
/// 查看图片
///
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 私有方法
///
/// 加载页面所需的数据源
///
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;
}
}
///
/// 绑定缩略图到控件中
///
private void BindImg()
{
try
{
//每次绑定要清空数据源
this.ilPic.Images.Clear();
//将缩略图二进制集合中的数据转换成图片文件
List LSImageList = new List();
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;
}
}
///
/// 重绘缩略图并把缩略图转为二进制储存在集合众
///
/// 图片实体
///
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;
}
}
///
/// 根据原图片宽高比获取缩略图的高(根据宽)
///
/// 原图宽度
/// 原图高度
/// 缩略图宽度
/// 缩略图的高度
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;
}
}
///
/// 验证添加项
///
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;
}
///
/// 绑定缩略图到缩略图集合中
///
/// 图片集合
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;
}
}
///
/// 将数据库中的二进制转换成图片
///
/// 需要转换成图片的二进制数据
/// 图片文件实体
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;
}
}
///
/// 将图片文件转换成二进制
///
/// 需要转换的图片
/// 图片二进制数据
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;
}
}
///
/// 验证产品编号唯一性
///
/// 产品编号
/// 是否重复,真为不重复,可插入
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;
}
}
///
/// 页面控件初始化
///
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();
this._smallByteList = new List();
this._imgList = new List();
this._updateImgList = new List();
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
}
}