| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_HR_0902.cs
- * 2.功能描述:员工报餐新增/编辑
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 张国印 2014/10/6 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.Library;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.Client.Controls.FormCommon;
- using Dongke.IBOSS.PRD.Client.DataModels;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.WCF.Proxys.HRModuleService;
- namespace Dongke.IBOSS.PRD.Client.HRModule
- {
- /// <summary>
- /// 员工报餐新增/编辑
- /// </summary>
- public partial class F_HR_0902 : FormBase
- {
- #region 成员变量
- // 记录备注
- private string _isMeal;
- // 记录备注
- private string _remarks;
- //格式刷是否开启
- private bool _isBrushIsOpen = false;
- // 当前列序号
- private int _columnIndex = -1;
- // 窗体状态的枚举 新建/编辑
- private Constant.FormMode _editStatus;
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="editStatus">编辑状态</param>
- /// <param name="pStaffId">员工ID</param>
- /// <param name="pSealDate">报餐日期</param>
- public F_HR_0902(Constant.FormMode editStatus)
- {
- InitializeComponent();
- this._editStatus = editStatus;
- this.dkStaffName.WhereCondition = "(StaffStatus = 1 Or StaffStatus = 2) AND ValueFlag = 1";
- this.SetFromTitleInfo();
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_HR_0902_Load(object sender, EventArgs e)
- {
- try
- {
- FormPermissionManager.FormPermissionControl(this.Name, this,
- LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData, LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
- if (this._editStatus == Constant.FormMode.LimitEdit)
- {
- this.dgvStaffDailyMeal.Columns["OrderBreakfast"].ReadOnly = true;
- this.dgvStaffDailyMeal.Columns["OrderLunch"].ReadOnly = true;
- this.dgvStaffDailyMeal.Columns["OrderDinner"].ReadOnly = true;
- this.dgvStaffDailyMeal.Columns["Remarks"].ReadOnly = true;
- }
- this.dgvStaffDailyMeal.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
- this.dkStaffName.WhereCondition = "StaffStatus in(1,2) and ValueFlag=1";//筛选适用的试用与正式员工
- }
- 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 dgvStaffDailyMeal_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)
- {
- try
- {
- if (this.dgvStaffDailyMeal.CurrentCell == null
- || this.dgvStaffDailyMeal.Rows.Count < Constant.INT_IS_ONE)
- {
- return;
- }
- DataGridViewCell currentCell = this.dgvStaffDailyMeal.CurrentCell;
- if (_columnIndex != -Constant.INT_IS_ONE && _columnIndex != currentCell.ColumnIndex)
- {
- this.SetBrushNotEnable();
- }
- List<string> checkColList = GetGirdViewCheckColName();
- if (checkColList.Contains(this.dgvStaffDailyMeal.Columns[currentCell.ColumnIndex].Name))
- {
- if (this._isBrushIsOpen)
- {
- this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].Value = this._isMeal;
- }
- this._columnIndex = currentCell.ColumnIndex;
- }
- else if ("Remarks".Equals(this.dgvStaffDailyMeal.Columns[currentCell.ColumnIndex].Name))
- {
- if (this._isBrushIsOpen && !this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].ReadOnly)
- {
- this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].Value = this._remarks;
- }
- this._columnIndex = currentCell.ColumnIndex;
- }
- }
- 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 tsbtnImport_Click(object sender, EventArgs e)
- {
- try
- {
- this.oFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
- this.oFileDialog.FileName = string.Empty;
- if (this.oFileDialog.ShowDialog() == DialogResult.OK)
- {
- DataTable dtStaffMeal = ExcelLayer.GetDataTable(this.oFileDialog.FileName, 1);
- #region 对数据进行验证
- if (dtStaffMeal == null && dtStaffMeal.Rows.Count <= Constant.INT_IS_ZERO)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "数据表中没有数据!"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- if (!CheckExcelImportData(dtStaffMeal.Columns))
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "导入模板错误!"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- #endregion
- DataSet dsResultStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- if (this._editStatus == Constant.FormMode.Edit)
- {
- return HRModuleProxy.Service.GetStaffDailyMealInfoForExcel(dtStaffMeal, WCFConstant.FormMode.Edit);
- }
- return HRModuleProxy.Service.GetStaffDailyMealInfoForExcel(dtStaffMeal, WCFConstant.FormMode.MealEdit);
- }));
- if (dsResultStaff != null)
- {
- base.DataSource = dsResultStaff;
- if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
- {
- this.dgvStaffDailyMeal.DataSource = this.DataSource.Tables[0];
- if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
- {
- // 提示未查找到数据
- MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- }
- }
- 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 tsbtnDataBrush_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.dgvStaffDailyMeal.CurrentCell == null || this.dgvStaffDailyMeal.Rows.Count < Constant.INT_IS_ONE)
- {
- return;
- }
- DataGridViewCell currentCell = this.dgvStaffDailyMeal.CurrentCell;
- List<string> checkColList = GetGirdViewCheckColName();
- if (checkColList.Contains(this.dgvStaffDailyMeal.Columns[currentCell.ColumnIndex].Name))
- {
- if (!_isBrushIsOpen)
- {
- this.tsbtnBrush.Checked = true;
- this._isBrushIsOpen = true;
- this.dgvStaffDailyMeal.Cursor = Cursors.Hand;
- this.dgvStaffDailyMeal.MultiSelect = true;
- this._isMeal = this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].Value + "";
- }
- else
- {
- this.dgvStaffDailyMeal.Cursor = Cursors.Default;
- this.dgvStaffDailyMeal.MultiSelect = false;
- this.tsbtnBrush.Checked = false;
- this._isBrushIsOpen = false;
- }
- }
- else if ("Remarks".Equals(this.dgvStaffDailyMeal.Columns[currentCell.ColumnIndex].Name))
- {
- if (!_isBrushIsOpen)
- {
- this.tsbtnBrush.Checked = true;
- this._isBrushIsOpen = true;
- this.dgvStaffDailyMeal.Cursor = Cursors.Hand;
- this.dgvStaffDailyMeal.MultiSelect = true;
- this._remarks = this.dgvStaffDailyMeal.CurrentRow.Cells[currentCell.ColumnIndex].Value + "";
- }
- else
- {
- this.dgvStaffDailyMeal.Cursor = Cursors.Default;
- this.dgvStaffDailyMeal.MultiSelect = false;
- this.tsbtnBrush.Checked = false;
- this._isBrushIsOpen = 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 tsbtnAdaptive_Click(object sender, EventArgs e)
- {
- this.dgvStaffDailyMeal.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
- }
- /// <summary>
- /// 关闭按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void tsbtnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 查询按钮事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSearch_Click(object sender, EventArgs e)
- {
- try
- {
- SearchDailyMealEntity searchDailyMealEntity = SetSearchDailyMealEntity();
- DataSet dsResultStaff = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return HRModuleProxy.Service.SearcStaffDailyMealInfoForEdit(searchDailyMealEntity);
- }));
- if (dsResultStaff != null)
- {
- base.DataSource = dsResultStaff;
- if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
- {
- this.dgvStaffDailyMeal.DataSource = this.DataSource.Tables[0];
- if (this.DataSource.Tables[0].Rows.Count <= Constant.INT_IS_ZERO)
- {
- // 提示未查找到数据
- MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- }
- }
- 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 btnClearCondition_Click(object sender, EventArgs e)
- {
- this.dkStaffName.UserID = null;
- this.dkStaffName.UserCode = string.Empty;
- this.dkStaffName.UserName = string.Empty;
- this.dkStaffName.StaffEntity = null;
- this.scbOrganization.ClearValue();
- this.dkJobs.JobsID = null;
- this.dkJobs.JobsCode = string.Empty;
- this.dkJobs.JobsName = string.Empty;
- this.dtpMealDate.Value = DateTime.Now;
- }
- /// <summary>
- /// 保存按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- DataTable dtStaffMeal = this.dgvStaffDailyMeal.DataSource as DataTable;
- dtStaffMeal.AcceptChanges();
- HRResultEntity resultStaff = (HRResultEntity)DoAsync(new BaseAsyncMethod(() =>
- {
- if (this._editStatus == Constant.FormMode.Edit)
- {
- return WCF.Proxys.HRModuleProxy.Service.SaveStaffDailyMealInfo(dtStaffMeal, WCFConstant.FormMode.Edit);
- }
- return WCF.Proxys.HRModuleProxy.Service.SaveStaffDailyMealInfo(dtStaffMeal, WCFConstant.FormMode.MealEdit);
- }));
- if (!string.IsNullOrEmpty(resultStaff.OperateLogInfo))
- {
- // 提示信息
- MessageBox.Show(resultStaff.OperateLogInfo,
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else if (resultStaff.OperateStatus > Constant.INT_IS_ZERO)
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "员工报餐", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- else
- {
- // 提示信息
- MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "员工报餐", "保存"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- 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 btnCancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 设置窗体按钮的文本信息
- /// </summary>
- private void SetFromTitleInfo()
- {
- if (this._editStatus == Constant.FormMode.Add)
- {
- this.Text = FormTitles.F_HR_0902_ADD;
- }
- else if (this._editStatus == Constant.FormMode.Edit)
- {
- this.Text = FormTitles.F_HR_0902_EDIT;
- }
- this.tsbtnImport.Text = ButtonText.TSBTN_IMPORT;
- this.tsbtnBrush.Text = ButtonText.TSBTN_BRUSH;
- this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
- this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
- this.btnSearch.Text = ButtonText.BTN_SEARCH;
- this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
- this.btnSave.Text = ButtonText.BTN_SAVE;
- this.btnCancel.Text = ButtonText.BTN_CANCEL;
- this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
- }
- /// <summary>
- /// 使格式刷不可用
- /// </summary>
- private void SetBrushNotEnable()
- {
- this._isBrushIsOpen = false;
- this.tsbtnBrush.Checked = false;
- this.dgvStaffDailyMeal.Cursor = Cursors.Default;
- this.dgvStaffDailyMeal.MultiSelect = false;
- }
- /// <summary>
- /// 验证Excel模板中列是否符合规则
- /// </summary>
- /// <param name="pColumns">列集合</param>
- /// <returns></returns>
- private bool CheckExcelImportData(DataColumnCollection pColumns)
- {
- #region 定义模板中的标题
- List<string> excelColName = new List<string>();
- excelColName.Add("员工编号");
- excelColName.Add("员工姓名");
- excelColName.Add("报餐日期");
- if (this._editStatus == Constant.FormMode.Edit)
- {
- excelColName.Add("预定早餐");
- excelColName.Add("预定午餐");
- excelColName.Add("预定晚餐");
- excelColName.Add("备注");
- }
- else if (this._editStatus == Constant.FormMode.LimitEdit)
- {
- excelColName.Add("吃早餐");
- excelColName.Add("吃午餐");
- excelColName.Add("吃晚餐");
- }
- #endregion
- foreach (DataColumn itemCol in pColumns)
- {
- string strColName = itemCol.ColumnName;
- if (!excelColName.Contains(strColName))
- {
- return false;
- }
- }
- return true;
- }
- /// <summary>
- /// 返回GridView表中Check列名称
- /// </summary>
- /// <returns></returns>
- private List<string> GetGirdViewCheckColName()
- {
- List<string> checkColNames = new List<string>();
- checkColNames.Add("OrderBreakfast");
- checkColNames.Add("OrderLunch");
- checkColNames.Add("OrderDinner");
- checkColNames.Add("MealBreakfast");
- checkColNames.Add("MealLunch");
- checkColNames.Add("MealDinner");
- return checkColNames;
- }
- /// <summary>
- /// 根据查询条件 形成查询实体
- /// </summary>
- /// <returns></returns>
- public SearchDailyMealEntity SetSearchDailyMealEntity()
- {
- SearchDailyMealEntity searchDailyMealEntity = new SearchDailyMealEntity();
- if (this.dkStaffName.UserID != null)
- {
- searchDailyMealEntity.StaffID = this.dkStaffName.UserID;
- }
- if (this.scbOrganization.SearchedPKMember == 0)
- {
- searchDailyMealEntity.OrganizationID = this.scbOrganization.SearchedPKMember;
- }
- if (this.dkJobs.JobsID != null)
- {
- searchDailyMealEntity.Jobs = this.dkJobs.JobsID;
- }
- if (this.dtpMealDate.Value != null)
- {
- searchDailyMealEntity.MealDate = new DateTime(this.dtpMealDate.Value.Year, this.dtpMealDate.Value.Month, this.dtpMealDate.Value.Day);
- }
- return searchDailyMealEntity;
- }
- #endregion
- }
- }
|