| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_TAT_0202.cs
- * 2.功能描述:工价策略明细
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 庄天威 2014/11/18 1.00 新建
- *******************************************************************************/
- using System;
- using System.Data;
- using System.Drawing;
- 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
- {
- /// <summary>
- /// 工价策略明细
- /// </summary>
- public partial class F_TAT_0202 : FormBase
- {
- #region 成员变量
- // 窗体模式ID
- private Constant.FormMode _formType;
- // 操作实体ID
- private int? _entityId;
- // 操作实体
- private WagesEntity _wagesEntity = new WagesEntity();
- // 选择窗体弹出标识
- private bool _showFlag = true;
- // 数据源
- private DataSet _dsSourse;
- // 窗体加载完毕标识
- private bool _pageLoadOK = false;
- #endregion
- #region 构造函数
- /// <summary>
- /// 窗体构造
- /// </summary>
- /// <param name="formType">窗体开启模式</param>
- /// <param name="entityId">操作实体ID</param>
- public F_TAT_0202(Constant.FormMode formType, int entityId)
- {
- InitializeComponent();
- this._formType = formType;
- this._entityId = entityId;
- this.tsbtnCreateJobs.Visible = false;
- // 窗口标题
- this.Text = FormTitles.F_TAT_0202;
- // 按钮
- this.btnSubmit.Text = ButtonText.BTN_SAVE;
- this.btnClose.Text = ButtonText.BTN_CANCEL;
- }
- #endregion
- #region 事件处理
- /// <summary>
- /// 窗体加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_TAT_0202_Load(object sender, EventArgs e)
- {
- try
- {
- this.cbCeremonial.Checked = true;
- this.BindJobsPriceType();
- //无论如何先绑定工种,即使没有信息,也需要Table的结构
- this.dgvJobs.AutoGenerateColumns = false;
- this.BindJobs();
- //如果是编辑或审核模式,还要绑定主体信息
- if(this._formType == Constant.FormMode.Edit || this._formType == Constant.FormMode.Display)
- {
- this.BindPage();
- //并将所有已存在的信息的类别列解除只读
- foreach(DataGridViewRow gvrFor in this.dgvJobs.Rows)
- {
- if(gvrFor.IsNewRow)
- {
- break;
- }
- gvrFor.Cells["PriceType"].ReadOnly = false;
- int TypeValue = Convert.ToInt32(gvrFor.Cells["PriceType"].Value);
- if (TypeValue == 3 || TypeValue == 4)
- {
- gvrFor.Cells["OneCount"].ReadOnly = false;
- gvrFor.Cells["OnePrice"].ReadOnly = false;
- //根据计车及计重量,设置单位单元格的小数精度
- Point dnInt = new Point(6, 0);
- Point dnDob = new Point(6, 6);
- if (TypeValue == 3)
- {
- ((C_DGV_Cell_Digital)gvrFor.Cells["OneCount"]).Number = dnInt;
- }
- else
- {
- ((C_DGV_Cell_Digital)gvrFor.Cells["OneCount"]).Number = dnDob;
- }
- }
- }
- this.dgvJobs.IsSetInputColumnsColor = true;
- this.tsbtnOther.Visible = true;
- }
- else
- {
- //新建模式下是不可以进入明细的
- if (this._formType == Constant.FormMode.Add)
- {
- this.tsbtnOther.Visible = false;
- }
- else //复制模式不可编辑明细
- {
- this.dgvJobs.ReadOnly = true;
- this.dgvJobs.IsSetInputColumnsColor = false;
- this.dgvJobs.AllowUserToAddRows = false;
- }
- }
- //页面加载完毕
- this._pageLoadOK = true;
- //如果是审核及观看模式
- if (this._formType == Constant.FormMode.Display)
- {
- this.btnPass.Visible = true;
- this.btnReturn.Visible = true;
- //列表设置为只读
- this.dgvJobs.ReadOnly = true;
- this.dgvJobs.IsSetInputColumnsColor = false;
- this.dgvJobs.AllowUserToAddRows = false;
- this.dgvJobs.AllowUserToDeleteRows = false;
- //控件除关闭外全部不可用
- this.txtWagesName.Enabled = false;
- this.txtRemarks.Enabled = false;
- this.dtpStartTime.Enabled = false;
- this.cbCeremonial.Enabled = false;
- this.cbTrial.Enabled = false;
- this.tsbtnCreateJobs.Enabled = false;
- this.btnSubmit.Enabled = false;
- }
- }
- catch(Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 批量生成工种
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnCreateJobs_Click(object sender, EventArgs e)
- {
- try
- {
- //需重新加载
- this._pageLoadOK = false;
- //这句话,因为新建的时候,莫名其妙会多出一个数据源不存在的空行,这样设定就不会出现了。
- this.dgvJobs.AllowUserToAddRows = false;
- //获取全部工种
- DataSet dsJobs = (DataSet)DoAsync(() =>
- {
- return SystemModuleProxy.Service.GetJobsData(1);
- });
- //如果获取到了工种
- if (dsJobs != null && dsJobs.Tables.Count != 0)
- {
- //循环生成工种信息并加入到数据源中
- foreach (DataRow drFor in dsJobs.Tables[0].Rows)
- {
- //首先查看该工种在现有数据源中是否存在
- int JobIsHave = 0;
- foreach (DataRow drSourse in this._dsSourse.Tables[0].Rows)
- {
- if (drSourse.RowState == DataRowState.Deleted)
- {
- continue;
- }
- int drForJobsId = Convert.ToInt32(drFor["JobsId"]);
- int drSourseJobsId = Convert.ToInt32(drSourse["JobsId"]);
- if (drForJobsId == drSourseJobsId)
- {
- JobIsHave++;
- break;
- }
- }
- //如果不存在才重新生成
- if (JobIsHave == 0 && drFor["JobsId"] != DBNull.Value)
- {
- DataRow drJobs = _dsSourse.Tables[0].NewRow();
- drJobs["JobsId"] = drFor["JobsId"];
- drJobs["JobsCode"] = drFor["JobsCode"];
- drJobs["JobsName"] = drFor["JobsName"];
- this._dsSourse.Tables[0].Rows.Add(drJobs);
- }
- }
- //绑定
- this.dgvJobs.AutoGenerateColumns = false;
- this.dgvJobs.DataSource = this._dsSourse.Tables[0];
- }
- //加载完毕
- this._pageLoadOK = true;
- this.dgvJobs.AllowUserToAddRows = true;
- this.dgvJobs.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 编辑工种对应明细
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnOther_Click(object sender, EventArgs e)
- {
- //获取当前行,如果不为空以及非新建行的话,就可以进入明细页面
- DataGridViewRow gvrNow = this.dgvJobs.CurrentRow;
- if(gvrNow != null && !gvrNow.IsNewRow)
- {
- //获取需要添加明细的信息ID
- int JobsId = Convert.ToInt32(gvrNow.Cells["JobsId"].Value);
- string JobsName = gvrNow.Cells["JobsName"].Value.ToString();
- string JobsCode = gvrNow.Cells["JobsCode"].Value.ToString();
- //以编辑模式打开信息窗体
- F_TAT_0203 frmTAT0203
- = new F_TAT_0203(this._formType, Convert.ToInt32(this._wagesEntity.WagesID), JobsId, JobsName, JobsCode);
- DialogResult dialogResult = frmTAT0203.ShowDialog();
- }
- else
- {
- //不可为空或选择新建行
- }
- }
- /// <summary>
- /// 自适应列宽
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnAdaptive_Click(object sender, EventArgs e)
- {
- this.dgvJobs.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
- }
- /// <summary>
- /// 提交操作
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSubmit_Click(object sender, EventArgs e)
- {
- try
- {
- if (!ValidationInput())
- {
- return;
- }
- //获取页面值绑定属性
- this.BindEntity();
- //提交操作
- ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() =>
- {
- return this.EntityToServer();
- });
- 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 dgvJobs_CellValueChanged(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- //变更后重新加载
- this._pageLoadOK = false;
- if (this.dgvJobs.Rows.Count <= 1 || !this._showFlag)
- {
- return;
- }
- DataGridViewRow rowItem = this.dgvJobs.Rows[e.RowIndex];
- DataGridViewColumn columnItem = this.dgvJobs.Columns[e.ColumnIndex];
- if (columnItem.Name == "JobsCode")
- {
- //打开多选页面进行值绑定
- this._showFlag = false;
- FormUtility.BindJobsRowDataSource(this.dgvJobs,
- e.RowIndex, columnItem.Name, string.Empty);
- this._showFlag = true;
- //为选中项设定默认值
- foreach (DataGridViewRow gvrFor in this.dgvJobs.Rows)
- {
- if (!gvrFor.IsNewRow && gvrFor.Cells["PriceType"].Value == DBNull.Value)
- {
- gvrFor.Cells["PriceType"].ReadOnly = false;
- gvrFor.Cells["PriceType"].Value = 1;
- }
- //如果是新行,不可录入工种以外的项
- if (gvrFor.IsNewRow)
- {
- gvrFor.Cells["PriceType"].ReadOnly = true;
- gvrFor.Cells["OneCount"].ReadOnly = true;
- gvrFor.Cells["OnePrice"].ReadOnly = true;
- }
- }
- }
- else if (columnItem.Name == "PriceType")
- {
- rowItem.Cells["OneCount"].Value = null;
- rowItem.Cells["OnePrice"].Value = null;
- int TypeValue = Convert.ToInt32(rowItem.Cells["PriceType"].Value);
- if (TypeValue != 3 && TypeValue != 4)
- {
- rowItem.Cells["OneCount"].ReadOnly = true;
- rowItem.Cells["OnePrice"].ReadOnly = true;
- }
- else
- {
- rowItem.Cells["OneCount"].ReadOnly = false;
- rowItem.Cells["OnePrice"].ReadOnly = false;
- //根据计车及计重量,设置单位单元格的小数精度
- Point dnInt = new Point(6, 0);
- Point dnDob = new Point(6, 6);
- if (TypeValue == 3)
- {
- ((C_DGV_Cell_Digital)rowItem.Cells["OneCount"]).Number = dnInt;
- }
- else
- {
- ((C_DGV_Cell_Digital)rowItem.Cells["OneCount"]).Number = dnDob;
- }
- }
- }
- //加载OK
- this._pageLoadOK = true;
- // 设置可输入单元格的颜色
- this.dgvJobs.IsSetInputColumnsColor = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 关闭窗体
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 工种选择改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvJobs_SelectionChanged(object sender, EventArgs e)
- {
- try
- {
- if(!this._pageLoadOK)
- {
- return;
- }
- if (this.dgvJobs.SelectedRows.Count != 0)
- {
- DataGridViewRow gvrFor = this.dgvJobs.SelectedRows[0];
- if (gvrFor.IsNewRow)
- {
- this.tsbtnOther.Enabled = false;
- return;
- }
- int TypeValue = Convert.ToInt32(gvrFor.Cells["PriceType"].Value);
- //按车或按重量计,不存在明细
- if (TypeValue == 3 || TypeValue == 4)
- {
- this.tsbtnOther.Enabled = false;
- }
- else
- {
- this.tsbtnOther.Enabled = true;
- }
- }
- }
- catch(Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 通过审核
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnPass_Click(object sender, EventArgs e)
- {
- //进行审核操作
- this._wagesEntity.AuditStatus = Convert.ToInt32(Constant.AuditStatus.Agree);
- ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() =>
- {
- return EntityToServer();
- });
- //服务实体共通处理
- ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
- if (srEntity.Status == Constant.ServiceResultStatus.Success)
- {
- this.DialogResult = DialogResult.OK;
- }
- }
- /// <summary>
- /// 驳回审核
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnReturn_Click(object sender, EventArgs e)
- {
- //进行审核操作
- this._wagesEntity.AuditStatus = Convert.ToInt32(Constant.AuditStatus.Disagree);
- ServiceResultEntity srEntity = (ServiceResultEntity)DoAsync(() =>
- {
- return EntityToServer();
- });
- //服务实体共通处理
- ServiceResultEntityManager.HandleServiceResultEntity(srEntity, this.Text);
- if (srEntity.Status == Constant.ServiceResultStatus.Success)
- {
- this.DialogResult = DialogResult.OK;
- }
- }
- #endregion
- #region 私有方法/函数
- /// <summary>
- /// 绑定计件方式
- /// </summary>
- private void BindJobsPriceType()
- {
- try
- {
- DataSet dsPriceType = SystemModuleProxy.Service.GetJobsPriceType();
- if(dsPriceType != null && dsPriceType.Tables.Count != 0)
- {
- this.PriceType.DisplayMember = "JobsPriceTypeName";
- this.PriceType.ValueMember = "JobsPriceTypeID";
- this.PriceType.DataSource = dsPriceType.Tables[0];
- }
- }
- catch(Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 绑定需要操作的实体信息
- /// </summary>
- private void BindPage()
- {
- try
- {
- if (this._entityId != 0 && this._entityId != null)
- {
- this._wagesEntity.WagesID = this._entityId;
- //获取工价策略
- ServiceResultEntity srEntity
- = TATModuleProxy.Service.GetWages(_wagesEntity);
- //如果取出了对应的数据
- if (srEntity.Data != null && srEntity.Data.Tables.Count != 0
- && srEntity.Data.Tables[0].Rows.Count != 0)
- {
- //为实体及页面相关赋值
- DataSet dsEntityData = (DataSet)srEntity.Data;
- DataRow drEntityRow = dsEntityData.Tables[0].Rows[0];
- this.txtWagesName.Text = drEntityRow["WagesName"].ToString();
- int SalaryType = Convert.ToInt32(drEntityRow["SalaryType"]);
- this._wagesEntity.SalaryType = SalaryType;
- if (SalaryType == 1)
- {
- this.cbCeremonial.Checked = true;
- }
- else
- {
- this.cbTrial.Checked = true;
- }
- this.txtRemarks.Text = drEntityRow["Remarks"].ToString();
- this.dtpStartTime.Text = drEntityRow["BeginAccountMonth"].ToString();
- this._wagesEntity.BeginAccountMonth = Convert.ToDateTime(drEntityRow["BeginAccountMonth"].ToString());
- this._wagesEntity.OPTimeStamp = Convert.ToDateTime(drEntityRow["OPTimeStamp"]);
- }
- }
- }
- catch(Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 绑定对应工种明细
- /// </summary>
- private void BindJobs()
- {
- try
- {
- //获取对应工种明细
- ServiceResultEntity srEntityDetail
- = TATModuleProxy.Service.GetWagesDetailById(Convert.ToInt32(this._entityId));
- if (srEntityDetail.Data != null && srEntityDetail.Data.Tables.Count != 0)
- {
- this._dsSourse = srEntityDetail.Data;
- this.dgvJobs.DataSource = srEntityDetail.Data.Tables[0];
- this.dgvJobs.IsSetInputColumnsColor = true;
- }
- }
- catch(Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 与服务交互操作
- /// </summary>
- /// <returns></returns>
- private ServiceResultEntity EntityToServer()
- {
- if (this._formType == Constant.FormMode.Add)
- {
- return TATModuleProxy.Service.AddWages(this._wagesEntity, _dsSourse);
- }
- else if (this._formType == Constant.FormMode.Edit)
- {
- return TATModuleProxy.Service.EditWages(this._wagesEntity, _dsSourse);
- }
- else if (_formType == Constant.FormMode.CopyAndAdd)
- {
- this._wagesEntity.CopyId = Convert.ToInt32(this._entityId);
- return TATModuleProxy.Service.AddWages(this._wagesEntity, _dsSourse);
- }
- else if (_formType == Constant.FormMode.Display)
- {
- return TATModuleProxy.Service.AuditWages(this._wagesEntity);
- }
- return null;
- }
- /// <summary>
- /// 为实体绑定页面属性
- /// </summary>
- private void BindEntity()
- {
- this._wagesEntity.WagesName = this.txtWagesName.Text.Trim();
- this._wagesEntity.BeginAccountMonth = this.dtpStartTime.Value.Date;
- if (this.cbCeremonial.Checked)
- {
- this._wagesEntity.SalaryType = 1;
- }
- else
- {
- this._wagesEntity.SalaryType = 0;
- }
- this._wagesEntity.Remarks = this.txtRemarks.Text;
- this._wagesEntity.AuditStatus = 0;
- }
- /// <summary>
- /// 验证必填项
- /// </summary>
- /// <returns>是否通过</returns>
- private bool ValidationInput()
- {
- if (string.IsNullOrWhiteSpace(this.txtWagesName.Text))
- {
- this.txtWagesName.Focus();
- return false;
- }
- //循环对应工种列表,如果有非计件类别但没有填写单位数量和单位价格,
- //或者选择记车的类别后,单位价格非整数的,都不可通过验证
- foreach (DataGridViewRow gvrFor in this.dgvJobs.Rows)
- {
- if (gvrFor.IsNewRow)
- {
- break;
- }
- int TypeValue = Convert.ToInt32(gvrFor.Cells["PriceType"].Value);
- if (TypeValue == 3 || TypeValue == 4)
- {
- if (gvrFor.Cells["OneCount"].Value == DBNull.Value ||
- gvrFor.Cells["OnePrice"].Value == DBNull.Value)
- {
- this.dgvJobs.Rows[gvrFor.Index].Selected = true;
- return false;
- }
- }
- }
- return true;
- }
- #endregion
- }
- }
|