/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_TAT_0203.cs
* 2.功能描述:工价策略产品关联
* 编辑履历:
* 作者 日期 版本 修改内容
* 庄天威 2014/11/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.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;
using Dongke.IBOSS.PRD.WCF.Proxys.TATModuleService;
namespace Dongke.IBOSS.PRD.Client.TATModule
{
///
/// 工价策略产品关联
///
public partial class F_TAT_0203 : FormBase
{
#region 成员变量
// 窗体模式ID
private Constant.FormMode _formType;
// 主体信息ID
private int? _WagesId;
// 主体工种ID
private int? _JobsId;
// 数据源
private DataSet _dsSourse;
// 产品数据源
private DataTable _dtGoodsSourse;
#endregion
#region 构造函数
///
/// 构造函数
///
/// 窗体开启模式
/// 策略ID
/// 工种ID
/// 工种名称
/// 工种编码
public F_TAT_0203(Constant.FormMode formType,int WagesId,
int JobsId,string JobsName,string JobsCode)
{
InitializeComponent();
this._WagesId = WagesId;
this._JobsId = JobsId;
this._formType = formType;
this.txtJobsName.Text = JobsName;
this.txtJobsCode.Text = JobsCode;
// 窗口标题
this.Text = FormTitles.F_TAT_0203;
// 按钮
this.btnSubmit.Text = ButtonText.BTN_SAVE;
this.btnClose.Text = ButtonText.BTN_CANCEL;
}
#endregion
#region 事件处理
///
/// 窗体加载
///
///
///
private void F_TAT_0203_Load(object sender, EventArgs e)
{
try
{
//绑定列表信息
this.BindPage();
//获取全部产品信息
this.GetGoods();
if(this._formType == Constant.FormMode.Display || this._formType == Constant.FormMode.CopyAndAdd)
{
this.dgvGoods.ReadOnly = true;
this.dgvGoods.IsSetInputColumnsColor = false;
this.dgvGoods.AllowUserToDeleteRows = false;
this.tsbtnCreateGoods.Enabled = false;
this.btnSubmit.Visible = false;
}
}
catch(Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 创建产品
///
///
///
private void tsbtnCreateGoods_Click(object sender, EventArgs e)
{
try
{
//遍历产品明细添加该工种的所有明细信息
foreach (DataRow drFor in this._dtGoodsSourse.Rows)
{
//首先查看该产品是否已存在
int GoodsIsHave = 0;
foreach (DataGridViewRow gvrFor in this.dgvGoods.Rows)
{
if (Convert.ToInt32(gvrFor.Cells["GoodsID"].Value)
== Convert.ToInt32(drFor["GoodsID"]))
{
GoodsIsHave++;
break;
}
}
//如果不存在才进行添加
if (GoodsIsHave == 0)
{
//向最终数据源添加扣罚明细信息
DataRow drDetail = this._dsSourse.Tables[0].NewRow();
drDetail["GoodsID"] = drFor["GoodsId"];
drDetail["GoodsCode"] = drFor["GoodsCode"];
drDetail["GoodsName"] = drFor["GoodsName"];
drDetail["PieceNum"] = 1;
drDetail["Wages"] = 0;
drDetail["PublicWages"] = 0;
this._dsSourse.Tables[0].Rows.Add(drDetail);
}
}
this.dgvGoods.IsSetInputColumnsColor = true;
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 自适应列宽
///
///
///
private void tsbtnAdaptive_Click(object sender, EventArgs e)
{
this.dgvGoods.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
}
///
/// 提交
///
///
///
private void btnSubmit_Click(object sender, EventArgs e)
{
try
{
//提交操作
ServiceResultEntity srEntity =
(ServiceResultEntity)DoAsync(() =>
{
return TATModuleProxy.Service.EditWagesGoodsDetail(
Convert.ToInt32(this._WagesId), Convert.ToInt32(this._JobsId), this._dsSourse);
});
ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
if (srEntity.Status == Constant.ServiceResultStatus.Success)
{
this.DialogResult = DialogResult.OK;
}
}
catch(Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 关闭窗体
///
///
///
private void btnClose_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
#endregion
#region 私有方法和函数
///
/// 绑定列表
///
private void BindPage()
{
try
{
//绑定某工种对应的产品信息
if (this._WagesId != null && this._JobsId != null)
{
ServiceResultEntity srEntity =
TATModuleProxy.Service.GetWagesGoodsDetail(Convert.ToInt32(this._WagesId), Convert.ToInt32(this._JobsId));
if(srEntity != null && srEntity.Data != null && srEntity.Data.Tables.Count != 0)
{
this.dgvGoods.AutoGenerateColumns = false;
this.dgvGoods.DataSource = srEntity.Data.Tables[0];
this.dgvGoods.IsSetInputColumnsColor = true;
this._dsSourse = srEntity.Data;
}
}
}
catch(Exception ex)
{
throw ex;
}
}
///
/// 获取全部产品信息
///
private void GetGoods()
{
try
{
GoodsEntity goods = new GoodsEntity();
goods.ValueFlag = 1;
DataSet dsGoods = SystemModuleProxy.Service.SerachGoods(goods);
if (dsGoods != null && dsGoods.Tables.Count != 0)
{
this._dtGoodsSourse = dsGoods.Tables[0];
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}