BaoKai_202508_Wms_Jingwang_.../WMS.FrmSC/FrmGoodsMaterialDet.cs

418 lines
14 KiB
C#
Raw Normal View History

2025-08-24 21:52:42 +08:00
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.SC;
using WMS.Common;
using DevExpress.XtraEditors.Repository;
using WMS.Model.Base;
//using WMS.FrmBaseData;
using WMS.Ctrl;
using WMS.Business;
using WMS.Business.Common;
using WMS.Business.SC;
namespace WMS.FrmSC
{
public partial class FrmGoodsMaterialDet : FormBase
{
#region
private List<GoodsInfoModel> listGoods = new List<GoodsInfoModel>();
private GoodsMaterialModel goodsMaterialModel = new GoodsMaterialModel();
private List<GoodsMaterialModel> listGoodsMaterial = new List<GoodsMaterialModel>();
private int flag = -1;//0:新增;1:修改;
private string currentGoodID = string.Empty;
DataTable tabUnit = null;
#endregion
#region
/// <summary>
/// 构造函数 用于新增
/// </summary>
public FrmGoodsMaterialDet(List<GoodsInfoModel> listGoods)
{
InitializeComponent();
flag = 0;
this.listGoods = listGoods;
}
/// <summary>
/// 构造函数 用于修改
/// </summary>
/// <param name="LogisticsComInfo"></param>
public FrmGoodsMaterialDet(List<GoodsMaterialModel> list)
{
InitializeComponent();
flag = 1;
listGoodsMaterial = list;
this.Text = "商品原材料对应关系-" + list[0].GOODS_ID;
currentGoodID = list[0].GOODS_ID;
}
private void FrmGoodsMaterialDet_Load(object sender, EventArgs e)
{
LEPStoID.LoadData();
//单位下拉框
lueUnit.NullText = "";
lueUnit.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("VC_DICTIONARY_NAME", "单位"));
lueUnit.ValueMember = "VC_CHAR_VALUE";
lueUnit.DisplayMember = "VC_DICTIONARY_NAME";
try
{
tabUnit = IBussFactory<BussCommon>.Instance().GetCustomCtrlData("t_sys_dictionary_tab", "VC_CHAR_VALUE", "VC_DICTIONARY_NAME", " VC_DICTIONARY_TYPE = 'vc_uom' and c_flag = '1'", "");
}
catch (Exception ex)
{
SystemCommon.ShowInfoMessageBox("加载单位时出错了:" + ex.Message);
}
lueUnit.DataSource = tabUnit;
if (flag == 1)
{
bsGoodsMaterial.DataSource = listGoodsMaterial;
GVGoodsMaterial.RefreshData();
dicGoods.Enabled = false;
dicGoods.t_dictonary.Text = listGoodsMaterial[0].GOODS_NAME;
}
}
#endregion
#region
private void btnDel_Click(object sender, EventArgs e)
{
if (listGoodsMaterial.Count == 0)
{
SystemCommon.ShowInfoMessageBox("请先选择要删除的数据");
return;
}
goodsMaterialModel = GVGoodsMaterial.GetFocusedRow() as GoodsMaterialModel;
listGoodsMaterial.Remove(goodsMaterialModel);
bsGoodsMaterial.DataSource = listGoodsMaterial;
GVGoodsMaterial.RefreshData();
}
#endregion
#region
private void btnSave_Click(object sender, EventArgs e)
{
/*验证*/
if (string.IsNullOrEmpty(dicGoods.t_dictonary.Text))
{
SystemCommon.ShowInfoMessageBox("请选择成品");
dicGoods.Focus();
return;
}
if (t_goodsNum.Text.Trim().Length == 0)
{
SystemCommon.ShowInfoMessageBox("基础数量不能为空");
t_goodsNum.Focus();
return;
}
if (!SystemCommon.IsPositiveFloat(t_goodsNum.Text.Trim()))
{
SystemCommon.ShowInfoMessageBox("基础数量为数字");
t_goodsNum.Focus();
t_goodsNum.SelectAll();
return;
}
foreach (var item in listGoodsMaterial)
{
if (item.STAND_NUM == 0)
{
SystemCommon.ShowInfoMessageBox("标准原料数必须大于0");
GVGoodsMaterial.Focus();
return;
}
if (item.MAX_NUM == 0)
{
SystemCommon.ShowInfoMessageBox("最大原料数必须大于0");
GVGoodsMaterial.Focus();
return;
}
if (item.MAX_NUM < item.STAND_NUM)
{
SystemCommon.ShowInfoMessageBox("最大原料数不能小于标准原料数");
GVGoodsMaterial.Focus();
return;
}
item.GOODS_ID = currentGoodID;
item.GOODS_NUM =decimal.Parse( t_goodsNum.Text);
item.GOODS_UNIT = LEPStoID.EditValue.ToString();
item.SCALING = (Math.Round(item.STAND_NUM / item.GOODS_NUM,4)).ToString();
GVGoodsMaterial.RefreshData();
}
if (flag == 0)
{ //增加
/*增加*/
string errText = string.Empty;
try
{
errText = IBussFactory<BussGoodsMaterial>.Instance().InsertGoodsMaterial(listGoodsMaterial);
if (string.IsNullOrEmpty(errText))//如果增加成功
{
SystemCommon.ShowInfoMessageBox("增加成功");
}
}
catch (Exception ex)
{
SystemCommon.ShowInfoMessageBox("新增出错了:" + ex.Message);
}
}
else if (flag == 1)//修改
{
/*修改*/
string errText = string.Empty;
try
{
errText = IBussFactory<BussGoodsMaterial>.Instance().UpdateGoodsMaterial(listGoodsMaterial);
if (string.IsNullOrEmpty(errText))//如果修改成功
{
SystemCommon.ShowInfoMessageBox("修改成功");
}
}
catch (Exception ex)
{
SystemCommon.ShowInfoMessageBox("修改出错了:" + ex.Message);
}
}
}
#endregion
#region
private void btnClose_Click(object sender, EventArgs e)
{
if (DialogResult.OK != SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?"))
{
return;
}
this.Close();
this.Dispose();
}
#endregion
//private void GVGoodsMaterialStorage_CustomRowCellEditForEditing(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
//{
// if (e.RowHandle < 0 || flag == -1)
// {
// return;
// }
// if (e.Column.Name == "colOUT_AREA_ID" || e.Column.Name == "colIN_AREA_ID")
// {
// string strResult = string.Empty;
// try
// {
// strResult = WebLockConfig.Instance.Common.GetCustomCtrlData("T_BASE_STORAGE_AREA", "STORAGE_AREA_ID", "STORAGE_AREA_NAME", " STORAGE_ID = '" + GVGoodsMaterialStorage.GetFocusedRowCellValue("STORAGE_ID").ToString() + "'", "");
// }
// catch (Exception)
// {
// SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
// }
// lueAreas.Properties.DataSource = Newtonsoft.Json.JsonConvert.DeserializeObject<DataTable>(strResult);
// e.RepositoryItem = lueAreas;//当前单元格绑定控件
// }
//}
/// <summary>
#region
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ctrlDicGoods_Button_Click(object sender, EventArgs e)
{
if (ctrlDicGoods.SelectTable.Rows.Count == 0)
{
//SystemCommon.ShowInfoMessageBox("您未选择商品!");
return;
}
//商品集合
List<GoodsInfoModel> listGoodsInfoModel = ConvertHelper<GoodsInfoModel>.ConvertToList(ctrlDicGoods.SelectTable);
/*将选择的商品加入明细*/
foreach (GoodsInfoModel item in listGoodsInfoModel)
{
GoodsMaterialModel model = new GoodsMaterialModel();
model.GOODS_ID = dicGoods.TextBoxFlag;
model.GOODS_NAME = dicGoods.t_dictonary.Text;
model.MATERIAL_ID = item.GOODS_ID;
model.MATERIAL_NAME = item.GOODS_NAME;
model.PRICE = item.PRICE;
model.UNIT = item.UNIT;
model.OPERAT_MAN = userData.USER_ID;
model.OPERAT_DATE = System.DateTime.Now;
//判断该商品是否已经在明细中后添加
bool had = false;
foreach (GoodsMaterialModel wntModel in listGoodsMaterial)
{
if (wntModel.MATERIAL_ID == model.MATERIAL_ID)
{
had = true;
}
}
if (!had)
{
listGoodsMaterial.Add(model);
}
}
if (listGoodsMaterial.Count > 0)
{
bsGoodsMaterial.DataSource = listGoodsMaterial;
GVGoodsMaterial.RefreshData();
////焦点置于采购数量
//GVGoodsMaterialGoods.FocusedColumn = GVGoodsMaterialGoods.Columns[1];
//GVGoodsMaterialGoods.FocusedRowHandle = 0;
}
else
{
bsGoodsMaterial.DataSource = listGoodsMaterial;
GVGoodsMaterial.RefreshData();
SystemCommon.ShowInfoMessageBox("未选择任何原材料或所选择的原材料已存在,请重新选择");
}
}
#endregion
/// <summary>
#region
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dicGoods_Button_Click(object sender, EventArgs e)
{
if (dicGoods.SelectTable.Rows.Count == 0)
{
SystemCommon.ShowInfoMessageBox("检测是否配置了物料属性!");
return;
}
//商品集合
List<GoodsInfoModel> listGoodsInfo = ConvertHelper<GoodsInfoModel>.ConvertToList(dicGoods.SelectTable);
if (listGoods.Exists(p => p.GOODS_ID == listGoodsInfo[0].GOODS_ID))
{
SystemCommon.ShowInfoMessageBox("您选择的商品已经是组合商品,请找到该商品后修改");
return;
}
currentGoodID = listGoodsInfo[0].GOODS_ID;//保存当前成品ID
dicGoods.t_dictonary.Text = listGoodsInfo[0].GOODS_NAME;
foreach (var item in listGoodsMaterial)
{
item.GOODS_ID = dicGoods.TextBoxFlag;
item.GOODS_NAME = dicGoods.t_dictonary.Text;
}
}
#endregion
//private void repositoryItemHyperLinkEdit1_Click(object sender, EventArgs e)
//{
// GoodsMaterialModel model = GVGoodsMaterial.GetFocusedRow() as GoodsMaterialModel;
// if (model != null && !string.IsNullOrEmpty(model.GOODS_ID))
// {
// FrmGoodsInfoDet.IFlag = 2;
// FrmGoodsInfoDet.StrGoodsID = model.GOODS_ID;
// LoadForm load = new LoadForm();
// DevExpress.XtraSplashScreen.SplashScreenManager.ShowForm(load, load.GetType(), false, true, false, 0);
// DevExpress.XtraSplashScreen.SplashScreenManager.Default.SetWaitFormDescription("正在读取商品信息....");
// FrmGoodsInfoDet.GetInstance().Show();
// }
//}
private void Unit_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
if (e.Column.FieldName == "UNIT")
{
if (e.Value == null)
{
return;
}
else
{
try
{
var arrayUnitRows = tabUnit.Select(string.Format("VC_CHAR_VALUE='{0}'", e.Value.ToString().Trim()));
e.DisplayText = arrayUnitRows == null ? "" : arrayUnitRows[0]["VC_DICTIONARY_NAME"].ToString();
}
catch (Exception)
{
}
}
}
}
#region
private void GVGoodsMaterial_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
{
if (e.RowHandle < 0)
{
return;
}
goodsMaterialModel = GVGoodsMaterial.GetFocusedRow() as GoodsMaterialModel;
goodsMaterialModel.OPERAT_MAN = userData.USER_ID;
goodsMaterialModel.OPERAT_DATE = DateTime.Now;
if (e.Column.Name == "colSTAND_NUM")
{
if (goodsMaterialModel.MAX_NUM == 0)
{
goodsMaterialModel.MAX_NUM = goodsMaterialModel.STAND_NUM;
goodsMaterialModel.SCALING = (Math.Round(goodsMaterialModel.STAND_NUM / goodsMaterialModel.GOODS_NUM, 4)).ToString();
}
}
}
#endregion
private void LEPStoID_EditValueChanged(object sender, EventArgs e)
{
if(listGoodsMaterial==null)
{
return;
}
if(listGoodsMaterial.Count>0)
{
foreach(GoodsMaterialModel goodsModel in listGoodsMaterial)
{
goodsModel.UNIT = LEPStoID.EditValue.ToString() ;
}
GVGoodsMaterial.RefreshData();
}
}
}
}