using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using WMS.Frm.Base; using WMS.Model.Base; using WMS.Model.SystemManage; using WMS.Common; using System.IO; using System.Data.SqlClient; using System.Drawing.Imaging; using DevExpress.XtraEditors; using WMS.Ctrl; using DevExpress.XtraGrid.Views.Grid; using WMS.Business; using WMS.Business.Base; using WMS.Business.SystemManage; namespace WMS.FrmBaseData { /// /// 商品规格信息 /// public partial class FrmGoodsSKUDet : FormBase { #region 变量 /// /// 商品规格信息实体 /// public static SKUModel skuModel = new SKUModel(); static FrmGoodsSKUDet frmSKUDet; //窗体标记 0新增 1修改 2查看 3编辑导入的数据 static int iFlag = -1; public static int IFlag { get { return FrmGoodsSKUDet.iFlag; } set { FrmGoodsSKUDet.iFlag = value; } } static string strGoodsID = string.Empty; public static string StrGoodsID { get { return FrmGoodsSKUDet.strGoodsID; } set { FrmGoodsSKUDet.strGoodsID = value; } } #endregion #region 实例化窗体 /// /// 实例化窗体 /// /// public static FrmGoodsSKUDet GetInstance() { if (frmSKUDet == null || frmSKUDet.IsDisposed) { frmSKUDet = new FrmGoodsSKUDet(); } return frmSKUDet; } #endregion #region 构造方法 public FrmGoodsSKUDet() { InitializeComponent(); } #endregion #region 窗体加载 private void FrmGoodsSKUDet_Load(object sender, EventArgs e) { bsSKU.DataSource = skuModel; #region #region 判断系统参数中是否编号可控 if (IBussFactory.Instance().GetParamValue("autoGoodsID") == "0") { txt_SKUID.Enabled = true; } else { txt_SKUID.Enabled = false; } if (iFlag == 1) { txt_SKUID.Enabled = false; } #endregion #endregion #region 下拉控件 //供应商 LueProvider.LoadData(); //ABC分类 LueABC.LoadData(); //存储类型 LueStored.LoadData(); //保质期 LueBZQ.LoadData(); //重量单位 LueZLDW.LoadData(); //商品规格单位 LueSPDW.LoadData(); //季节 LueJJ.LoadData(); //商品规格状态 LueStatus.LoadData(); #endregion #region 新增,修改,批量修改,查看获取信息 if (IFlag == 0) { skuModel = new SKUModel(); skuModel.STATUS = "1"; skuModel.GIFT_FLAG = "0"; skuModel.SC_FLAG = "0"; skuModel.HAZARDOUS = "0"; } if (IFlag == 2) { //获取商品规格信息 List list = IBussFactory.Instance().GetSKUList(skuModel); if (list.Count == 0) { SystemCommon.ShowInfoMessageBox("找不到该商品规格"); Close(); Dispose(); return; } skuModel = list[0]; foreach (Control item in this.Controls) { //item.Enabled = false; switch (item.GetType().Name) { case "PictureEdit": PictureEdit pictureEdit = item as PictureEdit; pictureEdit.Properties.ReadOnly = true; break; case "WMSCtrlTextBox": WMSCtrlTextBox textBox = item as WMSCtrlTextBox; textBox.Properties.ReadOnly = true; textBox.Enabled = false; break; case "TreeListLookUpEdit": TreeListLookUpEdit treeListLookUpEdit = item as TreeListLookUpEdit; treeListLookUpEdit.Properties.ReadOnly = true; break; case "LookUpEditSystem": LookUpEditSystem lookUpEditSystem = item as LookUpEditSystem; lookUpEditSystem.Properties.ReadOnly = true; break; case "RadioButton": RadioButton radioButton = item as RadioButton; radioButton.Enabled = false; break; case "MemoEdit": MemoEdit memoEdit = item as MemoEdit; memoEdit.Properties.ReadOnly = true; break; //case "GridControlCustom": // GridControlCustom gridControlCustom = item as GridControlCustom; // GridView view = gridControlCustom.MainView as GridView; // view.OptionsBehavior.Editable = false; // break; default: break; } } } bsSKU.DataSource = skuModel; //if (skuModel.HAZARDOUS == "0") //{ // radioButton1.Checked = true; //} //else //{ // radioButton2.Checked = true; //} //显示图片 if (skuModel.IMG != null) { MemoryStream ms = new System.IO.MemoryStream(skuModel.IMG); pictureEdit.Image = System.Drawing.Image.FromStream(ms); } #endregion } #endregion #region 按钮(确定) private void ctrlButtons1_Click(object sender, EventArgs e) { if (Validation() == false) return; string errText = string.Empty; //if (radioButton1.Checked == true) //{ // skuModel.HAZARDOUS = "1"; //} //else //{ // skuModel.HAZARDOUS = "0"; //} //图片 if (pictureEdit.Image != null) { MemoryStream Ms = new MemoryStream(); pictureEdit.Image.Save(Ms, pictureEdit.Image.RawFormat); byte[] img = new byte[Ms.Length]; Ms.Position = 0; Ms.Read(img, 0, Convert.ToInt32(Ms.Length)); Ms.Close(); skuModel.IMG = img; } FrmClose(); //if (iFlag == 3 || iFlag == 2) //{ // FrmClose(); // return; //} //SKUModel sku = bsSKU.DataSource as SKUModel; //sku.CREATE_MAN = userData.USER_ID; //sku.UPDATE_MAN = userData.USER_ID; //string strGoodsInfo = Newtonsoft.Json.JsonConvert.SerializeObject(sku); //if (iFlag == 0) //{ // string ID = string.Empty; // errText = WebLockConfig.Instance.WebSKU.InsertSKU(strGoodsInfo,ref ID); // sku.SKU_ID = ID; // if (errText != "") // { // SystemCommon.ShowErrorMessageBox(errText); // } // else // { // SystemCommon.ShowInfoMessageBox("添加成功!"); // FrmClose(); // } //} //else if (iFlag == 1) //{ // errText = WebLockConfig.Instance.WebSKU.UpdateSKU(strGoodsInfo); // if (errText != "") // { // SystemCommon.ShowErrorMessageBox(errText); // } // else // { // SystemCommon.ShowInfoMessageBox("修改成功!"); // FrmClose(); // } //} } #endregion #region 按钮(关闭) private void ctrlButtons2_Click(object sender, EventArgs e) { FrmClose(); } #endregion #region 验证 /// /// 验证 /// /// private bool Validation() { this.Focus(); if (iFlag == 0) { SKUModel sku = new SKUModel(); sku.SKU_ID = txt_SKUID.Text; List li =IBussFactory.Instance().GetSKUList(sku); if (li.Count > 0) { SystemCommon.ShowInfoMessageBox("该商品编号已经存在!请重新输入"); txt_SKUID.Focus(); txt_SKUID.SelectAll(); return false; } } if (txtGoodsName.Text == "") { SystemCommon.ShowErrorMessageBox("请填写商品规格名称!"); txtGoodsName.Focus(); return false; } //if (txtGoodsShortName.Text == "") //{ // SystemCommon.ShowErrorMessageBox("请填写商品规格简称!"); // txtGoodsShortName.Focus(); // return false; //} //if (txtPyName.Text == "") //{ // SystemCommon.ShowErrorMessageBox("请填写助记码!"); // txtPyName.Focus(); // return false; //} if (LueProvider.EditValue == null) { SystemCommon.ShowErrorMessageBox("请选择供应商!"); LueProvider.Focus(); return false; } if (LueSPDW.EditValue == null) { SystemCommon.ShowErrorMessageBox("请选择单位!"); LueSPDW.Focus(); return false; } return true; } #endregion #region 关闭窗体 /// /// 关闭窗体 /// /// /// private void FrmGoodsSKUDet_FormClosing(object sender, FormClosingEventArgs e) { FrmClose(); } /// /// 关闭窗体 /// private void FrmClose() { frmSKUDet.Dispose(); frmSKUDet.Close(); } #endregion /// /// 计算体积 /// /// /// private void txtLong_TextChanged(object sender, EventArgs e) { if (txtLong.Text == "" || txtWidth.Text == "" || txtHeight.Text == "") return; decimal temp = 0; if (!decimal.TryParse(txtLong.Text, out temp)) return; if (!decimal.TryParse(txtWidth.Text, out temp)) return; if (!decimal.TryParse(txtHeight.Text, out temp)) return; decimal decVOLUME = decimal.Parse(txtLong.Text) * decimal.Parse(txtWidth.Text) * decimal.Parse(txtHeight.Text); skuModel.GVOLUME = decVOLUME; txtVOLUME.Text = decVOLUME.ToString(); } } }