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.SystemManage; using WMS.Business.Base; namespace WMS.FrmBaseData { /// /// 商品信息 /// public partial class FrmGoodsInfoDet : FormBase { #region 变量 //商品分类实体集合 List listGoodsTypeModel = new List(); /// /// 当前选择的SKU /// SKUModel skuModel = new SKUModel(); /// /// 当前商品的SKU集合 /// private List listskuModel = new List(); /// /// 商品信息实体 /// public static JWGoodsInfoModel goodsModel = new JWGoodsInfoModel(); /// /// 商品计量单位实体 /// List ListGoodsMeasureModel = new List(); /// /// 需要增加的类 /// List newGoodsMeasureModel = new List(); /// /// 商品供应商 /// List ListGoodsProviderModel = new List(); List ListDictionaryTabModel = new List(); static FrmGoodsInfoDet frmGoodsDet; //窗体标记 0新增 1修改 2查看 3编辑导入的数据 static int iFlag = -1; public static int IFlag { get { return FrmGoodsInfoDet.iFlag; } set { FrmGoodsInfoDet.iFlag = value; } } static string strGoodsID = string.Empty; public static string StrGoodsID { get { return FrmGoodsInfoDet.strGoodsID; } set { FrmGoodsInfoDet.strGoodsID = value; } } #endregion #region 实例化窗体 /// /// 实例化窗体 /// /// public static FrmGoodsInfoDet GetInstance() { if (frmGoodsDet == null || frmGoodsDet.IsDisposed) { frmGoodsDet = new FrmGoodsInfoDet(); } return frmGoodsDet; } #endregion #region 构造方法 public FrmGoodsInfoDet() { InitializeComponent(); // boolCode = IBussFactory.Instance().GetParamValue("autoGoodsID"); // boolGoodsId = IBussFactory.Instance().GetParamValue("BarCodeGoodsID"); } #endregion #region 窗体加载 string boolCode = "1"; string boolGoodsId = "0"; private void FrmGoodsInfoDet_Load(object sender, EventArgs e) { #region 判断系统参数中是否编号可控 //if (boolCode == "0") //{ // txt_GoodsID.Enabled = true; //} //else //{ // txt_GoodsID.Enabled = false; //} //if (iFlag == 1) //{ // txt_GoodsID.Enabled = false; //} #endregion #region 判断条形码是否可输入 if (boolCode == "0") { txtTXM.Enabled = true; } else { txtTXM.Enabled = false; } #endregion //检测是否开启SKU if (boolSku == "0") { RefreshSKU(); } else { pageSku.PageVisible = false; ctrlButtons3.Visible = false; ctrlButtons4.Visible = false; ctrlButtons5.Visible = false; } #region 下拉控件 //供应商 LueProvider.LoadData(); //ABC分类 LueABC.LoadData(); //存储类型 LueStored.LoadData(); //保质期 LueBZQ.LoadData(); //重量单位 LueZLDW.LoadData(); //商品单位 LueSPDW.LoadData(); //季节 LueJJ.LoadData(); //商品状态 LueStatus.LoadData(); #endregion #region 绑定商品单位 ListDictionaryTabModel = IBussFactory.Instance().GetDictionaryTab("vc_uom"); UNITBINGSOURCE.DataSource = ListDictionaryTabModel; #endregion #region 绑定供应商 List listProvider = IBussFactory.Instance().GetProviderList(new ProviderModel()); providerModelBindingSource.DataSource = listProvider; #endregion #region 商品分类绑定 //获取商品分类 GoodsTypeModel model = new GoodsTypeModel(); listGoodsTypeModel = IBussFactory.Instance().GetGoodsTypeList(model); goodsTypeModelBindingSource.DataSource = listGoodsTypeModel; #endregion #region 新增,修改,批量修改,查看获取信息 if (IFlag == 0) { goodsModel = new JWGoodsInfoModel(); ListGoodsMeasureModel.Clear(); ListGoodsProviderModel.Clear(); //goodsModel.STATUS = "1"; //goodsModel.SC_FLAG = "0"; //goodsModel.HAZARDOUS = "0"; } if (IFlag == 1) { //GetGoodsMeasure(goodsModel.INVENTORY_ITEM_ID); //GetGoodsPrivider(goodsModel.INVENTORY_ITEM_ID); } if (IFlag == 2) { //获取商品信息 List list = IBussFactory.Instance().GetGoodsList(strGoodsID, "", "", ""); if (list.Count == 0) { SystemCommon.ShowInfoMessageBox("找不到该商品"); Close(); Dispose(); return; } goodsModel = list[0]; GetGoodsMeasure(goodsModel.INVENTORY_ITEM_ID); GetGoodsPrivider(goodsModel.INVENTORY_ITEM_ID); 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; } } radioGroup1.Enabled = false; ctrlButtons1.Enabled = false;//取消关闭按钮 GvGYS.OptionsBehavior.Editable = false; GvJLDW.OptionsBehavior.Editable = false; } if(goodsModel!=null) goodsInfoModelBindingSource.DataSource = goodsModel; // goodsInfoModelBindingSource.DataSource = goodsModel; //if (goodsModel.HAZARDOUS == "0") //{ // radioButton1.Checked = true; //} //else //{ // radioButton2.Checked = true; //} //显示图片 //if (goodsModel.IMG != null && goodsModel.IMG.Length > 0) //{ // try // { // MemoryStream ms = new System.IO.MemoryStream(goodsModel.IMG); // pictureEdit.Image = System.Drawing.Image.FromStream(ms); // } // catch (Exception ex) // { // } //} #endregion } #endregion #region 获取商品规格 /// /// 获取商品规格 /// private void RefreshSKU() { string errText = string.Empty; string strResult = string.Empty; SKUModel tempSKU = new SKUModel(); //tempSKU.INVENTORY_ITEM_ID = goodsModel.INVENTORY_ITEM_ID; try { listskuModel = IBussFactory.Instance().GetSKUList(tempSKU); bsSKU.DataSource = listskuModel; gridView1.RefreshData(); } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } } #endregion #region 获取商品单位 /// /// 获取商品单位 /// private void GetGoodsMeasure(string strGoodsID) { //获取商品单位 ListGoodsMeasureModel = IBussFactory.Instance().GetGoodsMeasureDataTable(strGoodsID); if(ListGoodsMeasureModel!=null) goodsMeasureModelBindingSource.DataSource = ListGoodsMeasureModel; } #endregion #region 获取商品供应商 /// /// 获取商品供应商 /// private void GetGoodsPrivider(string strGoodsID) { //获取商品供应商 List listGoodsProvider = IBussFactory.Instance().GetGoodsPrividerDataTale(strGoodsID); goodsProviderModelBindingSource.DataSource = listGoodsProvider; } #endregion #region 按钮(确定) private void ctrlButtons1_Click(object sender, EventArgs e) { if (Validation() == false) return; string errText = string.Empty; //图片 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(); //goodsModel.IMG = img; } if (iFlag == 3 || iFlag == 2) { FrmClose(); return; } //goodsModel.CREATE_MAN = userData.USER_ID; //goodsModel.UPDATE_MAN = userData.USER_ID; //goodsModel.STORAGE_ID = userData.STORAGE_ID; //goodsModel.STORAGE_NAME = userData.STORAGE_NAME; foreach (var item in ListGoodsMeasureModel) { item.CREATE_MAN = userData.USER_ID; item.UPDATE_MAN = userData.USER_ID; //item.INVENTORY_ITEM_ID = goodsModel.INVENTORY_ITEM_ID; } if (iFlag == 0) { errText = IBussFactory.Instance().AddGoodsInfo(goodsModel, ListGoodsMeasureModel, ListGoodsProviderModel); if (errText != "") { SystemCommon.ShowErrorMessageBox(errText); } else { SystemCommon.ShowInfoMessageBox("添加成功!"); DialogResult = DialogResult.OK; } } else if (iFlag == 1) { errText = IBussFactory.Instance().UpdateGoodsInfo(goodsModel, ListGoodsMeasureModel, ListGoodsProviderModel); if (errText != "") { SystemCommon.ShowErrorMessageBox(errText); } else { SystemCommon.ShowInfoMessageBox("修改成功!"); DialogResult = DialogResult.OK; } } } #endregion #region 按钮(关闭) private void ctrlButtons2_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; } #endregion #region 验证 /// /// 验证 /// /// private bool Validation() { xtraTabControl1.Focus(); 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 == "") //{ // SystemCommon.ShowErrorMessageBox("请选择供应商!"); // LueProvider.Focus(); // return false; //} if (LueSPDW.EditValue.ToString() == "") { SystemCommon.ShowErrorMessageBox("请选择基本单位!"); LueSPDW.Focus(); return false; } //ListGoodsMeasureModel = goodsMeasureModelBindingSource.DataSource as List; //foreach (var item in ListGoodsMeasureModel) //{ // //if (item.UNIT_ID == goodsModel.UNIT) // //{ // // SystemCommon.ShowErrorMessageBox("换算单位不能与最小单位相同!"); // // xtraTabControl1.SelectedTabPageIndex = 0; // // GvJLDW.Focus(); // // return false; // //} // if (ListGoodsMeasureModel.Count(p => p.UNIT_ID == item.UNIT_ID) > 1) // { // SystemCommon.ShowErrorMessageBox("换算单位列表中有重复的单位:" + item.UNIT_NAME); // xtraTabControl1.SelectedTabPageIndex = 0; // GvJLDW.Focus(); // return false; // } // //if (item.CONVERSION_RATIO > 1) // //{ // // SystemCommon.ShowErrorMessageBox(item.UNIT_NAME + ":换算比率不能大于1"); // // xtraTabControl1.SelectedTabPageIndex = 0; // // GvJLDW.Focus(); // // return false; // //} // if (item.CONVERSION_RATIO <= 0) // { // SystemCommon.ShowErrorMessageBox(item.UNIT_NAME + ":换算比率必须大于0"); // xtraTabControl1.SelectedTabPageIndex = 0; // GvJLDW.Focus(); // return false; // } // //if (item.BOX_CASES_STORED < 0) // //{ // // SystemCommon.ShowErrorMessageBox(item.BOX_CASES_STORED + ":不能小于0"); // // xtraTabControl1.SelectedTabPageIndex = 0; // // GvJLDW.Focus(); // // return false; // //} // //if (item.CASES_STORED < 0) // //{ // // SystemCommon.ShowErrorMessageBox(item.CASES_STORED + ":不能小于0"); // // xtraTabControl1.SelectedTabPageIndex = 0; // // GvJLDW.Focus(); // // return false; // //} // //if (item.CONVERSION_RATIO < 0) // //{ // // SystemCommon.ShowErrorMessageBox(item.CONVERSION_RATIO + ":不能小于0"); // // xtraTabControl1.SelectedTabPageIndex = 0; // // GvJLDW.Focus(); // // return false; // //} // //if (item.GLONG < 0) // //{ // // SystemCommon.ShowErrorMessageBox(item.GLONG + ":不能小于0"); // // xtraTabControl1.SelectedTabPageIndex = 0; // // GvJLDW.Focus(); // // return false; // //} // //if (item.GWIDTH < 0) // //{ // // SystemCommon.ShowErrorMessageBox(item.GWIDTH + ":不能小于0"); // // xtraTabControl1.SelectedTabPageIndex = 0; // // GvJLDW.Focus(); // // return false; // //} // //if (item.GHEIGHT < 0) // //{ // // SystemCommon.ShowErrorMessageBox(item.GHEIGHT + ":不能小于0"); // // xtraTabControl1.SelectedTabPageIndex = 0; // // GvJLDW.Focus(); // // return false; // //} // //if (item.GVOLUME < 0) // //{ // // SystemCommon.ShowErrorMessageBox(item.GVOLUME + ":不能小于0"); // // xtraTabControl1.SelectedTabPageIndex = 0; // // GvJLDW.Focus(); // // return false; // //} //} foreach (var item in ListGoodsProviderModel) { if (ListGoodsProviderModel.Count(p => p.PROVIDER_ID == item.PROVIDER_ID) > 1) { SystemCommon.ShowErrorMessageBox("供应商列表中有重复的供应商"); xtraTabControl1.SelectedTabPageIndex = 1; GvJLDW.Focus(); return false; } } return true; } #endregion #region 关闭窗体 /// /// 关闭窗体 /// /// /// private void FrmGoodsInfoDet_FormClosing(object sender, FormClosingEventArgs e) { FrmClose(); } /// /// 关闭窗体 /// private void FrmClose() { frmGoodsDet.Dispose(); frmGoodsDet.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); //goodsModel.GVOLUME = decVOLUME; txtVOLUME.Text = decVOLUME.ToString(); } /// /// 计算体积 /// /// /// private void GvJLDW_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (GvJLDW.RowCount > 0) { if (GvJLDW.GetRowCellValue(0, "UNIT_ID") != null) { LueSPDW.EditValue = GvJLDW.GetRowCellValue(0, "UNIT_ID").ToString(); } int rowid = e.RowHandle; if (rowid < 0) return; if (e.Column.Name == "colGLONG" || e.Column.Name == "colGWIDTH" || e.Column.Name == "colGHEIGHT") { decimal dlong = decimal.Parse(GvJLDW.GetRowCellValue(rowid, "GLONG").ToString()); decimal dwidth = decimal.Parse(GvJLDW.GetRowCellValue(rowid, "GWIDTH").ToString()); decimal dheight = decimal.Parse(GvJLDW.GetRowCellValue(rowid, "GHEIGHT").ToString()); decimal dvolumn = 0; dvolumn = dlong * dwidth * dheight; GvJLDW.SetRowCellValue(rowid, "GVOLUME", dvolumn); } } } private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) { if (listskuModel.Count == 0) { return; } skuModel = new SKUModel(); skuModel = gridView1.GetFocusedRow() as SKUModel; } private void ctrlButtons3_Click(object sender, EventArgs e) { SKUModel addSKUModel = new SKUModel(); FrmGoodsSKUDet.IFlag = 0; FrmGoodsSKUDet.skuModel = addSKUModel; FrmGoodsSKUDet.GetInstance().ShowDialog(); //FrmGoodsSKUDet.skuModel.INVENTORY_ITEM_ID = goodsModel.INVENTORY_ITEM_ID; listskuModel.Insert(0, FrmGoodsSKUDet.skuModel); bsSKU.DataSource = listskuModel; gridView1.RefreshData(); } private void ctrlButtons4_Click(object sender, EventArgs e) { FrmGoodsSKUDet.IFlag = 1; FrmGoodsSKUDet.skuModel = skuModel; FrmGoodsSKUDet.GetInstance().ShowDialog(); skuModel = FrmGoodsSKUDet.skuModel; bsSKU.DataSource = listskuModel; gridView1.RefreshData(); } private void ctrlButtons5_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(skuModel.SKU_ID)) { if (DialogResult.Yes == SystemCommon.ShowMessageBoxResult("确定删除规格")) { string errText = string.Empty; string strResult = string.Empty; try { errText = IBussFactory.Instance().DeleteSKU(skuModel.SKU_ID); if (errText == string.Empty) { listskuModel.RemoveAll(p => p.SKU_ID == skuModel.SKU_ID); bsSKU.DataSource = listskuModel; gridView1.RefreshData(); } else { SystemCommon.ShowInfoMessageBox(errText); } } catch (Exception) { SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!"); } } } } private void txt_GoodsID_TextChanged(object sender, EventArgs e) { if (boolGoodsId == "1") { txtTXM.Text = txt_GoodsID.Text; //goodsModel.BARCODE = txt_GoodsID.Text; } } private void LueSPDW_EditValueChanged(object sender, EventArgs e) { if (LueSPDW.EditValue.ToString().Length > 0) { if (ListGoodsMeasureModel.Count > 0) { ListGoodsMeasureModel[0].UNIT_ID = LueSPDW.EditValue.ToString(); } else { GoodsMeasureModel dtcModle = new GoodsMeasureModel(); dtcModle.UNIT_ID = LueSPDW.EditValue.ToString(); //dtcModle.INVENTORY_ITEM_ID = txt_GoodsID.Text; dtcModle.CONVERSION_RATIO = 1; ListGoodsMeasureModel.Insert(0, dtcModle); } goodsMeasureModelBindingSource.DataSource = ListGoodsMeasureModel; GvJLDW.RefreshData(); } } private void txtRemark_EditValueChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { if(txt_GoodsID.Text.Trim().Length==0) { return; } //GoodsMeasureModel modleGoodsMea = new GoodsMeasureModel(); //modleGoodsMea.INVENTORY_ITEM_ID = txt_GoodsID.Text; //ListGoodsMeasureModel.Add(modleGoodsMea); //newGoodsMeasureModel.Add(modleGoodsMea); //GvJLDW.RefreshData(); } private void button2_Click(object sender, EventArgs e) { if(txt_GoodsID.Text.Trim().Length==0) { SystemCommon.ShowInfoMessageBox("请输入商品编号"); txt_GoodsID.Focus(); return; } if (GvJLDW.RowCount > 0) { int i = GvJLDW.FocusedRowHandle; if (i > 0) { string goodsId = txt_GoodsID.Text.Trim(); string unitId = GvJLDW.GetFocusedRowCellValue("UNIT_ID").ToString(); IBussFactory.Instance().DeleteMeasure(goodsId, unitId); GetGoodsMeasure(goodsId); } } } private void rLueUint_EditValueChanged(object sender, EventArgs e) { //if (GvJLDW.RowCount > 0) //{ // if (GvJLDW.FocusedRowHandle == 0) // { // LookUpEdit lookUpEdit = sender as LookUpEdit; // string val = lookUpEdit.EditValue.ToString();// GvJLDW.GetRowCellValue(0, "UNIT_ID").ToString(); // if (val != LueSPDW.EditValue.ToString()) // { // LueSPDW.EditValue = val; // } // } //} } private void btnAddProvider_Click(object sender, EventArgs e) { GoodsProviderModel provider = new GoodsProviderModel(); //provider.INVENTORY_ITEM_ID = txt_GoodsID.Text; ListGoodsProviderModel.Add(provider); } private void btnRemoveProvider_Click(object sender, EventArgs e) { } private void btnRemoveUnit_Click(object sender, EventArgs e) { if(newGoodsMeasureModel.Count==0) { SystemCommon.ShowInfoMessageBox("没有新增的单位"); return; } if(txt_GoodsID.Text.Trim().Length==0) { return; } foreach (GoodsMeasureModel item in newGoodsMeasureModel) { //if(item.GOODS_MEASURE_NAME.Trim().Length==0) //{ // continue; //} IBussFactory.Instance().AddGoodsMeasure(item); } GetGoodsMeasure(txt_GoodsID.Text); SystemCommon.ShowInfoMessageBox("增加成功"); } } }