BaoKai_202508-Wms-Jingwang..../WMS.FrmStrategy/FrmStrAreaRepDet.cs

452 lines
18 KiB
C#
Raw Permalink Normal View History

2025-08-24 09:35:55 +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.Strategy;
using WMS.Common;
using DevExpress.XtraEditors.Repository;
using WMS.Model.Base;
using WMS.Ctrl;
using WMS.Business;
using WMS.Business.Strategy;
using WMS.Business.Common;
namespace WMS.FrmStrategy
{
public partial class FrmStrAreaRepDet : FormBase
{
#region
private StrAreaRepModel StrAreaRepModel = new StrAreaRepModel();
private List<StrAreaRepStorageModel> listStrAreaRepStorage = new List<StrAreaRepStorageModel>();
private List<StrAreaRepGoodsModel> listStrAreaRepGoods = new List<StrAreaRepGoodsModel>();
private StrAreaRepStorageModel StrAreaRepStorage = new StrAreaRepStorageModel();
private StrAreaRepGoodsModel StrAreaRepGoods = new StrAreaRepGoodsModel();
private int flag = -1;//0:新增;1:修改;
private DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit lueAreas = new RepositoryItemLookUpEdit();
#endregion
#region
/// <summary>
/// 构造函数 用于新增
/// </summary>
public FrmStrAreaRepDet()
{
Inti();
flag = 0;
}
/// <summary>
/// 构造函数 用于修改
/// </summary>
/// <param name="LogisticsComInfo"></param>
public FrmStrAreaRepDet(StrAreaRepModel StrAreaRep)
{
Inti();
flag = 1;
StrAreaRepModel = StrAreaRep;
this.Text = "库区间定时补货策略信息-" + StrAreaRepModel.STRATEGY_ID;
}
private void FrmStrAreaRepDet_Load(object sender, EventArgs e)
{
if (flag == 1)
{
//绑仓库库区明细
string errText = string.Empty;
string strDataSet = string.Empty;
StrAreaRepStorageModel queryStrAreaRepStorage = new StrAreaRepStorageModel();
queryStrAreaRepStorage.STRATEGY_ID = StrAreaRepModel.STRATEGY_ID;
try
{
listStrAreaRepStorage = IBussFactory<BussStrAreaRepStorage>.Instance().GetStrAreaRepStorageList(queryStrAreaRepStorage);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (errText == string.Empty)
{
}
else
{
SystemCommon.ShowInfoMessageBox(errText);
}
//绑商品明细
errText = string.Empty;
strDataSet = string.Empty;
StrAreaRepGoodsModel queryStrAreaRepGoods = new StrAreaRepGoodsModel();
queryStrAreaRepGoods.STRATEGY_ID = StrAreaRepModel.STRATEGY_ID;
try
{
listStrAreaRepGoods = IBussFactory<BussStrAreaRepGoods>.Instance().GetStrAreaRepGoodsList(queryStrAreaRepGoods);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
StrAreaRepModel.UPDATE_MAN = userData.USER_ID;
}
else if (flag == 0)
{
//StrAreaRepModel.ADDED_FLAG = "0";
//StrAreaRepModel.NULL_FLAG = "0";
//StrAreaRepModel.PRODUCE_FLAG = "0";
StrAreaRepModel.STRATEGY_STATE = "0";
StrAreaRepModel.CREATE_MAN = userData.USER_ID;
listStrAreaRepStorage.Add(new StrAreaRepStorageModel());
}
bsStrAreaRep.DataSource = StrAreaRepModel;
bsStrAreaRepStorage.DataSource = listStrAreaRepStorage;
GVStrAreaRepStorage.RefreshData();
bsStrAreaRepGoods.DataSource = listStrAreaRepGoods;
GVStrAreaRepGoods.RefreshData();
}
private void Inti()
{
InitializeComponent();
//单位下拉框
lueUnit.NullText = "";
lueUnit.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("VC_DICTIONARY_NAME", "单位"));
lueUnit.ValueMember = "VC_CHAR_VALUE";
lueUnit.DisplayMember = "VC_DICTIONARY_NAME";
DataTable strResult = new DataTable();
try
{
strResult = IBussFactory<BussCommon>.Instance().GetCustomCtrlData("t_sys_dictionary_tab", "VC_CHAR_VALUE", "VC_DICTIONARY_NAME", " VC_DICTIONARY_TYPE = 'vc_uom' and c_flag = '1'", "");
if (strResult != null)
{
lueUnit.DataSource = strResult;
}
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
lueStorage.NullText = "";
lueStorage.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("STORAGE_NAME", "仓库"));
lueStorage.ValueMember = "STORAGE_ID";
lueStorage.DisplayMember = "STORAGE_NAME";
try
{
strResult = IBussFactory<BussCommon>.Instance().GetCustomCtrlData("T_BASE_STORAGEINFO", "STORAGE_ID", "STORAGE_NAME", "", "");
if (strResult != null)
{
lueStorage.DataSource = strResult;
}
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
lueArea.NullText = "";
lueArea.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("STORAGE_AREA_NAME", "库区"));
lueArea.ValueMember = "STORAGE_AREA_ID";
lueArea.DisplayMember = "STORAGE_AREA_NAME";
try
{
strResult = IBussFactory<BussCommon>.Instance().GetCustomCtrlData("T_BASE_STORAGE_AREA", "STORAGE_AREA_ID", "STORAGE_AREA_NAME", "", "");
if (strResult != null)
{
lueArea.DataSource = strResult;
}
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
lueAreas.NullText = "";
lueAreas.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("STORAGE_AREA_NAME", "库区"));
lueAreas.ValueMember = "STORAGE_AREA_ID";
lueAreas.DisplayMember = "STORAGE_AREA_NAME";
}
#endregion
private void btnAddTab_Click(object sender, EventArgs e)
{
StrAreaRepStorageModel model = new StrAreaRepStorageModel();
model.STRATEGY_ID = StrAreaRepModel.STRATEGY_ID;
listStrAreaRepStorage.Add(model);
bsStrAreaRepStorage.DataSource = listStrAreaRepStorage;
GVStrAreaRepStorage.RefreshData();
}
private void btnDelTab_Click(object sender, EventArgs e)
{
StrAreaRepStorage = GVStrAreaRepStorage.GetFocusedRow() as StrAreaRepStorageModel;
listStrAreaRepStorage.Remove(StrAreaRepStorage);
bsStrAreaRepStorage.DataSource = listStrAreaRepStorage;
GVStrAreaRepStorage.RefreshData();
}
private void btnDelGoods_Click(object sender, EventArgs e)
{
StrAreaRepGoods = GVStrAreaRepGoods.GetFocusedRow() as StrAreaRepGoodsModel;
listStrAreaRepGoods.Remove(StrAreaRepGoods);
bsStrAreaRepGoods.DataSource = listStrAreaRepGoods;
GVStrAreaRepGoods.RefreshData();
}
private void btnSave_Click(object sender, EventArgs e)
{
/*验证*/
if (string.IsNullOrEmpty(txtStartegyName.Text))
{
SystemCommon.ShowInfoMessageBox("请输入策略名称");
txtStartegyName.Focus();
return;
}
if (string.IsNullOrEmpty(txtTime.Text) || txtTime.Text == "0")
{
SystemCommon.ShowInfoMessageBox("请输入补货间隔");
txtTime.Focus();
return;
}
List<StrAreaRepStorageModel> listAllStrAreaRepStorage = new List<StrAreaRepStorageModel>();
string errText = string.Empty;
string strDataSet = string.Empty;
StrAreaRepStorageModel queryStrAreaRepStorage = new StrAreaRepStorageModel();
try
{
listAllStrAreaRepStorage = IBussFactory<BussStrAreaRepStorage>.Instance().GetStrAreaRepStorageList(queryStrAreaRepStorage);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (listStrAreaRepGoods.Count == 0) {
SystemCommon.ShowInfoMessageBox("请选择商品");
GVStrAreaRepGoods.Focus();
return;
}
foreach (var item in listStrAreaRepStorage)
{
if (string.IsNullOrEmpty(item.STORAGE_ID)) {
SystemCommon.ShowInfoMessageBox("请选择仓库");
GVStrAreaRepStorage.Focus();
return;
}
if (string.IsNullOrEmpty(item.OUT_AREA_ID))
{
SystemCommon.ShowInfoMessageBox("请选择出库库区");
GVStrAreaRepStorage.Focus();
return;
}
if (string.IsNullOrEmpty(item.IN_AREA_ID))
{
SystemCommon.ShowInfoMessageBox("请选择入库库区");
GVStrAreaRepStorage.Focus();
return;
}
if (item.IN_AREA_ID == item.OUT_AREA_ID)
{
SystemCommon.ShowInfoMessageBox("出库库区、入库库区不能相同");
GVStrAreaRepStorage.Focus();
return;
}
if (listStrAreaRepStorage.FindAll(p => p.STORAGE_ID == item.STORAGE_ID && p.OUT_AREA_ID == item.OUT_AREA_ID && p.IN_AREA_ID == item.IN_AREA_ID).Count > 1)
{
SystemCommon.ShowInfoMessageBox("所选仓库库区不能重复");
GVStrAreaRepStorage.Focus();
return;
}
if (listAllStrAreaRepStorage.Exists(p => p.STORAGE_ID == item.STORAGE_ID && p.OUT_AREA_ID == item.OUT_AREA_ID && p.IN_AREA_ID == item.IN_AREA_ID && p.STRATEGY_ID != item.STRATEGY_ID))
{
SystemCommon.ShowInfoMessageBox("所选入库库区已存在于其它库区间定时补货策略");
GVStrAreaRepStorage.Focus();
return;
}
}
if (flag == 0)
{ //增加
/*增加*/
errText = string.Empty;
try
{
errText = IBussFactory<BussStrAreaRep>.Instance().InsertStrAreaRepAndTab(StrAreaRepModel, listStrAreaRepStorage, listStrAreaRepGoods);
if (string.IsNullOrEmpty(errText))//如果增加成功
{
SystemCommon.ShowInfoMessageBox("增加成功");
}
else
{
SystemCommon.ShowInfoMessageBox("增加失败" + errText);
return;
}
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
}
else if (flag == 1)//修改
{
/*修改*/
errText = string.Empty;
try
{
errText = IBussFactory<BussStrAreaRep>.Instance().UpdateStrAreaRepAndTab(StrAreaRepModel, listStrAreaRepStorage, listStrAreaRepGoods);
if (string.IsNullOrEmpty(errText))//如果修改成功
{
SystemCommon.ShowInfoMessageBox("修改成功");
}
else
{
SystemCommon.ShowInfoMessageBox("修改失败" + errText);
return;
}
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
}
this.Close();
this.Dispose();
}
private void btnClose_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != SystemCommon.ShowMessageBoxResult("确定放弃正在编辑的数据?"))
{
return;
}
this.Close();
this.Dispose();
}
private void GVStrAreaRepStorage_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")
{
DataTable strResult = new DataTable();
try
{
strResult = IBussFactory<BussCommon>.Instance().GetCustomCtrlData("T_BASE_STORAGE_AREA", "STORAGE_AREA_ID", "STORAGE_AREA_NAME", " STORAGE_ID = '" + GVStrAreaRepStorage.GetFocusedRowCellValue("STORAGE_ID").ToString() + "'", "");
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (strResult != null)
lueAreas.DataSource = strResult;
e.RepositoryItem = lueAreas;//当前单元格绑定控件
}
}
/// <summary>
/// 选择商品
/// </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)
{
StrAreaRepGoodsModel model = new StrAreaRepGoodsModel();
model.GOODS_ID = item.GOODS_ID;
model.GOODS_NAME = item.GOODS_NAME;
model.UNIT = item.UNIT;
model.NUM = decimal.Parse(txtAdd.Text);
model.STOCK_NUM = decimal.Parse(txtMin.Text);
model.STRATEGY_ID = StrAreaRepModel.STRATEGY_ID;
//判断该商品是否已经在入库商品明细中后添加
bool had = false;
foreach (StrAreaRepGoodsModel wntModel in listStrAreaRepGoods)
{
if (wntModel.GOODS_ID == model.GOODS_ID)
{
had = true;
}
}
if (!had)
{
listStrAreaRepGoods.Add(model);
}
}
if (listStrAreaRepGoods.Count > 0)
{
GVStrAreaRepGoods.RefreshData();
////焦点置于采购数量
//GVStrAreaRepGoods.FocusedColumn = GVStrAreaRepGoods.Columns[1];
//GVStrAreaRepGoods.FocusedRowHandle = 0;
}
else
{
SystemCommon.ShowInfoMessageBox("未选择任何商品或所选择的商品已存在,请重新选择");
}
}
private void repositoryItemHyperLinkEdit1_Click(object sender, EventArgs e)
{
// StrAreaRepGoodsModel model = GVStrAreaRepGoods.GetFocusedRow() as StrAreaRepGoodsModel;
// 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();
// }
}
}
}