123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- 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
- {
- /// <summary>
- /// 发货审核
- /// </summary>
- public partial class frmChildInvoiceCheck : KryptonForm
- {
- /// <summary>
- /// 窗体构造函数
- /// </summary>
- public frmChildInvoiceCheck()
- {
- InitializeComponent();
- }
- #region 全局变量
- /// <summary>
- /// 发货单主键ID
- /// </summary>
- public string InvoiceId { get; set; }
- /// <summary>
- /// 数据库中的发货单所有数据(包括主、明细表)。
- /// 未进行编辑过。
- /// </summary>
- private WmsOutInvoiceResult InvoiceDataNotEdit = new WmsOutInvoiceResult();
- private WmsBalanceAllocateStatus AutoAllocateBalanceMsg = new WmsBalanceAllocateStatus();
- #endregion
- #region 初始化数据
- /// <summary>
- /// 窗体加载函数
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void frmChildInvoiceCheck_Load(object sender, EventArgs e)
- {
- InitComboBoxItemData();
- LoadWmsOutInvoiceDtlData();
- kcmb_AllocateType.SelectedIndex = 1;
- }
- /// <summary>
- /// 初始化下拉列表数据
- /// </summary>
- private void InitComboBoxItemData()
- {
- /*
- ToDo:后续把下拉列表转为 后台获取数据,目前是写死的。
- */
- List<BasDictionaryResult> results = new List<BasDictionaryResult>();
- #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
- }
- /// <summary>
- /// 调用服务端接口,请求发货单明细表数据
- /// </summary>
- /// <returns></returns>
- 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;
- }
- }
- }
- /// <summary>
- /// 手动分配模式下,查询库存信息。
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- }
- }
- /// <summary>
- /// 重置查询条件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
- /// <summary>
- /// 提交发货审核结果数据。
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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<WmsStkTrayDtlRowsCountResultExt1> TrayIdLst = new List<WmsStkTrayDtlRowsCountResultExt1>();
- 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);
- }
- }
- /// <summary>
- /// 取消按钮事件
- /// 关闭发货审核窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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
- }
- }
|