BaoKai_202508_Wms_Jingwang_.../WMS.Frm.Base/FrmSelectLocAndPutInID.cs
2025-08-24 21:52:42 +08:00

168 lines
6.0 KiB
C#

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.Model.Stock;
using WMS.Common;
using WMS.Business;
using WMS.Business.Stock;
namespace WMS.Frm.Base
{
public partial class FrmSelectLocAndPutInID : FormBase
{
public MIStockModel stock = new MIStockModel();
private List<MIStockModel> listMIStock = new List<MIStockModel>();//某库区某商品库存集合
public FrmSelectLocAndPutInID(MIStockModel stock, string storageID, string areaID, string storageName, string areaName)
{
InitializeComponent();
if (stock == null)
{
stock = new MIStockModel();
}
this.stock = stock;
bsStock.DataSource = this.stock;
txtStorageID.Text = storageID;
txtStorageName.Text = storageName;
txtAreaID.Text = areaID;
txtAreaName.Text = areaName;
//查库存
string errText = string.Empty;
MIStockModel queryMI = new MIStockModel();
queryMI.STORAGE_ID = txtStorageID.Text;
queryMI.AREA_ID = txtAreaID.Text;
queryMI.GOODS_ID = stock.GOODS_ID;
string strResult = string.Empty;
try
{
listMIStock = IBussFactory<BussMIStock>.Instance().GetMIStockList(queryMI);
}
catch (Exception)
{
SystemCommon.ShowInfoMessageBox("未知错误,请检查网络连接!如仍无法解决问题请联系我们!");
}
if (errText == string.Empty)
{
listMIStock.RemoveAll(p => p.SHELVES_NUM == 0);
}
else
{
SystemCommon.ShowInfoMessageBox(errText);
}
List<MIStockModel> temp = new List<MIStockModel>();
foreach (var item in listMIStock)
{
if (temp.Exists(p => p.LOCATION_ID == item.LOCATION_ID)) { continue; }
MIStockModel t = new MIStockModel();
t.LOCATION_ID = item.LOCATION_ID;
temp.Add(t);
}
//库位下拉框
lueLoc.Properties.NullText = "";
lueLoc.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("LOCATION_ID", "库位"));
lueLoc.Properties.ValueMember = "LOCATION_ID";
lueLoc.Properties.DisplayMember = "LOCATION_ID";
lueLoc.Properties.DataSource = temp;
luePutInID.Properties.NullText = "";
luePutInID.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("PUTIN_ID", "入库批次号"));
luePutInID.Properties.ValueMember = "PUTIN_ID";
luePutInID.Properties.DisplayMember = "PUTIN_ID";
}
public FrmSelectLocAndPutInID()
{
}
private static FrmSelectLocAndPutInID frmSelectLocAndPutInID;
/// <summary>
/// 实例化FrmSelectLocAndPutInID的一个对象
/// </summary>
/// <returns>FrmSelectLocAndPutInID对象</returns>
public static FrmSelectLocAndPutInID GetInstance(MIStockModel stock, string storageID, string areaID, string storageName, string areaName)
{
if (frmSelectLocAndPutInID == null || frmSelectLocAndPutInID.IsDisposed)
{
frmSelectLocAndPutInID = new FrmSelectLocAndPutInID(stock, storageID, areaID, storageName,areaName);
}
return frmSelectLocAndPutInID;
}
public static FrmSelectLocAndPutInID GetInstance()
{
if (frmSelectLocAndPutInID == null || frmSelectLocAndPutInID.IsDisposed)
{
frmSelectLocAndPutInID = new FrmSelectLocAndPutInID();
}
return frmSelectLocAndPutInID;
}
private void FrmSelectLocAndPutInID_Load(object sender, EventArgs e)
{
}
private void btnClose_Click(object sender, EventArgs e)
{
DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
private void btnConfirm_Click(object sender, EventArgs e)
{
if (lueLoc.EditValue == null || string.IsNullOrEmpty(lueLoc.EditValue.ToString()))
{
SystemCommon.ShowInfoMessageBox("请选择库位");
lueLoc.Focus();
return;
}
else if (luePutInID.EditValue == null || string.IsNullOrEmpty(luePutInID.EditValue.ToString()))
{
SystemCommon.ShowInfoMessageBox("请选择批次号");
luePutInID.Focus();
return;
}
DialogResult = System.Windows.Forms.DialogResult.OK;
}
private void lueLoc_EditValueChanged(object sender, EventArgs e)
{
if (lueLoc.EditValue != null) {
List<MIStockModel> mistock = listMIStock.FindAll(p => p.LOCATION_ID == lueLoc.EditValue.ToString());
luePutInID.Properties.DataSource = mistock;
if (mistock.Count == 1) {
luePutInID.EditValue = mistock[0].PUTIN_ID;
}
if (!string.IsNullOrEmpty(lueLoc.EditValue.ToString()))
{
luePutInID_EditValueChanged(sender, e);
}
}
}
private void luePutInID_EditValueChanged(object sender, EventArgs e)
{
if (lueLoc.EditValue != null && luePutInID.EditValue != null)
{
MIStockModel tempStock = listMIStock.Find(p => p.LOCATION_ID == lueLoc.EditValue.ToString() && p.PUTIN_ID == luePutInID.EditValue.ToString());
if (tempStock != null) {
stock = tempStock;
bsStock.DataSource = stock;
}
}
}
}
}