using ComponentFactory.Krypton.Toolkit;
using NXWMS.Client.FrmCustom;
using NXWMS.Client.Model.AppModels.Condition.Common;
using NXWMS.Client.Model.AppModels.Result.Common;
using NXWMS.Client.Model.AppModels.Result.Inspection;
using NXWMS.Client.Model.AppModels.Result.Instock;
using NXWMS.Client.Model.CoreModels;
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.Text;
using System.Web.UI.WebControls;
using System.Windows.Forms;
namespace NXWMS.Forms.Inspection.frmInspectionChild
{
///
/// 质检审核窗体类
///
public partial class frmChildInspectionCheck : KryptonForm
{
///
/// 窗体构造函数
///
public frmChildInspectionCheck()
{
InitializeComponent();
}
#region 全局变量
///
/// 质检单主键ID
///
public string InspectionId { get; set; }
///
/// 数据库中的质检单所有数据(包括主、明细表)。
/// 未进行编辑过。
///
private WmsQaInspectionResult InspectionDataNotEdit = new WmsQaInspectionResult();
#endregion
#region 初始化数据
///
/// 窗体加载函数
///
///
///
private void frmChildInspectionCheck_Load(object sender, EventArgs e)
{
InitComboBoxItemData();
InitDataGridViewColumn();
kdtp_InspectionTime.Checked = false;
LoadWmsQaInspectionDtlData();
}
///
/// 初始化下拉列表数据
///
private void InitComboBoxItemData()
{
/*
ToDo:后续把下拉列表转为 后台获取数据,目前是写死的。
*/
List results = new List();
#region 质检单类型
results = BasDictionaryUtil.basDictionaryResultLst.FindAll(x => x.DICTIONARY_CODE == "InspectionTypeDesc");
if (results.Count > 0)
{
kcmb_InspectionType.Items.Clear();
foreach (var item in results)
{
kcmb_InspectionType.Items.Add(new ListItem
{
Value = item.DICTIONARY_ITEM_CODE,
Text = item.DICTIONARY_ITEM_NAME,
});
}
kcmb_InspectionType.SelectedIndex = 0;
}
else
{
KryptonMessageBox.Show("未找到质检单类型的字典项数据!");
}
#endregion
#region 质检方式
results = BasDictionaryUtil.basDictionaryResultLst.FindAll(x => x.DICTIONARY_CODE == "InspectionWayDesc");
if (results.Count > 0)
{
kcmb_InspectionWay.Items.Clear();
foreach (var item in results)
{
kcmb_InspectionWay.Items.Add(new ListItem
{
Value = item.DICTIONARY_ITEM_CODE,
Text = item.DICTIONARY_ITEM_NAME,
});
}
kcmb_InspectionWay.SelectedIndex = 0;
}
else
{
KryptonMessageBox.Show("未找到质检方式的字典项数据!");
}
#endregion
}
///
/// 初始化DataGridView列信息
///
private void InitDataGridViewColumn()
{
DataGridViewColumn column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "序号";
column1.Width = 50;
column1.ReadOnly = true;
//column1.
kdgv_InspectionDtlData.Columns.Add(column1);
column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "到货通知单号";
column1.Width = 150;
column1.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column1);
column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "物料编码";
column1.Width = 150;
column1.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column1);
column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "物料名称";
column1.Width = 200;
column1.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column1);
column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "物料条码";
column1.Width = 150;
column1.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column1);
DataGridViewComboBoxColumn cmb_Unit = new DataGridViewComboBoxColumn();
cmb_Unit.HeaderText = "质检结果";
cmb_Unit.Width = 90;
//目前写死下拉列表的数据项,后续改为后台获取
cmb_Unit.Items.AddRange(new ListItem[]
{
new ListItem{ Value = "Wait",Text = "待检"},
new ListItem{ Value = "OK",Text = "合格"},
new ListItem{ Value = "NG",Text = "不合格"}
});
cmb_Unit.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;
kdgv_InspectionDtlData.Columns.Add(cmb_Unit);
column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "批次号";
column1.Width = 120;
column1.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column1);
column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "单位";
column1.Width = 70;
column1.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column1);
column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "供应商";
column1.Width = 120;
column1.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column1);
column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "包装";
column1.Width = 80;
column1.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column1);
KryptonDataGridViewDateTimePickerColumn column_ProductTime = new KryptonDataGridViewDateTimePickerColumn();
column_ProductTime.HeaderText = "生产日期";
column_ProductTime.Width = 160;
column_ProductTime.Format = DateTimePickerFormat.Custom;
column_ProductTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
column_ProductTime.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column_ProductTime);
KryptonDataGridViewDateTimePickerColumn column_ExpTime = new KryptonDataGridViewDateTimePickerColumn();
column_ExpTime.HeaderText = "失效日期";
column_ExpTime.Width = 160;
column_ExpTime.Format = DateTimePickerFormat.Custom;
column_ExpTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
column_ExpTime.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column_ExpTime);
column1 = new KryptonDataGridViewTextBoxColumn();
column1.HeaderText = "到货通知单明细ID";
column1.Width = 30;
column1.Visible = false;
column1.ReadOnly = true;
kdgv_InspectionDtlData.Columns.Add(column1);
}
///
/// 调用服务端接口,请求质检单明细表数据
///
///
private string LoadWmsQaInspectionDtlData()
{
var result = WmsInspectionService.wmsQaInspectionService.GetWmsQaInspectionDtlListForId(new WmsQaInspectionResult { INSPECTION_ID = Convert.ToInt32(this.InspectionId) });
if (result.Status == OperateStatus.Success)
{
ktb_InspectionNo.Text = result.Data.INSPECTION_NO;
ktb_InspectionNo.Enabled = false;
ktb_InspectionUser.Text = result.Data.INSPECTION_USER;
ktb_InspectionUser.Enabled = false;
kcmb_InspectionType.Text = result.Data.INSPECTION_TYPE_NAME;
kcmb_InspectionType.Enabled = false;
kcmb_InspectionWay.Text = result.Data.INSPECTION_WAY_NAME;
kcmb_InspectionWay.Enabled = false;
ktb_Describe.Text = result.Data.DESCRIBE;
if (result.Data.INSPECTION_TIME != new DateTime())
{
kdtp_InspectionTime.Value = result.Data.INSPECTION_TIME;
}
InspectionDataNotEdit = result.Data;
kdgv_InspectionDtlData.Rows.Clear();
foreach (WmsQaInspectionDtlResult item in result.Data.WmsQaInspectionDtlList)
{
int index = kdgv_InspectionDtlData.Rows.Add();
kdgv_InspectionDtlData.Rows[index].Cells[0].Value = index + 1;
kdgv_InspectionDtlData.Rows[index].Cells[1].Value = item.BILL_NO;
kdgv_InspectionDtlData.Rows[index].Cells[2].Value = item.MATERIEL_CODE;
kdgv_InspectionDtlData.Rows[index].Cells[3].Value = item.MATERIEL_NAME;
kdgv_InspectionDtlData.Rows[index].Cells[4].Value = item.MATERIEL_BARCODE;
ListItem inspectionResultLstItm = GetComboBoxItem((DataGridViewComboBoxCell)kdgv_InspectionDtlData.Rows[index].Cells[5], item.INSPECTION_RESULT);
kdgv_InspectionDtlData.Rows[index].Cells[5].Value = inspectionResultLstItm;
kdgv_InspectionDtlData.Rows[index].Cells[6].Value = item.BATCH_NO;
kdgv_InspectionDtlData.Rows[index].Cells[7].Value = item.UNIT_CODE;
kdgv_InspectionDtlData.Rows[index].Cells[8].Value = item.SUPPLIER_NAME;
kdgv_InspectionDtlData.Rows[index].Cells[9].Value = item.PACKAGE_CODE;
kdgv_InspectionDtlData.Rows[index].Cells[10].Value = item.PRODUCT_DATE;
kdgv_InspectionDtlData.Rows[index].Cells[11].Value = item.EXP_DATE;
kdgv_InspectionDtlData.Rows[index].Cells[12].Value = item.BILL_DTL_ID;
}
return string.Empty;
}
else
{
return result.Message;
}
}
#endregion
#region 按钮事件
///
/// 确认按钮事件
/// 提交编辑完成的质检单数据
///
///
///
private void btnConfirm_Click(object sender, EventArgs e)
{
WmsQaInspectionResult mdInspection = new WmsQaInspectionResult();
mdInspection.INSPECTION_ID = InspectionDataNotEdit.INSPECTION_ID;
mdInspection.INSPECTION_NO = InspectionDataNotEdit.INSPECTION_NO;
mdInspection.INSPECTION_TYPE = Convert.ToInt32(((ListItem)kcmb_InspectionType.SelectedItem).Value);
mdInspection.INSPECTION_USER = ktb_InspectionUser.Text;
mdInspection.INSPECTION_WAY = Convert.ToInt32(((ListItem)kcmb_InspectionType.SelectedItem).Value);
if (kdtp_InspectionTime.Checked)
{
mdInspection.INSPECTION_TIME = kdtp_InspectionTime.Value;
}
else
{
mdInspection.INSPECTION_TIME = new DateTime();
}
mdInspection.INSPECTION_STATUS = (int)InspectionStatus.结果确认完成;
mdInspection.DESCRIBE = ktb_Describe.Text.Trim();
mdInspection.CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
mdInspection.UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId;
List mdInspectionDtlList = new List();
if (kdgv_InspectionDtlData.Rows.Count > 0 && !kdgv_InspectionDtlData.Rows[0].IsNewRow)
{
foreach (DataGridViewRow dvr in kdgv_InspectionDtlData.Rows)
{
if (!dvr.IsNewRow)
{
#region 校验每一行数据的完整性
string RowCheckMsg = string.Empty;
if (!CheckDataGridViewRowFormat(dvr, ref RowCheckMsg))
{
KryptonMessageBox.Show(RowCheckMsg);
return;
}
#endregion
string receiptNo = dvr.Cells[1].Value.ToString();
string materielCode = dvr.Cells[2].Value.ToString();
string materielName = dvr.Cells[3].Value.ToString();
string materielBarcode = dvr.Cells[4].Value == null ? null : dvr.Cells[4].Value.ToString();
string inspectionResult = GetComboBoxItem((DataGridViewComboBoxCell)dvr.Cells[5]).Value;
string batchNo = dvr.Cells[6].Value == null ? null : dvr.Cells[6].Value.ToString();
string unitCode = dvr.Cells[7].Value == null ? null : dvr.Cells[7].Value.ToString();
string supplierCode = dvr.Cells[8].Value == null ? null : dvr.Cells[8].Value.ToString();
string packageCode = dvr.Cells[9].Value == null ? null : dvr.Cells[9].Value.ToString();
DateTime productTime = Convert.ToDateTime(dvr.Cells[10].Value);
DateTime expTime = Convert.ToDateTime(dvr.Cells[11].Value);
int billDtlId = dvr.Cells[12].Value == null ? 0 : Convert.ToInt32(dvr.Cells[12].Value);
WmsQaInspectionDtlResult mdQaResult = InspectionDataNotEdit.WmsQaInspectionDtlList.Find(y => y.BILL_DTL_ID == billDtlId);
mdInspectionDtlList.Add(new WmsQaInspectionDtlResult
{
INSPECTION_DTL_ID = mdQaResult.INSPECTION_DTL_ID,
INSPECTION_ID = mdQaResult.INSPECTION_ID,
BILL_NO = mdQaResult.BILL_NO,
BILL_DTL_ID = billDtlId,
MATERIEL_CODE = materielCode,
MATERIEL_NAME = materielName,
MATERIEL_BARCODE = materielBarcode,
BATCH_NO = batchNo,
UNIT_CODE = unitCode,
SUPPLIER_CODE = mdQaResult.SUPPLIER_CODE,
SUPPLIER_NAME = mdQaResult.SUPPLIER_NAME,
PACKAGE_CODE = packageCode,
PRODUCT_DATE = productTime,
EXP_DATE = expTime,
INSPECTION_RESULT = inspectionResult,
ITEM_STATUS = mdQaResult.ITEM_STATUS,
INSPECTION_DTL_STATUS = (int)InspectionStatus.结果确认完成,
CREATE_BY = AppConfig.UserLoginResult.UserInfo.UserId,
UPDATE_BY = AppConfig.UserLoginResult.UserInfo.UserId,
DESCRIBE = null
});
}
}
mdInspection.WmsQaInspectionDtlList = mdInspectionDtlList;
var result = WmsInspectionService.wmsQaInspectionService.QaInspectionExamine(mdInspection);
if (result.Status == OperateStatus.Success)
{
KryptonMessageBox.Show(result.Message);
frmWmsQaInspection.RefreshFrmHost();
this.Close();
}
else
{
KryptonMessageBox.Show(result.Message);
}
}
else
{
KryptonMessageBox.Show("请添加数据行!");
}
}
///
/// 校验DataGridView输入行数据的正确性
///
/// DataGridView输入行
/// 校验结果信息
///
private bool CheckDataGridViewRowFormat(DataGridViewRow dvr, ref string OutMssg)
{
if (dvr.Cells[1].Value == null)
{
OutMssg = $"第【{dvr.Index + 1}】行未输入物料编码!";
return false;
}
if (dvr.Cells[2].Value == null)
{
OutMssg = $"第【{dvr.Index + 1}】行未输入物料编码!";
return false;
}
if (dvr.Cells[3].Value == null)
{
OutMssg = $"第【{dvr.Index + 1}】行未输入物料名称!";
return false;
}
if (dvr.Cells[5].Value == null)
{
OutMssg = $"第【{dvr.Index + 1}】行未选择质检结果!";
return false;
}
if (dvr.Cells[7].Value == null)
{
OutMssg = $"第【{dvr.Index + 1}】行未选择单位信息!";
return false;
}
if (dvr.Cells[8].Value == null)
{
OutMssg = $"第【{dvr.Index + 1}】行未选择供应商信息!";
return false;
}
if (dvr.Cells[10].Value == null)
{
OutMssg = $"第【{dvr.Index + 1}】行未输入生产日期!";
return false;
}
if (dvr.Cells[11].Value == null)
{
OutMssg = $"第【{dvr.Index + 1}】行未输入失效日期!";
return false;
}
if (DateTime.Compare(Convert.ToDateTime(dvr.Cells[10].Value), Convert.ToDateTime(dvr.Cells[11].Value)) >= 0)
{
OutMssg = $"第【{dvr.Index + 1}】行未输入的生产日期大于失效日期,不符合实际情况,请重新输入!";
return false;
}
OutMssg = "校验成功!";
return true;
}
///
/// 取消按钮事件
/// 退出编辑页面
///
///
///
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private ListItem GetComboBoxItem(DataGridViewComboBoxCell dataGridViewComboBoxCell)
{
foreach (var item in dataGridViewComboBoxCell.Items)
{
if (((ListItem)item).Text == dataGridViewComboBoxCell.Value.ToString())
{
return (ListItem)item;
}
}
return new ListItem();
}
private ListItem GetComboBoxItem(DataGridViewComboBoxCell dataGridViewComboBoxCell, string value)
{
foreach (var item in dataGridViewComboBoxCell.Items)
{
if (((ListItem)item).Value == value)
{
return (ListItem)item;
}
}
return new ListItem();
}
#endregion
#region DataGridView相关事件
///
/// 针对ComboBox下拉列表的DataGridView数据列单元格。
/// 由于DataGridView的ComboBox列的Item至使用的是KeyValue形式的ListItem,
/// 所以单元格结束编辑的时候。需要给单元格设定一个类型为ListItem的值。
///
///
///
private void kdgv_InspectionDtlData_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int rowIndex = e.RowIndex;
int columnIndex = e.ColumnIndex;
if (kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex] is DataGridViewComboBoxCell)
{
ListItem tstlst = GetComboBoxItem((DataGridViewComboBoxCell)kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex]);
kdgv_InspectionDtlData.Rows[rowIndex].Cells[columnIndex].Value = tstlst;
}
}
private void kdgv_InspectionDtlData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
int index = kdgv_InspectionDtlData.Rows.Count;
kdgv_InspectionDtlData.Rows[index - 1].Cells[0].Value = index;
}
#endregion
#region 鼠标右键单击事件
///
/// 重新加载正在编辑的质检单明细数据
///
///
///
private void 重新加载ToolStripMenuItem_Click(object sender, EventArgs e)
{
var loadfrm = new frmLoading();
loadfrm.Show();
var message = loadfrm.EventCalExec(LoadWmsQaInspectionDtlData);
if (!string.IsNullOrWhiteSpace(message))
{
KryptonMessageBox.Show($"查询失败!\r\n{message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
#endregion
}
}