/******************************************************************************* * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential * 类的信息: * 1.程序名称:F_PAM_0203.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_0302 : 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 decimal _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("StandardWages", typeof(decimal)); //标准工价 this._dtLeftDataSource.Columns.Add("DamageSubsidyRate", typeof(decimal)); //损坯补贴系数 this._dtLeftDataSource.Columns.Add("DamageSubsidy", typeof(decimal)); //损坯补贴 this._dtLeftDataSource.Columns.Add("RSuperiorCoefficient", typeof(decimal)); //干补正品系数 this._dtLeftDataSource.Columns.Add("RQualifiedCoefficient", typeof(decimal)); //干补副品系数 this._dtLeftDataSource.Columns.Add("RepairSubsidyRate", typeof(decimal)); //干补补贴系数 this._dtLeftDataSource.Columns.Add("RepairSubsidy", typeof(decimal)); //干补补贴 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("Balance", typeof(decimal)); //差额 this._dtRightDataSource.Columns.Add("QualityWages", typeof(decimal)); //质量工价 this._dtRightDataSource.Columns.Add("RowIndexFlag",typeof(int)); //行标识 return this._dtRightDataSource; } else { return this._dtRightDataSource; } } } #endregion #region 构造函数 /// /// 窗体构造 /// /// 窗体打开模式 /// 操作实体ID public F_PAM_0302(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_0302_ADD; } else if (this._formType == Constant.FormMode.Edit) { this.Text = FormTitles.F_PAM_0302_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"; //} //如果是修改,要绑定选中的信息 if (this._formType == Constant.FormMode.Edit) { //BindJobsData();//编辑工种数据源 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"; DataTable dtWagesType = dv.ToTable(); this.WagesTypeID.DataSource = dtWagesType; this.WagesTypeID.DisplayMember = "WagesTypeName"; this.WagesTypeID.ValueMember = "WagesTypeID"; } BindData();//绑定工资工种数据源 } //如果是新建,选项默认值设定 else if (this._formType == Constant.FormMode.Add) { // 绑定工价分类数据源 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"; DataTable dtWagesType = dv.ToTable(); this.WagesTypeID.DataSource = dtWagesType; this.WagesTypeID.DisplayMember = "WagesTypeName"; this.WagesTypeID.ValueMember = "WagesTypeID"; for (int i = 0; i < dtWagesType.Rows.Count; i++) { DataRow dr = DtLeftDataSource.NewRow(); dr["WagesTypeID"] = dtWagesType.Rows[i]["WagesTypeID"].ToString(); dr["StandardWages"] = 0; dr["DamageSubsidyRate"] = 1; dr["DamageSubsidy"] = 0; dr["RSuperiorCoefficient"] = 1; dr["RQualifiedCoefficient"] = 1; dr["RepairSubsidyRate"] = 1; dr["RepairSubsidy"] = 0; dr["RowIndexFlag"] = i; DtLeftDataSource.Rows.Add(dr); } } this.dgvWages.DataSource = DtLeftDataSource; this.dgvQualityWages.DataSource = DtRightDataSource; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 窗体关闭 /// /// /// private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } /// /// 窗体释放 /// /// /// private void F_MST_0702_FormClosed(object sender, FormClosedEventArgs e) { this.Dispose(); } /// /// 数据统计工序变更 /// /// /// private void dgvGoods_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (this.dgvQualityWages.Rows.Count <= 1) { return; } DataGridViewRow rowItem = this.dgvQualityWages.Rows[e.RowIndex]; DataGridViewColumn columnItem = this.dgvQualityWages.Columns[e.ColumnIndex]; // 用编号获取产品信息 if ("GoodsCode".Equals(columnItem.Name)) { string GoodsID = ""; if (this.dgvQualityWages.Rows[e.RowIndex].Cells["GoodsID"].Value != null) { GoodsID = this.dgvQualityWages.Rows[e.RowIndex].Cells["GoodsID"].Value.ToString(); } DataTable dtDataSource = FormUtility.BindGoodsRowDataSource(this.dgvQualityWages, e.RowIndex, columnItem.Name, _GoodsCodeValue); int row = e.RowIndex; // 返回多少行,进而给每个单元格传值,为的以后多个工资方案进行筛选 if (dtDataSource != null && dtDataSource.Rows.Count > 0) { for (int i = 0; i < dtDataSource.Rows.Count; i++) { //this.dgvGoods.Rows[row].Cells["WagesTypeID1"].Value = this._currentWagesTypeID; //DataRow dr = this.dtAllData.NewRow(); //dr["GoodsID"] = dtDataSource.Rows[i]["GoodsID"]; //dr["GoodsCode"] = dtDataSource.Rows[i]["GoodsCode"]; //dr["GoodsName"] = dtDataSource.Rows[i]["GoodsName"]; //dr["WagesTypeID"] = this._currentWagesTypeID; //dtAllData.Rows.Add(dr); //row++; //如果存在数据集中,此列标记删除 this.dgvQualityWages.Rows[row].Cells["WagesTypeID1"].Value = this._currentWagesTypeID; if (dtAllDataRight != null && GoodsID != "") { DataRow[] drSel = dtAllDataRight.Select(string.Format("WagesTypeID={0} and GoodsID={1}", this._currentWagesTypeID, GoodsID)); if (drSel.Length > 0) //存在,需要更把此行删除 { drSel[0].Delete(); } } if (GoodsID == "") //新增的时候,是否存在相同的工种编码 { //DataRow[] drSel = dtAllData.Select(string.Format("WagesTypeID={0} and GoodsID='{1}'", this._currentWagesTypeID, GoodsID)); //if (drSel.Length == 0) //不存在,把此行添加进来 //{ DataRow dr = this.dtAllDataRight.NewRow(); dr["GoodsID"] = dtDataSource.Rows[i]["GoodsID"]; dr["GoodsCode"] = dtDataSource.Rows[i]["GoodsCode"]; dr["GoodsName"] = dtDataSource.Rows[i]["GoodsName"]; dr["WagesTypeID"] = this._currentWagesTypeID; dtAllDataRight.Rows.Add(dr); row++; // } } else { DataRow dr = this.dtAllDataRight.NewRow(); dr["GoodsID"] = dtDataSource.Rows[i]["GoodsID"]; dr["GoodsCode"] = dtDataSource.Rows[i]["GoodsCode"]; dr["GoodsName"] = dtDataSource.Rows[i]["GoodsName"]; dr["WagesTypeID"] = this._currentWagesTypeID; dtAllDataRight.Rows.Add(dr); row++; } } this.dgvQualityWages.Rows[e.RowIndex].Selected = true; } // 设置可输入单元格的颜色 this.dgvQualityWages.IsSetInputColumnsColor = true; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 单元格开始编辑事件 /// /// /// private void dgvGoods_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { //try //{ // if (this.dgvQualityWages.Rows.Count <= 1 || !_ShowFlag) // { // return; // } // DataGridViewColumn columnItem = this.dgvQualityWages.Columns[e.ColumnIndex]; // //if ("GoodsCode".Equals(columnItem.Name)) // //{ // //_ShowFlag = false; // //_GoodsCodeValue = this.dgvQualityWages.Rows[e.RowIndex].Cells[columnItem.Name].Value + ""; // this.dgvQualityWages.Rows[e.RowIndex].Cells["RowIndexFlag1"].Value = this._currentRowIndexFlag; // // } // _ShowFlag = true; //} //catch (Exception ex) //{ // _ShowFlag = true; // // 对异常进行共通处理 // ExceptionManager.HandleEventException(this.ToString(), // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); //} } /// /// 选定项发生改变事件 /// /// /// 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.ToDecimal(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.Rows.Count > 0) { 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]["Balance"].ToString() != "") { DataRow drNew = DtRightDataSource.NewRow(); drNew["QualityRate"] = dtHistory.Rows[i]["QualityRate"].ToString(); drNew["Balance"] = dtHistory.Rows[i]["Balance"].ToString(); drNew["QualityWages"] = dtHistory.Rows[i]["QualityWages"].ToString(); drNew["RowIndexFlag"] = dtHistory.Rows[i]["RowIndexFlag"].ToString() == "" ? Convert.ToInt32(dtHistory.Rows[0]["RowIndexFlag"]) : Convert.ToInt32(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() == "" ? 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]["Balance"].ToString() != "") { DataRow drNew = DtRightDataSource.NewRow(); drNew["QualityRate"] = dtHistory.Rows[i]["QualityRate"].ToString(); drNew["Balance"] = dtHistory.Rows[i]["Balance"].ToString(); drNew["QualityWages"] = dtHistory.Rows[i]["QualityWages"].ToString(); drNew["RowIndexFlag"] = dtHistory.Rows[i]["RowIndexFlag"].ToString() == "" ? Convert.ToInt32(dtHistory.Rows[0]["RowIndexFlag"]) : Convert.ToInt32(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 (this.dkPieceProcedure.ProcedureIDS == null) { // 提示信息 MessageBox.Show("计件工序不能为空", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.txtPayPlanName.Text.Trim() == "") { // 提示信息 MessageBox.Show("策略名称不能为空", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (this.dkQualityBaseProcedure.ProcedureIDS == null) { // 提示信息 MessageBox.Show("质量基数工序不能为空", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } PieceworkEntity entity = new PieceworkEntity(); entity.PieceTacticsID = this._PieceTacticsID; if (cmbPayPlan.SelectedValue.ToString() != "-1") { entity.PayPlanID = Convert.ToInt32(cmbPayPlan.SelectedValue); } entity.PieceType = Convert.ToInt32(cmbPieceType.SelectedValue); entity.PayPlanName = this.txtPayPlanName.Text.Trim(); entity.QualityBaseProcedureIDS = this.dkQualityBaseProcedure.ProcedureIDS;//质量基数工序 entity.DamageCoefficient = this.txtDamageCoefficient.Text.Trim() == "" ? 1 : Convert.ToDecimal(this.txtDamageCoefficient.Text.Trim()); entity.UnqualifiedCoefficient = this.txtUnqualifiedCoefficient.Text.Trim() == "" ? 1 : Convert.ToDecimal(this.txtUnqualifiedCoefficient.Text.Trim()); entity.QualifiedCoefficient = this.txtQualifiedCoefficient.Text.Trim() == "" ? 1 : Convert.ToDecimal(this.txtQualifiedCoefficient.Text.Trim()); //损坯 entity.DamageFlag = chkDamageFlag.Checked ? "1" : "0"; entity.UnqualifiedFlag = chkUnqualifiedFlag.Checked ? "1" : "0"; entity.QualifiedFlag = chkQualifiedFlag.Checked ? "1" : "0"; entity.PieceProcedureIDS = this.dkPieceProcedure.ProcedureIDS;//计件工序 entity.PieceCoefficient = this.txtPieceCoefficient.Text.Trim() == "" ? 1 : Convert.ToDecimal(this.txtPieceCoefficient.Text.Trim()); DataTable dtLeft = this.dgvWages.DataSource as DataTable; //DataView dv = dtLeft.DefaultView; //dv.RowFilter = "WagesTypeID>0"; //dtLeft = dv.ToTable(); //dtLeft.AcceptChanges(); 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() == "" ? 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]["Balance"].ToString() != "") { DataRow drNew = DtRightDataSource.NewRow(); drNew["QualityRate"] = dtHistory.Rows[i]["QualityRate"].ToString(); drNew["Balance"] = dtHistory.Rows[i]["Balance"].ToString(); drNew["QualityWages"] = dtHistory.Rows[i]["QualityWages"].ToString(); drNew["RowIndexFlag"] = dtHistory.Rows[i]["RowIndexFlag"].ToString() == "" ? Convert.ToInt32(dtHistory.Rows[0]["RowIndexFlag"]) : Convert.ToInt32(dtHistory.Rows[i]["RowIndexFlag"].ToString()); DtRightDataSource.Rows.Add(drNew); } } } if (dtLeft != null && dtLeft.Rows.Count > 0) { List wagesentitys = new List(); for (int i = 0; i < dtLeft.Rows.Count; i++) { WCF.DataModels.PAMModule.WagesEntity wageentity = new WCF.DataModels.PAMModule.WagesEntity(); wageentity.WagesTypeID = Convert.ToInt32(dtLeft.Rows[i]["WagesTypeID"]); wageentity.StandardWages = Convert.ToDecimal(dtLeft.Rows[i]["StandardWages"].ToString() == "" ? 0 : dtLeft.Rows[i]["StandardWages"]); wageentity.DamageSubsidyRate = Convert.ToDecimal(dtLeft.Rows[i]["DamageSubsidyRate"].ToString() == "" ? 1 : dtLeft.Rows[i]["DamageSubsidyRate"]); wageentity.DamageSubsidy = Convert.ToDecimal(dtLeft.Rows[i]["DamageSubsidy"].ToString() == "" ? 0 : dtLeft.Rows[i]["DamageSubsidy"]); wageentity.RSuperiorCoefficient = Convert.ToDecimal(dtLeft.Rows[i]["RSuperiorCoefficient"].ToString() == "" ? 1 : dtLeft.Rows[i]["RSuperiorCoefficient"]); wageentity.RQualifiedCoefficient = Convert.ToDecimal(dtLeft.Rows[i]["RQualifiedCoefficient"].ToString() == "" ? 1 : dtLeft.Rows[i]["RQualifiedCoefficient"]); wageentity.RepairSubsidyRate = Convert.ToDecimal(dtLeft.Rows[i]["RepairSubsidyRate"].ToString() == "" ? 1 : dtLeft.Rows[i]["RepairSubsidyRate"]); wageentity.RepairSubsidy = Convert.ToDecimal(dtLeft.Rows[i]["RepairSubsidy"].ToString() == "" ? 0 : dtLeft.Rows[i]["RepairSubsidy"]); //质量工价 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.QualityWagesEntity qualityWagesEntity = new WCF.DataModels.PAMModule.QualityWagesEntity(); qualityWagesEntity.WagesTypeID = Convert.ToInt32(dtLeft.Rows[i]["WagesTypeID"]); qualityWagesEntity.QualityRate = Convert.ToDecimal(r["QualityRate"].ToString() == "" ? 0 : r["QualityRate"]) / 100; qualityWagesEntity.Balance = Convert.ToDecimal(r["Balance"].ToString() == "" ? 0 : r["Balance"]); qualityWagesEntity.QualityWages = Convert.ToDecimal(r["QualityWages"].ToString() == "" ? 0 : r["QualityWages"]); qualityWagesEntitys.Add(qualityWagesEntity); } // } // } wageentity.qualitywagesentity = qualityWagesEntitys; } wagesentitys.Add(wageentity); } entity.wagesentity = wagesentitys; } int returnValue = (int)DoAsync(new BaseAsyncMethod(() => { return PAMModuleProxy.Service.SavePiecework(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) { PieceworkEntity pieceworkEndit = new PieceworkEntity(); pieceworkEndit.PayPlanName = ""; DataSet dsProductionData = (DataSet)DoAsync(new BaseAsyncMethod(() => { return PAMModuleProxy.Service.GetPieceworkData(pieceworkEndit); })); DataRow[] dr = dsProductionData.Tables[0].Select("PayPlanID=" + this.cmbPayPlan.SelectedValue.ToString()); string errorMessage = string.Format("工资方案【{0}】已属于计件工资策略【{1}】,不能再被选择。", this.cmbPayPlan.Text, dr[0]["PieceTacticsName"].ToString()); // 提示信息 MessageBox.Show(errorMessage, 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.GetPieceworkByID(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.txtPayPlanName.Text = dsResultAccount.Tables[0].Rows[0]["PieceTacticsName"].ToString(); this.txtDamageCoefficient.Text = dsResultAccount.Tables[0].Rows[0]["DamageCoefficient"].ToString(); this.chkDamageFlag.Checked = Convert.ToBoolean(Convert.ToInt32(dsResultAccount.Tables[0].Rows[0]["DamageFlag"])); //this.dkPieceProcedure.ProcedureID = Convert.ToInt32(dsResultAccount.Tables[0].Rows[0]["PieceProcedureID"]); //this.dkPieceProcedure.Text = dsResultAccount.Tables[0].Rows[0]["PieceProcedureName"].ToString(); this.cmbPieceType.SelectedValue = Convert.ToInt32(dsResultAccount.Tables[0].Rows[0]["PieceType"]); this.txtUnqualifiedCoefficient.Text = dsResultAccount.Tables[0].Rows[0]["UnqualifiedCoefficient"].ToString(); this.chkUnqualifiedFlag.Checked = Convert.ToBoolean(Convert.ToInt32(dsResultAccount.Tables[0].Rows[0]["UnqualifiedFlag"])); this.txtPieceCoefficient.Text = dsResultAccount.Tables[0].Rows[0]["PieceCoefficient"].ToString(); this.chkQualifiedFlag.Checked = Convert.ToBoolean(Convert.ToInt32(dsResultAccount.Tables[0].Rows[0]["QualifiedFlag"])); //this.dkQualityBaseProcedure.ProcedureID = Convert.ToInt32(dsResultAccount.Tables[0].Rows[0]["QualityBaseProcedureID"]); //this.dkQualityBaseProcedure.Text = dsResultAccount.Tables[0].Rows[0]["QualityBaseProcedure"].ToString(); this.txtQualifiedCoefficient.Text = dsResultAccount.Tables[0].Rows[0]["QualifiedCoefficient"].ToString(); if (dsResultAccount.Tables[3].Rows.Count > 0) { DataRow[] dr1 = dsResultAccount.Tables[3].Select("ProcedureFlag=1"); string IDS = ""; string TextS = ""; foreach (DataRow r1 in dr1) { TextS += r1["ProcedureName"].ToString() + ","; IDS += r1["ProcedureID"].ToString() + ","; } IDS = IDS.Trim(','); TextS = TextS.Trim(','); if (IDS != "") { this.dkPieceProcedure.Text = TextS; this.dkPieceProcedure.ProcedureIDS = IDS; } IDS = ""; TextS = ""; // 质量工序 dr1 = dsResultAccount.Tables[3].Select("ProcedureFlag=2"); foreach (DataRow r1 in dr1) { 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["StandardWages"] = dsResultAccount.Tables[1].Rows[i]["StandardWages"]; dr["DamageSubsidyRate"] = dsResultAccount.Tables[1].Rows[i]["DamageSubsidyRate"]; dr["DamageSubsidy"] = dsResultAccount.Tables[1].Rows[i]["DamageSubsidy"]; dr["RSuperiorCoefficient"] = dsResultAccount.Tables[1].Rows[i]["RSuperiorCoefficient"]; dr["RQualifiedCoefficient"] = dsResultAccount.Tables[1].Rows[i]["RQualifiedCoefficient"]; dr["RepairSubsidyRate"] = dsResultAccount.Tables[1].Rows[i]["RepairSubsidyRate"]; dr["RepairSubsidy"] = dsResultAccount.Tables[1].Rows[i]["RepairSubsidy"]; dr["RowIndexFlag"] = i; this.DtLeftDataSource.Rows.Add(dr); //this._selectedrow++;//用于过滤边条件 if (dsResultAccount != null && dsResultAccount.Tables[2].Rows.Count > 0) { if (dsResultAccount.Tables[1].Rows[i]["WagesTypeID"].ToString() != "") { 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["Balance"] = rr["Balance"]; dr2["QualityWages"] = rr["QualityWages"]; dr2["RowIndexFlag"] = i; this.DtRightDataSource.Rows.Add(dr2); } } } //else //{ // DataRow dr2 = this.DtRightDataSource.NewRow(); // dr2["QualityRate"] = ""; // dr2["Balance"] = ""; // dr2["QualityWages"] = ""; // dr2["RowIndexFlag"] = i; // this.DtRightDataSource.Rows.Add(dr2); //} } } //this._currentRowIndexFlag = this._selectedrow; } DataView dv = this.DtRightDataSource.DefaultView; dv.RowFilter = "RowIndexFlag=0"; this.dgvQualityWages.DataSource = dv.ToTable();// DtRightDataSource; this.dgvWages.DataSource = DtLeftDataSource; //this.dgvWages.DataSource = DtLeftDataSource; //this.dgvQualityWages.DataSource = DtRightDataSource.Copy(); // this.dgvWages.Rows[DtLeftDataSource.Rows.Count - 1].Selected = true; } } catch (Exception ex) { throw ex; } } /// /// 绑定工种工资方案数据源 /// private void BindJobsData() { try { DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() => { return PAMModuleProxy.Service.GetJobsPayPlanInfo(Convert.ToInt32(this._entityId)); })); if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0) { this.dgvQualityWages.DataSource = dsResultAccount.Tables[0]; } } catch (Exception ex) { throw ex; } } #endregion /// /// 删除行时 /// /// /// private void dgvGoods_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { //try //{ // if (e.Row.Index != -1) // { // if (this.dgvQualityWages.CurrentCell != null) // { // string JobsID = this.dgvQualityWages.Rows[e.Row.Index].Cells["GoodsID"].Value.ToString(); // DataRow[] drSel = dtAllDataRight.Select(string.Format("WagesTypeID={0} and GoodsID={1}", this._currentWagesTypeID, JobsID)); // if (drSel.Length > 0) //存在,需要更把此行删除 // { // drSel[0].Delete(); // } // } // } //} //catch (Exception ex) //{ // throw ex; //} } /// /// 产品工价添加行事件 /// /// /// private void dgvWages_UserAddedRow(object sender, DataGridViewRowEventArgs e) { } /// /// 产品单元格验证事件 /// /// /// private void dgvWages_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { } private void dgvQualityWages_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { } /// /// 绑定计件工序类型 /// private void BindPieceType() { DataTable dtPieceType = new DataTable(); dtPieceType.Columns.Add("PieceTypeID"); dtPieceType.Columns.Add("PieceType"); DataRow dr = dtPieceType.NewRow(); dr["PieceTypeID"] = 0; dr["PieceType"] = "工序计件"; dtPieceType.Rows.Add(dr); dr = dtPieceType.NewRow(); dr["PieceTypeID"] = 1; dr["PieceType"] = "经过工序计件"; dtPieceType.Rows.Add(dr); this.cmbPieceType.DataSource = dtPieceType; this.cmbPieceType.DisplayMember = "PieceType"; this.cmbPieceType.ValueMember = "PieceTypeID"; } private void dgvQualityWages_CurrentCellDirtyStateChanged(object sender, EventArgs e) { } private void F_PAM_0302_Shown(object sender, EventArgs e) { this.dgvQualityWages.IsSetInputColumnsColor = true; this.dgvWages.IsSetInputColumnsColor = true; } private void dgvWages_CellValidated(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex < 0) { return; } DataGridViewRow rowItem = dgvWages.Rows[e.RowIndex]; DataGridViewColumn columnItem = dgvWages.Columns[e.ColumnIndex]; if ("StandardWages" == columnItem.Name) { object StandardWages = rowItem.Cells[e.ColumnIndex].FormattedValue; // 计算补贴 if (StandardWages == null || StandardWages.ToString() == string.Empty) { StandardWages = 0; rowItem.Cells["StandardWages"].Value = 0; } // 2.损坯补贴系数 object DamageSubsidyRate = rowItem.Cells["DamageSubsidyRate"].Value; if (DamageSubsidyRate == null || DamageSubsidyRate.ToString() == string.Empty) { DamageSubsidyRate = 1; rowItem.Cells["DamageSubsidyRate"].Value = 1; } rowItem.Cells["DamageSubsidy"].Value = Convert.ToDecimal(StandardWages.ToString()) * Convert.ToDecimal(DamageSubsidyRate.ToString()); // 3.干补补贴系数 object RepairSubsidyRate = rowItem.Cells["RepairSubsidyRate"].Value; if (RepairSubsidyRate == null || RepairSubsidyRate.ToString() == string.Empty) { RepairSubsidyRate = 1; rowItem.Cells["RepairSubsidyRate"].Value = 1; } rowItem.Cells["RepairSubsidy"].Value = Convert.ToDecimal(StandardWages.ToString()) * Convert.ToDecimal(RepairSubsidyRate.ToString()); //this.dgvWages.Rows[this.dgvWages.CurrentCell.RowIndex].Cells["StandardWages"].Value = StandardWages; this._currentStandardWages = Convert.ToDecimal(StandardWages); // 计算补贴 end //更改标准价格的时候,遍历子表修改质量工价 // 1.获取当前标识行信息 object objRowIndexFlag = rowItem.Cells["RowIndexFlag"].Value; if (objRowIndexFlag != null || objRowIndexFlag.ToString() != "") { DataRow[] dr = this.DtRightDataSource.Select("RowIndexFlag=" + objRowIndexFlag); if (dr.Length > 0) //表示有质量工价 { int rowIndex = 0; foreach (DataRow r in dr) { r["QualityWages"] = Convert.ToDecimal(StandardWages) + (r["Balance"].ToString() == "" ? 0 : Convert.ToDecimal(r["Balance"])); this.dgvQualityWages.Rows[rowIndex].Cells["QualityWages"].Value = r["QualityWages"]; rowIndex++; } this.DtRightDataSource.AcceptChanges(); } } } if ("DamageSubsidyRate" == columnItem.Name) { object DamageSubsidyRate = rowItem.Cells[e.ColumnIndex].FormattedValue; // 损坯补贴系数 if (DamageSubsidyRate == null || DamageSubsidyRate.ToString() == string.Empty) { DamageSubsidyRate = 1; rowItem.Cells["DamageSubsidyRate"].Value = 1; } // 2.标准工价 object StandardWages = rowItem.Cells["StandardWages"].Value; if (StandardWages == null || StandardWages.ToString() == string.Empty) { StandardWages = 0; rowItem.Cells["StandardWages"].Value = 0; } rowItem.Cells["DamageSubsidy"].Value = Convert.ToDecimal(StandardWages.ToString()) * Convert.ToDecimal(DamageSubsidyRate.ToString()); // 计算补贴 end //rowItem.Cells["DamageSubsidyRate"].Value = DamageSubsidyRate; } if ("RepairSubsidyRate" == columnItem.Name) { object RepairSubsidyRate = rowItem.Cells[e.ColumnIndex].FormattedValue; // 计算补贴 if (RepairSubsidyRate == null || RepairSubsidyRate.ToString() == string.Empty) { RepairSubsidyRate = 1; rowItem.Cells["RepairSubsidyRate"].Value = 1; } // 2.标准工价 object StandardWages = rowItem.Cells["StandardWages"].Value; if (StandardWages == null || StandardWages.ToString() == string.Empty) { StandardWages = 0; rowItem.Cells["StandardWages"].Value = 0; } rowItem.Cells["RepairSubsidy"].Value = Convert.ToDecimal(StandardWages.ToString()) * Convert.ToDecimal(RepairSubsidyRate.ToString()); // 计算补贴 end //rowItem.Cells["RepairSubsidyRate"].Value = RepairSubsidyRate; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } private void dgvQualityWages_CellValidated(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex < 0) { return; } DataGridViewRow rowItem = dgvQualityWages.Rows[e.RowIndex]; DataGridViewColumn columnItem = dgvQualityWages.Columns[e.ColumnIndex]; if ((e.ColumnIndex == 0 || e.ColumnIndex == 1) && e.RowIndex != -Constant.INT_IS_ONE) { rowItem.Cells["RowIndexFlag1"].Value = this._currentRowIndexFlag; } if ("Balance" == columnItem.Name) { object Balance = rowItem.Cells[columnItem.Name].FormattedValue; if (Balance == null || Balance.ToString() == string.Empty) { Balance = 0; rowItem.Cells["Balance"].Value = 0; } rowItem.Cells["QualityWages"].Value = this._currentStandardWages + Convert.ToDecimal(Balance); } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex); } } } }