using ComponentFactory.Krypton.Toolkit;
using NXWMS.Client.Model.AppModels.Condition.Balance;
using NXWMS.Client.Model.AppModels.Condition.Base;
using NXWMS.Client.Model.AppModels.Result.Balance;
using NXWMS.Client.Model.AppModels.Result.Base;
using NXWMS.Client.Model.AppModels.Result.Common;
using NXWMS.Client.Model.AppModels.Result.OutStock;
using NXWMS.Client.Model.CoreModels;
using NXWMS.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Windows.Forms;
namespace NXWMS.Forms.OutStock.frmOutstockChild
{
///
/// 发货审核
///
public partial class frmChildInvoiceCheck : KryptonForm
{
///
/// 窗体构造函数
///
public frmChildInvoiceCheck()
{
InitializeComponent();
}
#region 全局变量
///
/// 发货单主键ID
///
public string InvoiceId { get; set; }
///
/// 数据库中的发货单所有数据(包括主、明细表)。
/// 未进行编辑过。
///
private WmsOutInvoiceResult InvoiceDataNotEdit = new WmsOutInvoiceResult();
private WmsBalanceAllocateStatus AutoAllocateBalanceMsg = new WmsBalanceAllocateStatus();
#endregion
#region 初始化数据
///
/// 窗体加载函数
///
///
///
private void frmChildInvoiceCheck_Load(object sender, EventArgs e)
{
InitComboBoxItemData();
LoadWmsOutInvoiceDtlData();
kcmb_AllocateType.SelectedIndex = 1;
}
///
/// 初始化下拉列表数据
///
private void InitComboBoxItemData()
{
/*
ToDo:后续把下拉列表转为 后台获取数据,目前是写死的。
*/
List results = new List();
#region 库区
var regionResult = BaseServices.regionService.GetList(new RegionSearchCondition { IsUsed = true, ItemSQL = "REGION_CODE,REGION_NAME,AREA_NAME,AREA_CODE,WAREHOUSE_CODE,WAREHOUSE_NAME" });
if (regionResult.Status == OperateStatus.Success)
{
kcmb_RegionMsg.Items.Clear();
kcmb_RegionMsg.Items.Add(new ListItem
{
Value = "",
Text = "请选择",
});
foreach (RegionResult item in regionResult.Data.RowData.ToList())
{
kcmb_RegionMsg.Items.Add(new ListItem
{
Value = item.REGION_CODE,
Text = item.REGION_NAME,
});
}
kcmb_RegionMsg.SelectedIndex = 0;
}
else
{
kcmb_RegionMsg.Items.Clear();
KryptonMessageBox.Show(regionResult.Message);
}
#endregion
}
///
/// 调用服务端接口,请求发货单明细表数据
///
///
private string LoadWmsOutInvoiceDtlData()
{
var result = WmsInvoiceService.wmsOutInvoiceService.GetWmsOutInvoiceDtlListForId(new WmsOutInvoiceResult { INVOICE_ID = Convert.ToInt32(this.InvoiceId) });
if (result.Status == OperateStatus.Success)
{
InvoiceDataNotEdit = result.Data;
kdgv_InvoiceDtlData.Rows.Clear();
foreach (WmsOutInvoiceDtlResult item in result.Data.WmsOutInvoiceDtlList)
{
int index = kdgv_InvoiceDtlData.Rows.Add();
kdgv_InvoiceDtlData.Rows[index].Cells[0].Value = index + 1;
kdgv_InvoiceDtlData.Rows[index].Cells[1].Value = item.MATERIEL_CODE;
kdgv_InvoiceDtlData.Rows[index].Cells[2].Value = item.MATERIEL_NAME;
kdgv_InvoiceDtlData.Rows[index].Cells[3].Value = item.MATERIEL_BARCODE;
kdgv_InvoiceDtlData.Rows[index].Cells[4].Value = item.MATERIEL_SPEC;
kdgv_InvoiceDtlData.Rows[index].Cells[5].Value = item.BATCH_NO;
kdgv_InvoiceDtlData.Rows[index].Cells[6].Value = item.INVOICE_DEMAND_QTY;
kdgv_InvoiceDtlData.Rows[index].Cells[7].Value = item.UNIT_CODE;
kdgv_InvoiceDtlData.Rows[index].Cells[8].Value = item.PACKAGE_CODE;
}
kdgv_InvoiceDtlData.ClearSelection();
return string.Empty;
}
else
{
return result.Message;
}
}
#endregion
#region 按钮事件
private void kcmb_AllocateType_SelectionChangeCommitted(object sender, EventArgs e)
{
if (kcmb_AllocateType.Text == "自动分配")
{
AutoAllocateBalanceMsg = null;
kdgv_AllowBalanceData.Columns[0].ReadOnly = true;
kdgv_AllowBalanceData.Rows.Clear();
foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
{
dvr.Cells[9].Value = null;
dvr.Cells[10].Value = null;
dvr.Cells[9].Style.BackColor = dvr.Cells[1].Style.BackColor;
dvr.Cells[10].Style.BackColor = dvr.Cells[1].Style.BackColor;
}
var result = WmsInvoiceService.wmsOutInvoiceService.InvoiceAllocationBalanceAuto(InvoiceDataNotEdit);
if (result.Status == OperateStatus.Success)
{
AutoAllocateBalanceMsg = result.Data;
foreach (WmsStkBalanceDtlResult item in result.Data.BalanceDtlResultLst)
{
int index = kdgv_AllowBalanceData.Rows.Add();
kdgv_AllowBalanceData.Rows[index].Cells[0].Value = true;
kdgv_AllowBalanceData.Rows[index].Cells[1].Value = index + 1;
kdgv_AllowBalanceData.Rows[index].Cells[2].Value = item.BALANCE_ID;
kdgv_AllowBalanceData.Rows[index].Cells[3].Value = item.TRAY_ID;
kdgv_AllowBalanceData.Rows[index].Cells[4].Value = item.TRAY_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[5].Value = item.PALLET_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[6].Value = item.TRAY_DTL_ID;
kdgv_AllowBalanceData.Rows[index].Cells[7].Value = item.MATERIEL_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[8].Value = item.MATERIEL_NAME;
kdgv_AllowBalanceData.Rows[index].Cells[9].Value = item.MATERIEL_BARCODE;
kdgv_AllowBalanceData.Rows[index].Cells[10].Value = item.MATERIEL_SPEC;
kdgv_AllowBalanceData.Rows[index].Cells[11].Value = item.BATCH_NO;
kdgv_AllowBalanceData.Rows[index].Cells[12].Value = item.QTY;
kdgv_AllowBalanceData.Rows[index].Cells[13].Value = item.UNIT_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[14].Value = item.PACKAGE_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[15].Value = item.PRODUCT_DATE;
kdgv_AllowBalanceData.Rows[index].Cells[16].Value = item.EXP_DATE;
kdgv_AllowBalanceData.Rows[index].DefaultCellStyle.BackColor = Color.LightGreen;
foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
{
string materielCode = dvr.Cells[1].Value.ToString();
string batchNo = dvr.Cells[5].Value.ToString();
decimal invoiceQty = Convert.ToDecimal(dvr.Cells[6].Value);
decimal allowQty = dvr.Cells[9].Value == null ? 0 : Convert.ToDecimal(dvr.Cells[9].Value);
if (item.MATERIEL_CODE == materielCode && item.BATCH_NO == batchNo)
{
dvr.Cells[9].Value = allowQty + item.QTY;
string percentage = ((allowQty + item.QTY) / invoiceQty).ToString("0.00%");
dvr.Cells[10].Value = "已分配:【" + percentage + "】";
if ((allowQty + item.QTY) >= invoiceQty)
{
dvr.Cells[9].Style.BackColor = Color.LightGreen;
dvr.Cells[10].Style.BackColor = Color.LightGreen;
}
break;
}
}
kdgv_AllowBalanceData.ClearSelection();
}
}
else
{
if ((result.Data != null && result.Data.BalanceDtlResultLst.Count > 0))
{
AutoAllocateBalanceMsg = result.Data;
foreach (WmsStkBalanceDtlResult item in result.Data.BalanceDtlResultLst)
{
int index = kdgv_AllowBalanceData.Rows.Add();
kdgv_AllowBalanceData.Rows[index].Cells[0].Value = true;
kdgv_AllowBalanceData.Rows[index].Cells[1].Value = index + 1;
kdgv_AllowBalanceData.Rows[index].Cells[2].Value = item.BALANCE_ID;
kdgv_AllowBalanceData.Rows[index].Cells[3].Value = item.TRAY_ID;
kdgv_AllowBalanceData.Rows[index].Cells[4].Value = item.TRAY_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[5].Value = item.PALLET_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[6].Value = item.TRAY_DTL_ID;
kdgv_AllowBalanceData.Rows[index].Cells[7].Value = item.MATERIEL_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[8].Value = item.MATERIEL_NAME;
kdgv_AllowBalanceData.Rows[index].Cells[9].Value = item.MATERIEL_BARCODE;
kdgv_AllowBalanceData.Rows[index].Cells[10].Value = item.MATERIEL_SPEC;
kdgv_AllowBalanceData.Rows[index].Cells[11].Value = item.BATCH_NO;
kdgv_AllowBalanceData.Rows[index].Cells[12].Value = item.QTY;
kdgv_AllowBalanceData.Rows[index].Cells[13].Value = item.UNIT_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[14].Value = item.PACKAGE_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[15].Value = item.PRODUCT_DATE;
kdgv_AllowBalanceData.Rows[index].Cells[16].Value = item.EXP_DATE;
kdgv_AllowBalanceData.Rows[index].DefaultCellStyle.BackColor = Color.LightGreen;
foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
{
string materielCode = dvr.Cells[1].Value.ToString();
string batchNo = dvr.Cells[5].Value.ToString();
decimal invoiceQty = Convert.ToDecimal(dvr.Cells[6].Value);
decimal allowQty = dvr.Cells[9].Value == null ? 0 : Convert.ToDecimal(dvr.Cells[9].Value);
if (item.MATERIEL_CODE == materielCode && item.BATCH_NO == batchNo)
{
dvr.Cells[9].Value = allowQty + item.QTY;
string percentage = ((allowQty + item.QTY) / invoiceQty).ToString("0.00%");
dvr.Cells[10].Value = "已分配:【" + percentage + "】";
if ((allowQty + item.QTY) >= invoiceQty)
{
dvr.Cells[9].Style.BackColor = Color.LightGreen;
dvr.Cells[10].Style.BackColor = Color.LightGreen;
}
break;
}
}
kdgv_AllowBalanceData.ClearSelection();
}
}
KryptonMessageBox.Show(result.Message);
}
}
else
{
AutoAllocateBalanceMsg = null;
kdgv_AllowBalanceData.Columns[0].ReadOnly = false;
kdgv_AllowBalanceData.Rows.Clear();
foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
{
dvr.Cells[9].Value = null;
dvr.Cells[10].Value = null;
dvr.Cells[9].Style.BackColor = dvr.Cells[1].Style.BackColor;
dvr.Cells[10].Style.BackColor = dvr.Cells[1].Style.BackColor;
}
}
}
///
/// 手动分配模式下,查询库存信息。
///
///
///
private void kbtn_Search_Click(object sender, EventArgs e)
{
if (kcmb_AllocateType.Text != "自动分配")
{
kdgv_AllowBalanceData.Columns[0].ReadOnly = false;
kdgv_AllowBalanceData.Rows.Clear();
var result = WmsInvoiceService.wmsOutInvoiceService.InvoiceAllovationBalanceManual(new WmsStkBalanceDtlSearchMd {
MaterielMsg = ktb_MaterielMsg.Text,
BatchNoMsg = ktb_BatchNoMsg.Text,
RegionMsg = ((ListItem)kcmb_RegionMsg.SelectedItem).Value,
BinMsg = ktb_BinMsg.Text,
PalletMsg = ktb_PalletNoMsg.Text,
InvoiceMd = InvoiceDataNotEdit,
});
if (result.Status == OperateStatus.Success)
{
foreach (WmsStkBalanceDtlResult item in result.Data)
{
int index = kdgv_AllowBalanceData.Rows.Add();
kdgv_AllowBalanceData.Rows[index].Cells[0].Value = false;
kdgv_AllowBalanceData.Rows[index].Cells[1].Value = index + 1;
kdgv_AllowBalanceData.Rows[index].Cells[2].Value = item.BALANCE_ID;
kdgv_AllowBalanceData.Rows[index].Cells[3].Value = item.TRAY_ID;
kdgv_AllowBalanceData.Rows[index].Cells[4].Value = item.TRAY_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[5].Value = item.PALLET_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[6].Value = item.TRAY_DTL_ID;
kdgv_AllowBalanceData.Rows[index].Cells[7].Value = item.MATERIEL_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[8].Value = item.MATERIEL_NAME;
kdgv_AllowBalanceData.Rows[index].Cells[9].Value = item.MATERIEL_BARCODE;
kdgv_AllowBalanceData.Rows[index].Cells[10].Value = item.MATERIEL_SPEC;
kdgv_AllowBalanceData.Rows[index].Cells[11].Value = item.BATCH_NO;
kdgv_AllowBalanceData.Rows[index].Cells[12].Value = item.QTY;
kdgv_AllowBalanceData.Rows[index].Cells[13].Value = item.UNIT_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[14].Value = item.PACKAGE_CODE;
kdgv_AllowBalanceData.Rows[index].Cells[15].Value = item.PRODUCT_DATE;
kdgv_AllowBalanceData.Rows[index].Cells[16].Value = item.EXP_DATE;
kdgv_AllowBalanceData.ClearSelection();
}
}
}
}
///
/// 重置查询条件
///
///
///
private void kbtn_Reset_Click(object sender, EventArgs e)
{
ktb_MaterielMsg.Text = "";
ktb_BatchNoMsg.Text = "";
ktb_BinMsg.Text = "";
ktb_PalletNoMsg.Text = "";
kcmb_RegionMsg.SelectedIndex = 0;
}
///
/// 提交发货审核结果数据。
///
///
///
private void kbtn_Confirm_Click(object sender, EventArgs e)
{
int index = 0;
foreach (DataGridViewRow item in kdgv_InvoiceDtlData.Rows)
{
index++;
decimal notInvoiceDtlQty = Convert.ToInt32(item.Cells[6].Value);
decimal allocateQty = Convert.ToInt32(item.Cells[9].Value);
if (allocateQty < notInvoiceDtlQty)
{
KryptonMessageBox.Show($"发货单明细第:【{index}】行分配数量小于未发货数量。目前版本不支持部分匹配出库,后续会添加该功能!");
return;
}
}
WmsOutInvoiceCheckResult checkResult = new WmsOutInvoiceCheckResult();
checkResult.IsAutoAllocateBalance = kcmb_AllocateType.Text == "自动分配";
checkResult.InvoiceMdResult = InvoiceDataNotEdit;
checkResult.InvoiceMdResult.UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
checkResult.InvoiceMdResult.UPDATE_NAME = AppConfig.UserLoginResult.UserInfo.UserName;
List TrayIdLst = new List();
foreach (DataGridViewRow item in kdgv_AllowBalanceData.Rows)
{
bool isCheck = Convert.ToBoolean(item.Cells[0].Value);
string TrayId = item.Cells[3].Value.ToString();
if (isCheck)
{
if (TrayIdLst.FirstOrDefault(x => x.TRAY_ID == Convert.ToInt32(TrayId)) == null)
{
TrayIdLst.Add(new WmsStkTrayDtlRowsCountResultExt1 { TRAY_ID = Convert.ToInt32(TrayId) });
}
}
}
if (kcmb_AllocateType.Text == "自动分配")
{
checkResult.TrayIdLst = AutoAllocateBalanceMsg.PalletTaskResultTask;
}
else
{
checkResult.TrayIdLst = TrayIdLst;
}
var result = WmsInvoiceService.wmsOutInvoiceService.SubmitInvoiceCheckResult(checkResult);
if (result.Status == OperateStatus.Success)
{
KryptonMessageBox.Show(result.Message);
frmWmsOutInvoice.RefreshFrmHost();
this.Close();
}
else
{
KryptonMessageBox.Show(result.Message);
}
}
///
/// 取消按钮事件
/// 关闭发货审核窗体
///
///
///
private void kbtn_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
#region DataGridView相关事件
private void kdgv_AllowBalanceData_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)kdgv_AllowBalanceData.CurrentCell;
if (Convert.ToBoolean(checkCell.EditedFormattedValue))
{
kdgv_AllowBalanceData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGreen;
string materielCodeOfBalance = kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[7].Value.ToString();
string bacthNoOfBalance = kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[11].Value.ToString();
decimal qtyOfBalance = Convert.ToDecimal(kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[12].Value);
foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
{
string materielCode = dvr.Cells[1].Value.ToString();
string batchNo = dvr.Cells[5].Value.ToString();
decimal invoiceQty = Convert.ToDecimal(dvr.Cells[6].Value);
decimal allowQty = dvr.Cells[9].Value == null ? 0 : Convert.ToDecimal(dvr.Cells[9].Value);
if (materielCodeOfBalance == materielCode && bacthNoOfBalance == batchNo)
{
dvr.Cells[9].Value = allowQty + qtyOfBalance;
string percentage = ((allowQty + qtyOfBalance) / invoiceQty).ToString("0.00%");
dvr.Cells[10].Value = "已分配:【" + percentage + "】";
if ((allowQty + qtyOfBalance) >= invoiceQty)
{
dvr.Cells[9].Style.BackColor = Color.LightGreen;
dvr.Cells[10].Style.BackColor = Color.LightGreen;
}
else
{
dvr.Cells[9].Style.BackColor = Color.LightYellow;
dvr.Cells[10].Style.BackColor = Color.LightYellow;
}
break;
}
}
}
else
{
kdgv_AllowBalanceData.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Transparent;
string materielCodeOfBalance = kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[7].Value.ToString();
string bacthNoOfBalance = kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[11].Value.ToString();
decimal qtyOfBalance = Convert.ToDecimal(kdgv_AllowBalanceData.Rows[e.RowIndex].Cells[12].Value);
foreach (DataGridViewRow dvr in kdgv_InvoiceDtlData.Rows)
{
string materielCode = dvr.Cells[1].Value.ToString();
string batchNo = dvr.Cells[5].Value.ToString();
decimal invoiceQty = Convert.ToDecimal(dvr.Cells[6].Value);
decimal allowQty = dvr.Cells[9].Value == null ? 0 : Convert.ToDecimal(dvr.Cells[9].Value);
if (materielCodeOfBalance == materielCode && bacthNoOfBalance == batchNo)
{
if ((allowQty - qtyOfBalance) <= 0)
{
dvr.Cells[9].Value = null;
dvr.Cells[10].Value = null;
dvr.Cells[9].Style.BackColor = Color.Transparent;
dvr.Cells[10].Style.BackColor = Color.Transparent;
break;
}
else
{
dvr.Cells[9].Value = allowQty - qtyOfBalance;
string percentage = ((allowQty - qtyOfBalance) / invoiceQty).ToString("0.00%");
dvr.Cells[10].Value = "已分配:【" + percentage + "】";
if ((allowQty - qtyOfBalance) >= invoiceQty)
{
dvr.Cells[9].Style.BackColor = Color.LightGreen;
dvr.Cells[10].Style.BackColor = Color.LightGreen;
}
else
{
dvr.Cells[9].Style.BackColor = Color.LightYellow;
dvr.Cells[10].Style.BackColor = Color.LightYellow;
}
break;
}
}
}
}
}
}
#endregion
#region 鼠标右键单击事件
#endregion
}
}