/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PAM_0402.cs
* 2.功能描述:新建/编辑产品品质、品质考核
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2015/08/18 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.PAMModule
{
public partial class F_PAM_0402 : 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;
#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_PAM_0402(Constant.FormMode formType, int entityId)
{
InitializeComponent();
this._formType = formType;
this._entityId = entityId;
this._PieceTacticsID = entityId;
// 窗体显示的Title
if (this._formType == Constant.FormMode.Add)
{
this.Text = FormTitles.F_PAM_0402_ADD;
}
else if (this._formType == Constant.FormMode.Edit)
{
this.Text = FormTitles.F_PAM_0402_EDIT;
}
this.btnSave.Text = ButtonText.BTN_SAVE;
this.btnCancel.Text = ButtonText.BTN_CLOSE;
}
#endregion
#region 事件处理
///
/// 窗体加载
///
///
///
private void F_MST_0702_Load(object sender, EventArgs e)
{
try
{
this.dgvWages.AutoGenerateColumns = false;
this.dgvQualityWages.AutoGenerateColumns = false;
//BindPieceType();//绑定计件工序类型
// 绑定工资方案数据源
DataSet dsPayPlan = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PAMModuleProxy.Service.GetPayPlan();
}));
if (dsPayPlan != null && dsPayPlan.Tables[0].Rows.Count > 0)
{
DataRow dr = dsPayPlan.Tables[0].NewRow();
dr["PayPlanName"] = "";
dr["PayPlanID"] = -1;
dsPayPlan.Tables[0].Rows.InsertAt(dr, 0);
cmbPayPlan.DataSource = dsPayPlan.Tables[0];
cmbPayPlan.DisplayMember = "PayPlanName";
cmbPayPlan.ValueMember = "PayPlanID";
}
// 绑定工价分类数据源
DataSet dsWagesType = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PAMModuleProxy.Service.GetAllWagesType();
}));
if (dsWagesType != null && dsWagesType.Tables[0].Rows.Count > 0)
{
//DataView dv = dsWagesType.Tables[0].DefaultView;
//dv.RowFilter = "valueflag=1";
//this.WagesTypeID.DataSource = dv.ToTable();
//this.WagesTypeID.DisplayMember = "WagesTypeName";
//this.WagesTypeID.ValueMember = "WagesTypeID";
DataView dv = dsWagesType.Tables[0].DefaultView;
dv.RowFilter = "valueflag=1";
DataTable dtWagesType = dv.ToTable();
this.WagesTypeID.DataSource = dtWagesType;
this.WagesTypeID.DisplayMember = "WagesTypeName";
this.WagesTypeID.ValueMember = "WagesTypeID";
if (this._formType == Constant.FormMode.Add)
{
for (int i = 0; i < dtWagesType.Rows.Count; i++)
{
DataRow dr = DtLeftDataSource.NewRow();
dr["WagesTypeID"] = dtWagesType.Rows[i]["WagesTypeID"].ToString();
dr["RowIndexFlag"] = i;
DtLeftDataSource.Rows.Add(dr);
}
}
}
// 加载缺陷扣罚管理数据
this.GetAllDefectFine();
//// 缺陷扣罚
//DataSet dsDefectFine = (DataSet)DoAsync(new BaseAsyncMethod(() =>
//{
// return SystemModuleProxy.Service.GetDictionaryData(0, "ASE002");
//}));
//this.cmbDefectFine.DisplayMember = "DictionaryValue";
//this.cmbDefectFine.ValueMember = "DictionaryID";
//this.cmbDefectFine.DataSource = dsDefectFine.Tables[0];
//如果是修改,要绑定选中的信息
if (this._formType == Constant.FormMode.Edit)
{
DataSet dsWagesType2 = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PAMModuleProxy.Service.GetAllWagesType();
}));
if (dsWagesType2 != null && dsWagesType2.Tables[0].Rows.Count > 0)
{
DataView dv = dsWagesType2.Tables[0].DefaultView;
dv.RowFilter = "valueflag=1";
DataTable dtWagesType = dv.ToTable();
this.WagesTypeID.DataSource = dtWagesType;
this.WagesTypeID.DisplayMember = "WagesTypeName";
this.WagesTypeID.ValueMember = "WagesTypeID";
}
//BindJobsData();//编辑工种数据源
BindData();//绑定工资工种数据源
}
//如果是新建,选项默认值设定
else if (this._formType == Constant.FormMode.Add)
{
this.dgvWages.DataSource = DtLeftDataSource;
this.dgvQualityWages.DataSource = DtRightDataSource.Copy(); ;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 获取缺陷扣罚管理的全部数据
///
/// 用户信息
///
///
/// 2016.1.5 王鑫 新建
///
private void GetAllDefectFine()
{
try
{
DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return SystemModuleProxy.Service.GetAllDefectFine();
}));
if(dsResultAccount!=null && dsResultAccount.Tables[0].Rows.Count>0)
{
DataView dv = dsResultAccount.Tables[0].DefaultView;
dv.RowFilter = "valueflag=1";
this.cmbDefectFine.DisplayMember = "DefectFineCode";
this.cmbDefectFine.ValueMember = "DefectFineID";
this.cmbDefectFine.DataSource = dv.ToTable();
}
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 单元格开始编辑事件
///
///
///
private void dgvGoods_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
}
///
/// 选定项发生改变事件
///
///
///
private void dgvWagesType_SelectionChanged(object sender, EventArgs e)
{
try
{
if (this.dgvWages.CurrentCell != null)
{
if (this.dgvWages.Rows[this.dgvWages.CurrentCell.RowIndex].Cells["RowIndexFlag"].Value.ToString() != string.Empty)
{
this._currentRowIndexFlag = Convert.ToInt32(this.dgvWages.Rows[this.dgvWages.CurrentCell.RowIndex].Cells["RowIndexFlag"].Value);
if (this.dgvWages.Rows[this.dgvWages.CurrentCell.RowIndex].Cells["RowIndexFlag"].Value.ToString() != "")
{
//if (this.dgvWages.Rows[this.dgvWages.CurrentCell.RowIndex].Cells["StandardWages"].Value.ToString() != "")
//{
// this._currentStandardWages = Convert.ToInt32(this.dgvWages.Rows[this.dgvWages.CurrentCell.RowIndex].Cells["StandardWages"].Value);
//}
}
DataTable dtJobs = this.DtRightDataSource;
DataTable dtHistory = this.dgvQualityWages.DataSource as DataTable;//
if (dtHistory != null)
{
dtHistory = dtHistory.Copy();
}
if (dtHistory != null && dtHistory.Rows.Count > 0)
{
if (dtHistory.Rows[0]["RowIndexFlag"].ToString() != "")
{
//DataRow[] dr = this.DtRightDataSource.Select("RowIndexFlag=" + dtHistory.Rows[0]["RowIndexFlag"]);
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;
this.dgvQualityWages.DataSource = dv.ToTable();
}
}
else
{
//this._selectedrow++;
//int rowindex = this._selectedrow;
//this.dgvWages.Rows[this.dgvWages.CurrentCell.RowIndex].Cells["RowIndexFlag"].Value = rowindex;
//this._currentRowIndexFlag = rowindex;
//this._currentStandardWages = 0;
DataTable dtJobs = this.DtRightDataSource;
DataTable dtHistory = this.dgvQualityWages.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.dgvQualityWages.DataSource = dv.ToTable();
}
//}
}
else
{
if (dtJobs != null)
{
DataView dv = dtJobs.DefaultView;
dv.RowFilter = "RowIndexFlag=-1";
this.dgvQualityWages.DataSource = dv.ToTable();
}
else
{
this.dgvQualityWages.DataSource = null;
}
}
}
}
this.dgvQualityWages.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
{
if (string.IsNullOrEmpty(this.txtPayPlanName.Text))
{
// 提示信息
MessageBox.Show("策略名称不能为空",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
DataTable dtLeft = this.dgvWages.DataSource as DataTable;
DataView dv = dtLeft.DefaultView;
dv.RowFilter = "WagesTypeID>0";
dtLeft = dv.ToTable();
dtLeft.AcceptChanges();
if (dtLeft.Rows.Count == 0)
{
MessageBox.Show("请添写工价分类信息",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (this.DtRightDataSource != null && this.DtRightDataSource.Rows.Count == 0)
{
MessageBox.Show("请添写工价分类明细信息",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
QualityASS entity = new QualityASS();
entity.QualityASSTacticsID = this._PieceTacticsID;
if (cmbPayPlan.SelectedValue.ToString() != "-1")
{
entity.PayPlanID = Convert.ToInt32(cmbPayPlan.SelectedValue);
}
entity.DefectFine = Convert.ToInt32(this.cmbDefectFine.SelectedValue);
//entity.QualityBaseProcedureIDS = this.dkQualityBaseProcedure.ProcedureIDS;//质量基数工序
entity.QualityTacticsName = this.txtPayPlanName.Text;
if (dtLeft != null && dtLeft.Rows.Count > 0)
{
List qagesentitys = new List();
for (int i = 0; i < dtLeft.Rows.Count; i++)
{
WCF.DataModels.PAMModule.QualityGoods wageentity = new WCF.DataModels.PAMModule.QualityGoods();
wageentity.WagesTypeID = Convert.ToInt32(dtLeft.Rows[i]["WagesTypeID"]);
//质量工价
if (this.DtRightDataSource != null && this.DtRightDataSource.Rows.Count > 0)
{
List qualityWagesEntitys = new List();
//for (int j = 0; j < DtRightDataSource.Rows.Count; j++)
//{
// DataRow[] drWagesTypeID = dtLeft.Select("RowIndexFlag=" + DtRightDataSource.Rows[j]["RowIndexFlag".ToString()]);
//if (drWagesTypeID.Length > 0)
//{
DataRow[] dr2 = DtRightDataSource.Select("RowIndexFlag=" + dtLeft.Rows[i]["RowIndexFlag".ToString()]);
foreach (DataRow r in dr2)
{
WCF.DataModels.PAMModule.QualityReward qualityWagesEntity = new WCF.DataModels.PAMModule.QualityReward();
qualityWagesEntity.WagesTypeID = Convert.ToInt32(dtLeft.Rows[i]["WagesTypeID"]);
qualityWagesEntity.QualityRate = Convert.ToDecimal(r["QualityRate"].ToString() == "" ? 0 : r["QualityRate"]) / 100;
qualityWagesEntity.QualityReward2 = Convert.ToDecimal(r["QualityReward"].ToString() == "" ? 0 : r["QualityReward"]);
qualityWagesEntitys.Add(qualityWagesEntity);
}
// }
// }
wageentity.qualityReward = qualityWagesEntitys;
}
qagesentitys.Add(wageentity);
}
entity.qualityGoods = qagesentitys;
}
int returnValue = (int)DoAsync(new BaseAsyncMethod(() =>
{
return PAMModuleProxy.Service.SaveQualityASS(entity);
}));
if (returnValue >= 0) //等于O,表示未修改数据,影响行为0
{
// 提示信息
MessageBox.Show(string.Format(Messages.MSG_CMN_I001, this.Text, "保存"),
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DialogResult = DialogResult.OK;
}
else if (returnValue == -1)
{
// 提示信息
MessageBox.Show("一个解决方案只能对应一个计件工资策略",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (returnValue == -2)
{
// 提示信息
MessageBox.Show("工价分类不能重复在工资方案使用",
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (returnValue == -3)
{
// 提示信息
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.dgvQualityWages.DataSource = dv.ToTable();// DtRightDataSource;
this.dgvWages.DataSource = DtLeftDataSource;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
///
/// 删除行时
///
///
///
private void dgvGoods_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
{
}
///
/// 产品工价添加行事件
///
///
///
private void dgvWages_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
try
{
if (e.Row.Index != -1)
{
if (this.dgvWages.CurrentCell != null)
{
this._selectedrow++;//用于过滤边条件
this._currentRowIndexFlag = this._selectedrow;
this.dgvWages.Rows[this.dgvWages.CurrentCell.RowIndex].Cells["RowIndexFlag"].Value = this._selectedrow;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
private void dgvQualityWages_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
}
private void F_PAM_0402_Shown(object sender, EventArgs e)
{
this.dgvQualityWages.IsSetInputColumnsColor = true;
}
private void dgvQualityWages_CellValidated(object sender, DataGridViewCellEventArgs e)
{
if ((e.ColumnIndex == 0 || e.ColumnIndex == 1) && e.RowIndex != -Constant.INT_IS_ONE)
{
this.dgvQualityWages.Rows[this.dgvQualityWages.CurrentCell.RowIndex].Cells["RowIndexFlag1"].Value = this._currentRowIndexFlag;
}
}
}
}