/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0504.cs
* 2.功能描述:配置QC项目产品
* 编辑履历:
* 作者 日期 版本 修改内容
* 李士越 2024/06/24 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.WinForm.Controls;
using System.Linq;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
///
/// 配置QC项目产品
///
public partial class F_MST_0504 : FormBase
{
#region 成员变量
///
/// 配置QC项目产品
///
private int _formStatus;
#endregion
#region 构造函数
///
/// 配置或撤销产品工序配置
///
/// 1:配置到工序;2:从工序撤销
/// 产品列表
public F_MST_0504(int formStatus, DataTable goods)
{
InitializeComponent();
this.dgvGoods.AutoGenerateColumns = false;
if (goods.Columns.Contains("Sel"))
{
goods.Columns.Remove("Sel");
}
goods.Columns.Add("Sel", typeof(string));
this.dgvGoods.DataSource = goods;
this._formStatus = formStatus;
this.Text = "配置QC项目产品";
GetlongdingList();
}
#endregion
#region 事件
///
/// 关闭
///
///
///
private void tsbtnClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
///
/// 自适应列宽
///
///
///
private void tsbtnAdaptive_Click(object sender, System.EventArgs e)
{
this.dgvGoods.AutoResizeColumns();
}
///
/// 画面加载
///
///
///
private void F_MST_0504_Load(object sender, System.EventArgs e)
{
try
{
foreach (DataGridViewColumn item in this.dgvGoods.Columns)
{
if ("Sel" != item.Name)
{
item.ReadOnly = true;
}
}
this.dgvGoods.IsSetInputColumnsColor = true;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 全选
///
///
///
private void tsbtnAllCheck_Click(object sender, System.EventArgs e)
{
try
{
this.dgvGoods.CommitEdit(DataGridViewDataErrorContexts.Commit);
foreach (DataGridViewRow item in dgvGoods.Rows)
{
DataRowView row = item.DataBoundItem as DataRowView;
if (row != null)
{
row["Sel"] = "1";
row.EndEdit();
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 反选
///
///
///
private void tsbtnUnCheck_Click(object sender, System.EventArgs e)
{
try
{
this.dgvGoods.CommitEdit(DataGridViewDataErrorContexts.Commit);
foreach (DataGridViewRow item in dgvGoods.Rows)
{
DataRowView row = item.DataBoundItem as DataRowView;
if (row != null)
{
int c = int.Parse(row["Sel"].ToString()!="" ? row["Sel"].ToString():"0");
row["Sel"] = (c == 1 ? 0 : 1).ToString();
row.EndEdit();
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 全不选
///
///
///
private void tsbtnNoCheck_Click(object sender, System.EventArgs e)
{
try
{
this.dgvGoods.CommitEdit(DataGridViewDataErrorContexts.Commit);
foreach (DataGridViewRow item in dgvGoods.Rows)
{
DataRowView row = item.DataBoundItem as DataRowView;
if (row != null)
{
row["Sel"] = "0";
row.EndEdit();
}
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 保存
///
///
///
private void tsbtnSave_Click(object sender, EventArgs e)
{
try
{
if (this.longdingList.Text=="") {
MessageBox.Show("没有选择检验标准", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
this.dgvGoods.CommitEdit(DataGridViewDataErrorContexts.Commit);
this.dgvGoods.EndEdit();
DataTable goods = this.dgvGoods.DataSource as DataTable;
List goodsIDList = new List();
List goodsCodeList = new List();
//筛选Sel为1的进行循环
foreach (DataRow item in goods.AsEnumerable().Where(ex => ex.Field("Sel") == "1"))
{
item.EndEdit();
if ("1" == item["Sel"].ToString())
{
goodsIDList.Add(item["GoodsID"].ToString());
goodsCodeList.Add(item["GoodsCode"].ToString());
}
}
if (goodsIDList.Count == 0)
{
MessageBox.Show("没有选择任何产品", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrWhiteSpace(this.longdingList.Text))
{
DialogResult dr = MessageBox.Show("确定保存?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dr != DialogResult.OK)
{
return;
}
}
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "F_MST_0504";
cre.Name = "Insert_T_P_Fqcitemsgoods";
cre.Properties["GoodsIDs"] = string.Join(",", goodsIDList);
cre.Properties["GoodsCodes"] = string.Join(",", goodsCodeList);
cre.Properties["ITEMSID"] = this.longdingList.SelectedValue;
ServiceResultEntity sre = CommonModuleProxy.Service.DoRequest(cre);
if (sre.Status == Constant.ServiceResultStatus.Success)
{
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品", "配置"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品工序", (_formStatus == 1 ? "配置" : "撤销")),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 获取检验标准名称
///
/// 获取检验标准名称
///
public void GetlongdingList()
{
ServiceResultEntity sre = CommonModuleProxy.Service.DoRequest(new ClientRequestEntity()
{
NameSpace = "F_MST_0504",
Name = "GetlongdingList"
});
if (sre.Status == Basics.BaseResources.Constant.ServiceResultStatus.Success)
{
longdingList.DisplayMember = "INSPECTNAME";
longdingList.ValueMember = "ITEMSID";
longdingList.DataSource = sre.Data.Tables[0];
longdingList.SelectedText = "";
longdingList.Text = "";
}
}
#endregion
}
}