/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_MST_0903.cs
* 2.功能描述:设置缺陷对应缺陷扣罚及扣除数
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2016/1/5 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.DockPanel;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.Controls;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.DataModels.PAMModule;
using Dongke.IBOSS.PRD.WCF.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
namespace Dongke.IBOSS.PRD.Client.SystemModule
{
public partial class F_MST_0903 : FormBase
{
#region 成员变量
// 窗体模式ID
//private Constant.FormMode _formType;
// 操作实体ID(方案)
//private int? _entityId;
// 工序
private DataSet _dsProcedure = new DataSet();
// 工种编码值
//private string _GoodsCodeValue;
//private bool _ShowFlag = true;
// 数据源
//DataTable dt = null;
// 当前工资方案ID
//private int? _currentWagesTypeID = null;
// 产品全部数据集
//DataTable dtAllDataLeft = null;
// 质量全部数据集
//DataTable dtAllDataRight = null;
// 产品工价数据源
DataTable _dtLeftDataSource = null;
// 质量工价数据源
DataTable _dtRightDataSource = null;
// 当前行ID
private int _selectedrow = -1;
// 当前选定行
private int _currentRowIndexFlag = 0;
// 当前标准工价
private int _currentStandardWages = 0;
// 计件工资策略ID
private int? _PieceTacticsID = null;
// 缺陷扣罚数据源
private DataTable _dtDefectFine = null;
// 缺陷扣除数数据源
private DataTable _dtDefectDeduction = null;
// 临时数据源
private DataTable _dtTempSource = null;
//上次临时标记
//private string _tempRowIndex = "";
// 临时扣除数数据源
private DataTable _dtTempSource2 = null;
#endregion
#region 属性
///
/// 产品工价数据源属性
///
public DataTable DtLeftDataSource
{
set
{
this._dtLeftDataSource = value;
}
get
{
if (this._dtLeftDataSource == null)
{
this._dtLeftDataSource = new DataTable();
this._dtLeftDataSource.Columns.Add("WagesTypeID", typeof(decimal)); //工价分类ID
this._dtLeftDataSource.Columns.Add("RowIndexFlag"); //行标识
return this._dtLeftDataSource;
}
else
{
return this._dtLeftDataSource;
}
}
}
///
/// 质量工价数据源属性
///
public DataTable DtRightDataSource
{
set
{
this._dtRightDataSource = value;
}
get
{
if (this._dtRightDataSource == null)
{
this._dtRightDataSource = new DataTable();
this._dtRightDataSource.Columns.Add("QualityRate", typeof(decimal)); //质量区间开始
this._dtRightDataSource.Columns.Add("WagesTypeID", typeof(int)); //差额
this._dtRightDataSource.Columns.Add("QualityReward"); //质量工价
this._dtRightDataSource.Columns.Add("RowIndexFlag", typeof(int)); //行标识
return this._dtRightDataSource;
}
else
{
return this._dtRightDataSource;
}
}
}
#endregion
#region 构造函数
///
/// 窗体构造
///
/// 窗体打开模式
/// 操作实体ID
public F_MST_0903()
{
InitializeComponent();
this.Text = FormTitles.F_MST_0903;
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
}
#endregion
#region 事件处理
///
/// 窗体加载
///
///
///
private void F_MST_0903_Load(object sender, EventArgs e)
{
try
{
this.dgvDefect.AutoGenerateColumns = false;
this.dgvDefectFine.AutoGenerateColumns = false;
this.dgvDefectDeduction.AutoGenerateColumns = false;
#region 加载缺陷扣罚数据源
DataSet dsDefectFine = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetAllDefectFineRelation();
}));
//if (dsDefectFine != null && dsDefectFine.Tables[0].Rows.Count > 0)
//{
_dtDefectFine = dsDefectFine.Tables[0];
//}
#endregion
#region 加载缺陷扣除数数据源
DataSet dsDefectDeduction = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetAllDefectDeductionRelation();
}));
//if (dsDefectDeduction != null && dsDefectDeduction.Tables[0].Rows.Count > 0)
//{
_dtDefectDeduction = dsDefectDeduction.Tables[0]; ;
//}
#endregion
#region 加载缺陷数据源
DataSet defectds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetDefectData(1);
}));
if (defectds != null
&& defectds.Tables.Count > Constant.INT_IS_ZERO
&& defectds.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
{
defectds.Tables[0].DefaultView.RowFilter = "valueflag =1";
this.dgvDefect.DataSource = defectds.Tables[0].DefaultView.ToTable();
}
#endregion
#region 加载缺陷扣罚下拉数据源
DataSet dsDefectFineDDL = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetAllDefectFine();
}));
if (dsDefectFineDDL != null && dsDefectFineDDL.Tables[0].Rows.Count > 0)
{
defectfineID2.DataSource = dsDefectFineDDL.Tables[0];
defectfineID2.DisplayMember = "DefectFineCode";
defectfineID2.ValueMember = "DefectFineID";
}
#endregion
#region 加载缺陷扣除数下拉数据源
DataSet dsDefectDeductionDDL = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetAllDefectDeduction();
}));
if (dsDefectDeductionDDL != null && dsDefectDeductionDDL.Tables[0].Rows.Count > 0)
{
DefectDeductionID.DataSource = dsDefectDeductionDDL.Tables[0];
DefectDeductionID.DisplayMember = "DefectDeductionNum";
DefectDeductionID.ValueMember = "DefectDeductionID";
}
#endregion
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 单元格开始编辑事件
///
///
///
private void dgvGoods_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
}
///
/// 选定项发生改变事件
///
///
///
private void dgvDefect_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvDefect.CurrentCell != null)
{
if (this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["defectid"].Value.ToString() != string.Empty)
{
DataTable dtJobs = this._dtDefectFine;
DataTable dtJobs2 = this._dtDefectDeduction;
DataTable dtHistory = this.dgvDefectFine.DataSource as DataTable;//
if (dtHistory != null)
{
_dtTempSource = dtHistory;
}
DataTable dtHistory2 = this.dgvDefectDeduction.DataSource as DataTable;//
if (dtHistory2 != null)
{
_dtTempSource2 = dtHistory2;
}
this._currentRowIndexFlag = Convert.ToInt32(this.dgvDefect.Rows[this.dgvDefect.CurrentCell.RowIndex].Cells["defectid"].Value);
//if(this._dtDefectFine!=null)
//{
// DataView dvDefectFine = this._dtDefectFine.DefaultView;
// dvDefectFine.RowFilter = "defectid=" + this._currentRowIndexFlag;
// this.dgvDefectFine.DataSource = dvDefectFine.ToTable();
//}
//if(this._dtDefectDeduction!=null)
//{
// DataView dvDefectDeduction = this._dtDefectDeduction.DefaultView;
// dvDefectDeduction.RowFilter = "defectid=" + this._currentRowIndexFlag;
// this.dgvDefectDeduction.DataSource = dvDefectDeduction.ToTable();
//}
if (_dtTempSource != null && _dtTempSource.Rows.Count > 0)
{
if (_dtTempSource.Rows[0]["defectid"].ToString() != "")
{
DataRow[] dr = dtJobs.Select("defectid=" + _dtTempSource.Rows[0]["defectid"].ToString());//this._currentRowIndexFlag
//先删除掉
foreach (DataRow r in dr)
{
r.Delete();
}
//重新插入
for (int i = 0; i < _dtTempSource.Rows.Count; i++)
{
if (_dtTempSource.Rows[i]["DefectID"].ToString() != "" && _dtTempSource.Rows[i]["DefectFineID"].ToString() != "")
{
DataRow drNew = dtJobs.NewRow();
drNew["DefectID"] = _dtTempSource.Rows[i]["DefectID"].ToString();
drNew["DefectFineID"] = _dtTempSource.Rows[i]["DefectFineID"].ToString();
dtJobs.Rows.Add(drNew);
}
}
_dtTempSource = null;
}
}
if (dtJobs != null)
{
DataView dv = dtJobs.DefaultView;
dv.RowFilter = "defectid=" + this._currentRowIndexFlag;
this.dgvDefectFine.DataSource = dv.ToTable();
}
if (_dtTempSource2 != null && _dtTempSource2.Rows.Count > 0)
{
if (_dtTempSource2.Rows[0]["defectid"].ToString() != "")
{
DataRow[] dr = dtJobs2.Select("defectid=" + _dtTempSource2.Rows[0]["defectid"].ToString());//this._currentRowIndexFlag
//先删除掉
foreach (DataRow r in dr)
{
r.Delete();
}
//重新插入
for (int i = 0; i < _dtTempSource2.Rows.Count; i++)
{
if (_dtTempSource2.Rows[i]["DefectID"].ToString() != "" && _dtTempSource2.Rows[i]["DefectDeductionID"].ToString() != "")
{
DataRow drNew = dtJobs2.NewRow();
drNew["DefectID"] = _dtTempSource2.Rows[i]["DefectID"].ToString();
drNew["DefectDeductionID"] = _dtTempSource2.Rows[i]["DefectDeductionID"].ToString();
dtJobs2.Rows.Add(drNew);
}
}
_dtTempSource2 = null;
}
}
if (dtJobs2 != null)
{
DataView dv = dtJobs2.DefaultView;
dv.RowFilter = "defectid=" + this._currentRowIndexFlag;
this.dgvDefectDeduction.DataSource = dv.ToTable();
}
}
else
{
//DataTable dtJobs = this.DtRightDataSource;
//DataTable dtHistory = this.dgvDefectFine.DataSource as DataTable;//
//if (dtHistory != null && dtHistory.Rows.Count > 0)
//{
// // DataRow[] dr = this.DtRightDataSource.Select("RowIndexFlag=" + (dtHistory.Rows[0]["RowIndexFlag"].ToString() == "" ? "0" : dtHistory.Rows[0]["RowIndexFlag"].ToString()));
// DataRow[] dr = this.DtRightDataSource.Select("RowIndexFlag=" + (dtHistory.Rows[0]["RowIndexFlag"].ToString() == "" ? this._currentRowIndexFlag : Convert.ToInt32(dtHistory.Rows[0]["RowIndexFlag"].ToString())));
// //先删除掉
// foreach (DataRow r in dr)
// {
// r.Delete();
// }
// //重新插入
// for (int i = 0; i < dtHistory.Rows.Count; i++)
// {
// if (dtHistory.Rows[i]["QualityRate"].ToString() != "" || dtHistory.Rows[i]["QualityReward"].ToString() != "")
// {
// DataRow drNew = DtRightDataSource.NewRow();
// drNew["QualityRate"] = dtHistory.Rows[i]["QualityRate"].ToString();
// drNew["QualityReward"] = dtHistory.Rows[i]["QualityReward"].ToString();
// drNew["RowIndexFlag"] = dtHistory.Rows[i]["RowIndexFlag"].ToString();
// DtRightDataSource.Rows.Add(drNew);
// }
// }
// if (dtJobs != null)
// {
// DataView dv = dtJobs.DefaultView;
// //dv.RowFilter = "RowIndexFlag=" + this._currentRowIndexFlag;
// dv.RowFilter = "RowIndexFlag=-1";
// this.dgvDefectFine.DataSource = dv.ToTable();
// }
// //}
//}
//else
//{
// if (dtJobs != null)
// {
// DataView dv = dtJobs.DefaultView;
// dv.RowFilter = "RowIndexFlag=-1";
// this.dgvDefectFine.DataSource = dv.ToTable();
// }
// else
// {
// this.dgvDefectFine.DataSource = null;
// }
//}
}
}
this.dgvDefectFine.IsSetInputColumnsColor = true;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 保存按钮事件
///
///
///
private void btnSave_Click_1(object sender, EventArgs e)
{
try
{
dgvDefect_SelectionChanged(null, null);
if (this._dtDefectFine == null || this._dtDefectFine.Rows.Count == 0)
{
return;
}
if (this._dtDefectDeduction == null || this._dtDefectDeduction.Rows.Count == 0)
{
return;
}
//// 获取缺陷数据源,校验是否有重重的数据
//DataTable dtDefect = this.dgvDefect.DataSource as DataTable;
//bool isError = false;
//int ErrorIndex = 0;
//for (int i = 0; i < dtDefect.Rows.Count; i++)
//{
// DataRow[] dr = _dtDefectFine.Select("defectid=" + dtDefect.Rows[i]["defectid"]);
// if(dr.Length>1)
// {
// ErrorIndex = i;
// isError = true;
// break;
// }
//}
//if(isError)
//{
// this.dgvDefect.Rows[ErrorIndex].Selected = true;
// // 提示信息
// MessageBox.Show("当前缺陷有重复的缺陷扣罚",
// this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
// return;
//}
//for (int i = 0; i < dtDefect.Rows.Count; i++)
//{
// DataRow[] dr = _dtDefectDeduction.Select("defectid=" + dtDefect.Rows[i]["defectid"]);
// if (dr.Length > 1)
// {
// ErrorIndex = i;
// isError = true;
// break;
// }
//}
//if (isError)
//{
// this.dgvDefect.Rows[ErrorIndex].Selected = true;
// // 提示信息
// MessageBox.Show("当前缺陷有重复的缺陷扣除数",
// this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
// return;
//}
int returnValue = (int)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.SaveDefectRelation(this._dtDefectFine, this._dtDefectDeduction);
}));
if (returnValue >= 0) //等于O,表示未修改数据,影响行为0
{
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (returnValue == -1)
{
// 提示信息
MessageBox.Show("保存失败",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 绑定编辑数据
///
private void BindData()
{
try
{
DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PAMModuleProxy.Service.GetQualityASSByID(Convert.ToInt32(this._PieceTacticsID));
}));
if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
{
//绑定主信息
//////if (dsResultAccount.Tables[0].Rows[0]["PayPlanID"].ToString() != "")
//////{
////// this.cmbPayPlan.SelectedValue = dsResultAccount.Tables[0].Rows[0]["PayPlanID"].ToString();
//////}
//////this.cmbDefectFine.SelectedValue = dsResultAccount.Tables[0].Rows[0]["DefectFine"].ToString();
////////this.dkQualityBaseProcedure.ProcedureID = Convert.ToInt32(dsResultAccount.Tables[0].Rows[0]["QualityBaseProcedureID"]);
////////this.dkQualityBaseProcedure.Text = dsResultAccount.Tables[0].Rows[0]["QualityBaseProcedure"].ToString();
//////this.txtPayPlanName.Text = dsResultAccount.Tables[0].Rows[0]["QualityTacticsName"].ToString();
//if (dsResultAccount.Tables[3].Rows.Count > 0)
//{
// string IDS = "";
// string TextS = "";
// foreach (DataRow r1 in dsResultAccount.Tables[3].Rows)
// {
// TextS += r1["ProcedureName"].ToString() + ",";
// IDS += r1["ProcedureID"].ToString() + ",";
// }
// IDS = IDS.Trim(',');
// TextS = TextS.Trim(',');
// if (IDS != "")
// {
// //this.dkQualityBaseProcedure.Text = TextS;
// //this.dkQualityBaseProcedure.ProcedureIDS = IDS;
// }
//}
if (dsResultAccount != null && dsResultAccount.Tables[1].Rows.Count > 0)
{
//产品工价
this._selectedrow = dsResultAccount.Tables[1].Rows.Count;
for (int i = 0; i < dsResultAccount.Tables[1].Rows.Count; i++)
{
DataRow dr = this.DtLeftDataSource.NewRow();
dr["WagesTypeID"] = dsResultAccount.Tables[1].Rows[i]["WagesTypeID"];
dr["RowIndexFlag"] = i;
this.DtLeftDataSource.Rows.Add(dr);
//this._selectedrow++;//用于过滤边条件
if (dsResultAccount != null && dsResultAccount.Tables[2].Rows.Count > 0)
{
DataRow[] r = dsResultAccount.Tables[2].Select("WagesTypeID=" + dsResultAccount.Tables[1].Rows[i]["WagesTypeID"]);
if (r.Length > 0)
{
foreach (DataRow rr in r)
{
DataRow dr2 = this.DtRightDataSource.NewRow();
dr2["QualityRate"] = Convert.ToDecimal(rr["QualityRate"]) * 100;
dr2["WagesTypeID"] = rr["WagesTypeID"];
dr2["QualityReward"] = rr["QualityReward"];
dr2["RowIndexFlag"] = i;
this.DtRightDataSource.Rows.Add(dr2);
}
}
}
}
}
DataView dv = this.DtRightDataSource.DefaultView;
dv.RowFilter = "RowIndexFlag=0";
this.dgvDefectFine.DataSource = dv.ToTable();// DtRightDataSource;
this.dgvDefect.DataSource = DtLeftDataSource;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
///
/// 删除行时
///
///
///
private void dgvGoods_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
}
private void dgvQualityWages_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
}
private void F_PAM_0402_Shown(object sender, EventArgs e)
{
this.dgvDefectFine.IsSetInputColumnsColor = true;
}
private void dgvDefectFine_CellValidated(object sender, DataGridViewCellEventArgs e)
{
if ((e.ColumnIndex == 0 || e.ColumnIndex == 1) && e.RowIndex != -Constant.INT_IS_ONE)
{
this.dgvDefectFine.Rows[this.dgvDefectFine.CurrentCell.RowIndex].Cells["defectid1"].Value = this._currentRowIndexFlag;
}
}
private void dgvDefectDeduction_CellValidated(object sender, DataGridViewCellEventArgs e)
{
if ((e.ColumnIndex == 0 || e.ColumnIndex == 1) && e.RowIndex != -Constant.INT_IS_ONE)
{
this.dgvDefectDeduction.Rows[this.dgvDefectDeduction.CurrentCell.RowIndex].Cells["defectid2"].Value = this._currentRowIndexFlag;
}
}
}
}