using ComponentFactory.Krypton.Toolkit; using NXWMS.Client.Code.Converter; using NXWMS.Client.Code.Extends; using NXWMS.Client.Model.AppModels.Condition; using NXWMS.Client.Model.AppModels.Condition.Balance; using NXWMS.Client.Model.AppModels.Condition.Base; using NXWMS.Client.Model.AppModels.Condition.SysSettings; using NXWMS.Client.Model.AppModels.Result; using NXWMS.Client.Model.AppModels.Result.Balance; using NXWMS.Client.Model.AppModels.Result.Base; using NXWMS.Client.Model.AppModels.Result.SysSettings; using NXWMS.Client.Model.CoreModels; using NXWMS.Client.String.Enums; using NXWMS.Commons; using NXWMS.Services; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace NXWMS.Forms.Balance.frmBalanceChild { public partial class frmOperateBalanceInventory : KryptonForm { /// /// 客户端字段排序列表 /// // private List _clientFieldOrderList; /// /// 界面功能类型 /// public enum EnumFunctionType { Add, Edit, InventoryFirst, InventorySecond, ResultConfirm, } /// /// 界面功能类型 /// public EnumFunctionType _FunctionType; private BindingList source = new BindingList(); /// /// 传入单号 /// public string _InventoryNo; /// /// 盘点主 /// public InventoryMainSearchResult _MainInfo; /// /// 盘点子 /// // public List _DetailList; public frmOperateBalanceInventory() { InitializeComponent(); this.dataGridView.AutoGenerateColumns = false; } private void InitControl() { CheckForIllegalCrossThreadCalls = false; this.SetFormSizeLocation(); //当前新增id列表 frmBalanceDetailSearch._alreadyAddIdList = new List(); dataGridView.DataSource = new List(); dataGridView.CellClick += new DataGridViewCellEventHandler(dataGridView_CellClick); //dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), false, true); var fieldList = new List(); cmbType.DataSource = fieldList.GetFieldValueIdList(); cmbType.DisplayMember = "Name"; cmbType.ValueMember = "Id"; cmbType.SelectedValue = ((int)InventoryType.WMS).ToString(); fieldList = new List(); cmbInventoryMode.DataSource = fieldList.GetFieldValueIdList(); cmbInventoryMode.DisplayMember = "Name"; cmbInventoryMode.ValueMember = "Id"; cmbInventoryMode.SelectedValue = ((int)InventoryMode.Select).ToString(); this.dataGridView.DataSource = source; txtInventoryNo.Text = _InventoryNo; //不同结果类型 switch (_FunctionType) { case EnumFunctionType.Add: this.Text = "盘点单-新增"; txtInventoryNo.Enabled = true; this.ColumnActualInventoryQty.Visible = false; this.ColumnInventoryResultQty.Visible = false; this.ColumnDifferenceQty.Visible = false; break; case EnumFunctionType.Edit: this.Text = "盘点单-编辑"; txtInventoryNo.Enabled = false; this.ColumnActualInventoryQty.Visible = false; this.ColumnInventoryResultQty.Visible = false; this.ColumnDifferenceQty.Visible = false; break; case EnumFunctionType.InventoryFirst: this.Text = "盘点单-盘点"; txtInventoryNo.Enabled = false; this.ColumnActualInventoryQty.Visible = true; this.ColumnInventoryResultQty.Visible = true; break; case EnumFunctionType.InventorySecond: this.Text = "盘点单-差异盘点"; txtInventoryNo.Enabled = false; this.ColumnActualInventoryQty.Visible = true; this.ColumnInventoryResultQty.Visible = true; break; case EnumFunctionType.ResultConfirm: this.Text = "盘点单-结果确认"; this.ColumnInventoryResultQty.InheritedStyle.BackColor = Color.Red; this.ColumnInventoryResultQty.InheritedStyle.ForeColor = Color.Blue; this.ColumnActualInventoryQty.Visible = true; this.ColumnInventoryResultQty.Visible = true; txtInventoryNo.Enabled = false; btnAdd.Visible = false; break; } } private void InitData() { } private void btnAdd_Click(object sender, EventArgs e) { var detailForm = new frmBalanceDetailSearch(); detailForm._execFormType = ExecFormType.Select; detailForm.Text = "选择库存记录"; if (detailForm.ShowDialog() == DialogResult.Yes) { var ids = detailForm._CheckRowIdList; //查询当前库存库位中的详细库存数据 var balanceResult = BalanceServices.balanceSearchService.GetDetailList(new BalanceDetailSearchCondition { BalanceStatus = ((int)BalanceStatus.InStock), Ids = string.Join(",", ids) }); if (balanceResult.Status == OperateStatus.Success) { var addRows = balanceResult.Data.RowData.ToList(); foreach (var item in addRows) { source.Add(new InventoryDetailSearchResult { BalanceId = item.BALANCE_ID, BatchNo = item.BatchNo, BinName = item.BIN_NAME, BinCode = item.BIN_CODE, Qty = item.QTY, MaterielCode = item.MaterielCode, MaterielTypeCode = item.MaterielTypeCode, MaterielName = item.MaterielName, UnitName = item.UnitName, TrayCode = item.TrayCode, PalletCode = item.PalletCode, }); this.dataGridView.Refresh(); } //var currentDataTable = ((List)dataGridView.DataSource); //var result = currentDataTable.Union(addRows); //dataGridView.DataSource = addRows.ToList(); //dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), true, true); } } } /// /// 选择行索引列表 /// private List _CheckRowIndexList = new List(); private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex == 0) { if (this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null) { if (!_CheckRowIndexList.Where(s => s == e.RowIndex).Any()) { _CheckRowIndexList.Add(e.RowIndex); } this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1; } else if (dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() == "1") { if (_CheckRowIndexList.Where(s => s == e.RowIndex).Any()) { _CheckRowIndexList.Remove(e.RowIndex); } this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 0; } else { if (!_CheckRowIndexList.Where(s => s == e.RowIndex).Any()) { _CheckRowIndexList.Add(e.RowIndex); } this.dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = 1; } } } private void btnConfirm_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtInventoryNo.Text)) { KryptonMessageBox.Show($"请输入盘库单号!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrWhiteSpace(cmbType.Text)) { KryptonMessageBox.Show($"请选择盘库单据类型!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrWhiteSpace(cmbInventoryMode.Text)) { KryptonMessageBox.Show($"请选择盘库方式!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (dataGridView.Rows.Count == 0) { KryptonMessageBox.Show($"请添加至少一条盘点明细记录!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var itemList = new List(); foreach (var item in this.source) { itemList.Add(new InventoryAddDetailCondition { BalanceId = _FunctionType == EnumFunctionType.Add ? item.BalanceId : default(int?), BinCode = item.BinCode, MaterielBarCode = item.MaterielBarcode, MaterielCode = item.MaterielCode, InventoryDTLId = _FunctionType == EnumFunctionType.Add ? default(int?) : item.InventoryDtlId, InventoryDTLStatus = _FunctionType == EnumFunctionType.Add ? default(int?) : item.InventoryDtlStatus }); } //for (int i = 0; i < dataGridView.Rows.Count; i++) //{ // itemList.Add(new InventoryAddDetailCondition // { // BalanceId = _FunctionType == EnumFunctionType.Add ? // Convert.ToInt32(dataGridView.Rows[i].Cells["ColumBalanceId"].Value.ToString()) : // (int?)null, // BinCode = dataGridView.Rows[i].Cells["ColumColumBinCode"].Value.ToString(), // MaterielBarCode = _FunctionType == EnumFunctionType.Add ? // dataGridView.Rows[i].Cells["ColumMaterielCode"].Value.ToString() : // dataGridView.Rows[i].Cells["ColumMaterielCode"].Value.ToString(), //TODO 条码号暂时用物料号代替,后期要改! // MaterielCode = _FunctionType == EnumFunctionType.Add ? // dataGridView.Rows[i].Cells["ColumMaterielCode"].Value.ToString() : // dataGridView.Rows[i].Cells["ColumMaterielCode"].Value.ToString(), // InventoryDTLId = _FunctionType == EnumFunctionType.Add ? (int?)null : // Convert.ToInt32(dataGridView.Rows[i].Cells["ColumInventoryDtlId"].Value.ToString()), // InventoryDTLStatus = _FunctionType == EnumFunctionType.Add ? (int?)null : // Convert.ToInt32(dataGridView.Rows[i].Cells["ColumInventoryDtlStatus"].Value.ToString()), // }); //} switch (_FunctionType) { case EnumFunctionType.Add: var addEntity = new InventoryOperateCondition { Describe = richDescibe.Text, InventoryBeginDate = dtpBeginTime.GetDateTimeValue(), InventoryEndDate = dtpEndTime.GetDateTimeValue(), InventoryMode = cmbInventoryMode.SelectedValue.GetObjectToInt().Value, InventoryNo = txtInventoryNo.Text, InventoryPercentage = (int)numPercentage.Value, OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, InventoryType = cmbType.SelectedValue.GetObjectToInt().Value, InventoryAddDetailList = itemList, }; var addResult = BalanceServices.balanceOperateService.AddInventory(addEntity); if (addResult.Status == OperateStatus.Success) { KryptonMessageBox.Show($"新增盘点单成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView.ClearSelection(); this.DialogResult = DialogResult.Yes; } else { KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case EnumFunctionType.Edit: var editEntity = new InventoryOperateCondition { Describe = richDescibe.Text, InventoryBeginDate = dtpBeginTime.GetDateTimeValue(), InventoryEndDate = dtpEndTime.GetDateTimeValue(), InventoryMode = cmbInventoryMode.SelectedValue.GetObjectToInt().Value, InventoryNo = txtInventoryNo.Text, InventoryPercentage = (int)numPercentage.Value, OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, InventoryType = cmbType.SelectedValue.GetObjectToInt().Value, InventoryAddDetailList = itemList, InventoryStatus = null, InventoryId = _MainInfo.InventoryId, }; var editResult = BalanceServices.balanceOperateService.EditInventory(editEntity); if (editResult.Status == OperateStatus.Success) { KryptonMessageBox.Show($"编辑盘点单成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView.ClearSelection(); this.DialogResult = DialogResult.Yes; } else { KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case EnumFunctionType.InventoryFirst: var resultConfimEntity1 = new ResultConfirmInventoryCondition { InventoryNo = txtInventoryNo.Text, OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, OperationTime = DateTime.Now, InventoryStatus = InventoryStatusEnum.FirstInventorComplate, ResultConfirmInventoryDetail = this.source.ToList().ConvertAll(m => { return new ResultConfirmInventoryDetail() { InventoryDTLId = m.InventoryDtlId, InventoryResultQTY = m.InventoryResultQty, ActualInventoryQty = m.ActualInventoryQty }; }) }; var info = BalanceServices.balanceOperateService.ConfirmInventory(resultConfimEntity1); ; if (info.Status == OperateStatus.Success) { KryptonMessageBox.Show($"一次盘点保存成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView.ClearSelection(); } else { KryptonMessageBox.Show($"操作失败!\r\n{info.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case EnumFunctionType.InventorySecond: var resultConfimEntity2 = new ResultConfirmInventoryCondition { InventoryNo = txtInventoryNo.Text, OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, InventoryStatus = InventoryStatusEnum.TwoInventorComplate, OperationTime = DateTime.Now, ResultConfirmInventoryDetail = this.source.ToList().ConvertAll(m => { return new ResultConfirmInventoryDetail() { InventoryDTLId = m.InventoryDtlId, InventoryResultQTY = m.InventoryResultQty, ActualInventoryQty = m.ActualInventoryQty }; }) }; var _info = BalanceServices.balanceOperateService.ConfirmInventory(resultConfimEntity2); ; if (_info.Status == OperateStatus.Success) { KryptonMessageBox.Show($"一次盘点保存成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView.ClearSelection(); } else { KryptonMessageBox.Show($"操作失败!\r\n{_info.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case EnumFunctionType.ResultConfirm: var resultConfirmInventoryDetailList = new List(); foreach (var item in this.source) { resultConfirmInventoryDetailList.Add(new ResultConfirmInventoryDetail { InventoryDTLId = item.InventoryDtlId, InventoryResultQTY = item.InventoryResultQty }); } var resultConfimEntity = new ResultConfirmInventoryCondition { InventoryNo = txtInventoryNo.Text, OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, ResultConfirmInventoryDetail = resultConfirmInventoryDetailList, }; var confimResult = BalanceServices.balanceOperateService.ResultConfirmInventory(resultConfimEntity); if (confimResult.Status == OperateStatus.Success) { KryptonMessageBox.Show($"盘点单确认成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); dataGridView.ClearSelection(); this.DialogResult = DialogResult.Yes; Close(); } else { KryptonMessageBox.Show($"操作失败!\r\n{confimResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; } } private void btnCancel_Click(object sender, EventArgs e) { if (KryptonMessageBox.Show($"确认退出新增盘点? \r\n退出后,当前所有操作数据全部清空!", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { this.DialogResult = DialogResult.No; } } private void 删除选中行ToolStripMenuItem_Click(object sender, EventArgs e) { if (KryptonMessageBox.Show($"确认删除选中数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { switch (_FunctionType) { case EnumFunctionType.Add: var addList = (List)dataGridView.DataSource; for (int i = 0; i < addList.Count; i++) { if (dataGridView.Rows[i].Cells[0].Value.ToString() == "1") { addList.RemoveAt(i); i--; } else { continue; } } dataGridView.DataSource = null; dataGridView.DataSource = addList; //dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), true, true); break; case EnumFunctionType.Edit: var editList = (List)dataGridView.DataSource; for (int i = 0; i < editList.Count; i++) { if (dataGridView.Rows[i].Cells[0].Value.ToString() == "1") { editList.RemoveAt(i); i--; } else { continue; } } dataGridView.DataSource = null; dataGridView.DataSource = editList; //dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), true, true); break; } } } private void 全部删除ToolStripMenuItem_Click(object sender, EventArgs e) { if (KryptonMessageBox.Show($"确认删除所有数据?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { switch (_FunctionType) { case EnumFunctionType.Add: var addList = (List)dataGridView.DataSource; for (int i = 0; i < addList.Count; i++) { addList.RemoveAt(i); i--; } dataGridView.DataSource = null; dataGridView.DataSource = addList; //dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), true, true); break; case EnumFunctionType.Edit: var editList = (List)dataGridView.DataSource; for (int i = 0; i < editList.Count; i++) { editList.RemoveAt(i); i--; } dataGridView.DataSource = null; dataGridView.DataSource = editList; //dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), true, true); break; } } } private void dataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (_FunctionType != EnumFunctionType.ResultConfirm) { if (e.Button == MouseButtons.Right) { if (!_CheckRowIndexList.Any()) { KryptonMessageBox.Show($"请选择记录操作!", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information); return; } contextMenuStrip1.Show(MousePosition.X, MousePosition.Y); } } } private void frmOperateBalanceInventory_Load(object sender, EventArgs e) { InitData(); InitControl(); if (_FunctionType != EnumFunctionType.Add) { //获取对应盘点单数据 var mainResult = BalanceServices.balanceSearchService.GetMainInventoryList(new InventoryMainSearchCondition { InventoryNo = _InventoryNo }); if (mainResult.Status == OperateStatus.Success) { _MainInfo = mainResult.Data.RowData.FirstOrDefault(); txtInventoryNo.Text = _MainInfo.InventoryNo; cmbType.SelectedValue = _MainInfo.InventoryType.ToString(); numPercentage.Value = Convert.ToDecimal(_MainInfo.InventoryPercentage); cmbInventoryMode.SelectedValue = _MainInfo.InventoryMode.ToString(); if (_MainInfo.InventoryBeginTime != null) { dtpBeginTime.Checked = true; dtpBeginTime.Value = _MainInfo.InventoryBeginTime.Value; } if (_MainInfo.InventoryEndTime != null) { dtpEndTime.Checked = true; dtpEndTime.Value = _MainInfo.InventoryEndTime.Value; } richDescibe.Text = _MainInfo.Describe; } else { KryptonMessageBox.Show($"操作失败!\r\n{mainResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } //获取对应盘点子数据 var detailResult = BalanceServices.balanceSearchService.GetDetailInventoryList(new InventoryDetailSearchCondition { Id = _MainInfo.InventoryId }); if (detailResult.Status == OperateStatus.Success) { var addRows = detailResult.Data.ToList(); this.source.Clear(); foreach (var item in addRows) { this.source.Add(item); } //dataGridView.BuildDataGridView(CommonUtil.GetFieldOrderDic(_clientFieldOrderList), true, true); } else { KryptonMessageBox.Show($"操作失败!\r\n{detailResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } private void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { var num = Convert.ToDecimal(this.dataGridView.Rows[e.RowIndex].Cells["ColumnDifferenceQty"].Value); if (num < 0) { this.dataGridView.Rows[e.RowIndex].Cells["ColumnDifferenceQty"].Style.ForeColor = Color.Red; } else if (num == 0) { this.dataGridView.Rows[e.RowIndex].Cells["ColumnDifferenceQty"].Style.ForeColor = Color.Empty; } else { this.dataGridView.Rows[e.RowIndex].Cells["ColumnDifferenceQty"].Style.ForeColor = Color.Green; } } private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { this.dataGridView.Refresh(); } } }