/******************************************************************************* * 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 { /// /// 员工报餐新增/编辑 /// 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 构造函数 /// /// 构造函数 /// /// 编辑状态 /// 员工ID /// 报餐日期 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 事件 /// /// 窗体加载事件 /// /// /// 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); } } /// /// 数据刷刷数据 /// /// /// 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 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); } } /// /// 导入按钮 /// /// /// 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); } } /// /// 数据刷按钮 /// /// /// 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 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); } } /// /// 自动适应列宽 /// /// /// private void tsbtnAdaptive_Click(object sender, EventArgs e) { this.dgvStaffDailyMeal.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); } /// /// 关闭按钮事件 /// /// /// private void tsbtnClose_Click(object sender, EventArgs e) { this.Close(); } /// /// 查询按钮事件 /// /// /// 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); } } /// /// 清空条件 /// /// /// 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; } /// /// 保存按钮 /// /// /// 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); } } /// /// 关闭按钮 /// /// /// private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 私有方法 /// /// 设置窗体按钮的文本信息 /// 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; } /// /// 使格式刷不可用 /// private void SetBrushNotEnable() { this._isBrushIsOpen = false; this.tsbtnBrush.Checked = false; this.dgvStaffDailyMeal.Cursor = Cursors.Default; this.dgvStaffDailyMeal.MultiSelect = false; } /// /// 验证Excel模板中列是否符合规则 /// /// 列集合 /// private bool CheckExcelImportData(DataColumnCollection pColumns) { #region 定义模板中的标题 List excelColName = new List(); 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; } /// /// 返回GridView表中Check列名称 /// /// private List GetGirdViewCheckColName() { List checkColNames = new List(); checkColNames.Add("OrderBreakfast"); checkColNames.Add("OrderLunch"); checkColNames.Add("OrderDinner"); checkColNames.Add("MealBreakfast"); checkColNames.Add("MealLunch"); checkColNames.Add("MealDinner"); return checkColNames; } /// /// 根据查询条件 形成查询实体 /// /// 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 } }