/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_PAM_0203.cs
* 2.功能描述:新建/编辑产品工价分类
* 编辑履历:
* 作者 日期 版本 修改内容
* 王鑫 2015/08/18 1.00 新建
*******************************************************************************/
using System;
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.Proxys;
using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
namespace Dongke.IBOSS.PRD.Client.PAMModule
{
///
/// 产品工价分类
///
public partial class F_PAM_0203 : 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 dtAllData = null;
#endregion
#region 构造函数
///
/// 窗体构造
///
/// 窗体打开模式
/// 操作实体ID
public F_PAM_0203(Constant.FormMode formType, int entityId)
{
InitializeComponent();
this._formType = formType;
this._entityId = entityId;
// 窗体显示的Title
if (this._formType == Constant.FormMode.Add)
{
this.Text = FormTitles.F_PAM_0203_ADD;
}
else if (this._formType == Constant.FormMode.Edit)
{
this.Text = FormTitles.F_PAM_0203_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.dgvPayPlan.AutoGenerateColumns = false;
this.dgvGoods.AutoGenerateColumns = false;
//如果是修改,要绑定选中的信息
if (this._formType == Constant.FormMode.Edit)
{
BindJobsData();//编辑工种数据源
BindData();//绑定工资工种数据源
}
//如果是新建,选项默认值设定
else if (this._formType == Constant.FormMode.Add)
{
//绑定全部的工资工种列表,用于过滤筛选
DataSet dsProductionData = (DataSet)DoAsync(new BaseAsyncMethod(() =>
{
return PAMModuleProxy.Service.GetGoodsWagesType("", "");
}));
BindData();//绑定工价分类数据源
if (dsProductionData != null && dsProductionData.Tables[0].Rows.Count > 0)
{
this.dgvGoods.DataSource = dsProductionData.Tables[0];//新建时默认数据源
}
else
{
dt = new DataTable();
dt.Columns.Add("GoodsID");
dt.Columns.Add("GoodsCode");
dt.Columns.Add("GoodsName");
dt.Columns.Add("WagesTypeID");
this.dgvGoods.DataSource = dt;//新建时默认数据源
}
dtAllData = this.dgvGoods.DataSource as DataTable;
}
}
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.dgvGoods.Rows.Count <= 1)
{
return;
}
DataGridViewRow rowItem = this.dgvGoods.Rows[e.RowIndex];
DataGridViewColumn columnItem = this.dgvGoods.Columns[e.ColumnIndex];
// 用编号获取产品信息
if ("GoodsCode".Equals(columnItem.Name))
{
string GoodsID = "";
if (this.dgvGoods.Rows[e.RowIndex].Cells["GoodsID"].Value != null)
{
GoodsID = this.dgvGoods.Rows[e.RowIndex].Cells["GoodsID"].Value.ToString();
}
DataTable dtDataSource = FormUtility.BindGoodsRowDataSource(this.dgvGoods,
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.dgvGoods.Rows[row].Cells["WagesTypeID1"].Value = this._currentWagesTypeID;
if (dtAllData != null && GoodsID != "")
{
DataRow[] drSel = dtAllData.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.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++;
// }
}
else
{
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.dgvGoods.Rows[e.RowIndex].Selected = true;
}
// 设置可输入单元格的颜色
this.dgvGoods.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.dgvGoods.Rows.Count <= 1 || !_ShowFlag)
{
return;
}
DataGridViewColumn columnItem = this.dgvGoods.Columns[e.ColumnIndex];
if ("GoodsCode".Equals(columnItem.Name))
{
_ShowFlag = false;
_GoodsCodeValue = this.dgvGoods.Rows[e.RowIndex].Cells[columnItem.Name].Value + "";
}
_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.dgvPayPlan.CurrentCell != null)
{
this._currentWagesTypeID = Convert.ToInt32(this.dgvPayPlan.Rows[this.dgvPayPlan.CurrentCell.RowIndex].Cells["WagesTypeID"].Value);
//DataTable dtJobs = this.dgvGoods.DataSource as DataTable;
DataTable dtJobs = this.dtAllData;
if (dtJobs != null)
{
DataView dv = dtJobs.DefaultView;
dv.RowFilter = "WagesTypeID=" + this._currentWagesTypeID;
this.dgvGoods.DataSource = dv.ToTable();
}
//if (dtJobs != null && dtJobs.Rows.Count > 0)
//{
// DataRow[] dr = dtJobs.Select("WagesTypeID=" + this._currentWagesTypeID);
// if (dr.Length > 0)
// {
// this.dgvGoods.DataSource = dr.CopyToDataTable();
// }
//}
//else
//{
// if (dtJobs != null)
// {
// DataView dv = dtJobs.DefaultView;
// dv.RowFilter = "WagesTypeID=" + this._currentWagesTypeID;
// this.dgvGoods.DataSource = dv.ToTable();
// }
//}
}
}
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
{
DataTable dt = this.dtAllData;// this.dgvGoods.DataSource as DataTable;
if (dt == null)
{
return;
}
dt.TableName = "Table1";
int returnValue = (int)DoAsync(new BaseAsyncMethod(() =>
{
return PAMModuleProxy.Service.SaveGoodsWagesTypeData(Convert.ToBoolean(this._entityId), dt);
}));
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 == -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.GetAllWagesType();
}));
if (dsResultAccount != null && dsResultAccount.Tables[0].Rows.Count > 0)
{
if (this._formType == Constant.FormMode.Edit)
{
DataRow[] dr = dsResultAccount.Tables[0].Select("WagesTypeID=" + this._entityId);
if (dr.Length > 0)
{
this.dgvPayPlan.DataSource = dr.CopyToDataTable();
}
}
else
{
DataView dv = dsResultAccount.Tables[0].DefaultView;
dv.RowFilter = "valueflag=1";
this.dgvPayPlan.DataSource = dv.ToTable();
}
}
}
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.dgvGoods.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.dgvGoods.CurrentCell != null)
{
string JobsID = this.dgvGoods.Rows[e.Row.Index].Cells["GoodsID"].Value.ToString();
DataRow[] drSel = dtAllData.Select(string.Format("WagesTypeID={0} and GoodsID={1}", this._currentWagesTypeID, JobsID));
if (drSel.Length > 0) //存在,需要更把此行删除
{
drSel[0].Delete();
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}