| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_MST_0001.cs
- * 2.功能描述:帐套维护页面
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 张国印 2014/08/27 1.00 新建
- *******************************************************************************/
- using System;
- using System.Data;
- using System.Reflection;
- 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.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- namespace Dongke.IBOSS.PRD.Client.SystemModule
- {
- /// <summary>
- /// 帐套维护页面
- /// </summary>
- public partial class F_MST_0001 : FormBase
- {
- #region 成员变量
- // 窗体的单例模式
- private static F_MST_0001 _instance;
- // 帐套数据源
- private DataTable _dtSourse;
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- public F_MST_0001()
- {
- InitializeComponent();
- this.SetFromTitleInfo();
- }
- #endregion
- #region 事件
- /// <summary>
- /// 窗体关闭事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0001_FormClosed(object sender, FormClosedEventArgs e)
- {
- _instance = null;
- }
- /// <summary>
- /// 页面加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0001_Load(object sender, EventArgs e)
- {
- try
- {
- FormPermissionManager.FormPermissionControl(this.Name, this,
- LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
- LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
- // 设置“保存”按钮不可用
- this.btnSave.Enabled = false;
- // 设置表格不自动创建列
- this.dgvAccount.AutoGenerateColumns = false;
- // 窗体启动立即加载全部帐套信息
- this.GetAllAccount();
- this.RefreshDataGridViewData();
- this.SetAccountCodeEnable();
- this.dgvAccount.IsSetInputColumnsColor = true;
- this.dgvAccount.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 新增一行时,给有效属性设置选中状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvAccount_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
- {
- e.Row.Cells["ValueFlag"].Value = 1;
- }
- /// <summary>
- /// 行校验,帐套代码、帐套名称不能为空
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvAccount_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
- {
- try
- {
- // 按Esc时不进行校验
- if (!this.dgvAccount.IsCurrentRowDirty)
- {
- this.dgvAccount.IsSetInputColumnsColor = true;
- return;
- }
- if (this.ActiveControl != null && "btnCancel".Equals(this.ActiveControl.Name))
- {
- // 清除单元格的错误消息
- this.dgvAccount.CurrentRow.ErrorText = string.Empty;
- return;
- }
- DataGridViewRow row = this.dgvAccount.CurrentRow;
- if (!row.IsNewRow)
- {
- // 帐套代码不能为空
- if (row.Cells["AccountCode"].Value == null
- || string.IsNullOrEmpty(row.Cells["AccountCode"].Value.ToString().Trim()))
- {
- // 增加单元格的错误消息
- this.dgvAccount.CurrentRow.ErrorText =
- string.Format(Messages.MSG_CMN_W005, "帐套编码");
- e.Cancel = true;
- return;
- }
- // 帐套名称不能为空
- if (row.Cells["AccountName"].Value == null
- || string.IsNullOrEmpty(row.Cells["AccountName"].Value.ToString().Trim()))
- {
- // 增加单元格的错误消息
- this.dgvAccount.CurrentRow.ErrorText =
- string.Format(Messages.MSG_CMN_W005, "帐套名称");
- e.Cancel = true;
- return;
- }
- }
- // 清除单元格的错误消息
- this.dgvAccount.CurrentRow.ErrorText = string.Empty;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 输入验证,帐套代码不能重复输入
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvAccount_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
- {
- try
- {
- if (this.ActiveControl != null && "btnCancel".Equals(this.ActiveControl.Name))
- {
- return;
- }
- if (!this.dgvAccount.CurrentRow.IsNewRow)
- {
- DataGridViewRow rowItem = this.dgvAccount.Rows[e.RowIndex];
- DataGridViewColumn columnItem = this.dgvAccount.Columns[e.ColumnIndex];
- object value = rowItem.Cells[columnItem.Name].EditedFormattedValue;
- // 帐套代码
- if ("AccountCode".Equals(columnItem.Name))
- {
- if (value != null || !string.IsNullOrEmpty(value.ToString().Trim()))
- {
- bool isUnique = Utility.IsUnique(value.ToString(),
- this.dgvAccount.CurrentRow.Index,
- this.dgvAccount, "AccountCode");
- if (!isUnique)
- {
- // 增加单元格的错误消息
- this.dgvAccount.CurrentRow.ErrorText =
- string.Format(Messages.MSG_CMN_W006, "帐套编码");
- e.Cancel = true;
- this.btnSave.Enabled = false;
- return;
- }
- }
- }
- // 清除单元格的错误消息
- this.dgvAccount.CurrentRow.ErrorText = string.Empty;
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 根据数据变化,设置保存按钮的状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvAccount_RowValidated(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- this.RefreshSaveBtnStatus();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 根据数据有没有改变,设置"保存"按钮是否可用
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvAccount_CellValidated(object sender, DataGridViewCellEventArgs e)
- {
- try
- {
- this.RefreshSaveBtnStatus();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- 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();
- }
- /// <summary>
- /// 窗体关闭
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_MST_0001_FormClosing(object sender, FormClosingEventArgs e)
- {
- try
- {
- // 判断数据是否有变化
- if (DataJudge.IsChange((DataTable)this.dgvAccount.DataSource))
- {
- // 判断单元格是否有错误提示
- if (string.IsNullOrEmpty(this.dgvAccount.CurrentRow.ErrorText))
- {
- DialogResult dialogResult = MessageBox.Show(Messages.MSG_CMN_Q001,
- this.Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
- // 保存数据
- if (dialogResult == DialogResult.Yes)
- {
- this.SaveAccountInfo();
- }
- // 点击取消,不关闭窗体
- else if (dialogResult == DialogResult.Cancel)
- {
- e.Cancel = true;
- return;
- }
- }
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 保存按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- // 判断数据是否有变化
- if (DataJudge.IsChange((DataTable)this.dgvAccount.DataSource))
- {
- // 判断单元格是否有错误提示
- if (string.IsNullOrEmpty(this.dgvAccount.CurrentRow.ErrorText))
- {
- this.SaveAccountInfo();
- this.SetAccountCodeEnable();
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "列表中数据存在错误。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- else
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "列表中数据没有变化。"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- }
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 是否停用被选中后 刷新页面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void chkDisplayDisabledData_CheckedChanged(object sender, EventArgs e)
- {
- try
- {
- this.RefreshDataGridViewData();
- this.SetAccountCodeEnable();
- this.dgvAccount.IsSetInputColumnsColor = true;
- this.btnSave.Enabled = true;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- /// <summary>
- /// 排序后维持表格状态
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvAccount_Sorted(object sender, EventArgs e)
- {
- this.SetAccountCodeEnable();
- this.dgvAccount.IsSetInputColumnsColor = true;
- }
- /// <summary>
- /// 添加行事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dgvAccount_UserAddedRow(object sender, DataGridViewRowEventArgs e)
- {
- this.dgvAccount.IsSetInputColumnsColor = true;
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 设置窗体按钮的文本信息
- /// </summary>
- private void SetFromTitleInfo()
- {
- // 窗口标题
- this.Text = FormTitles.F_MST_0001;
- // 设置按钮文本
- this.btnCancel.Text = ButtonText.BTN_CLOSE;
- this.btnSave.Text = ButtonText.BTN_SAVE;
- }
- /// <summary>
- /// 得到帐套信息
- /// </summary>
- /// <returns></returns>
- private void RefreshDataGridViewData()
- {
- try
- {
- if (this.chkDisplayDisabledData.Checked == false)
- {
- _dtSourse.DefaultView.RowFilter = "ValueFlag=1";
- }
- else
- {
- _dtSourse.DefaultView.RowFilter = null;
- }
- this.dgvAccount.DataSource = _dtSourse;
- this.btnSave.Enabled = false;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 将已经存在的帐套代码单元格置成只读
- /// </summary>
- private void SetAccountCodeEnable()
- {
- for (int i = 0; i < this.dgvAccount.Rows.Count; i++)
- {
- if (!this.dgvAccount.Rows[i].IsNewRow)
- {
- if (string.IsNullOrEmpty(this.dgvAccount.Rows[i].Cells["AccountID"].Value.ToString()))
- {
- this.dgvAccount.Rows[i].Cells["AccountCode"].ReadOnly = false;
- }
- else
- {
- this.dgvAccount.Rows[i].Cells["AccountCode"].ReadOnly = true;
- }
- }
- }
- }
- /// <summary>
- /// 获取到帐套信息
- /// </summary>
- /// <returns></returns>
- private DataSet GetAccountInfo()
- {
- try
- {
- //获取是否停用选项的值
- bool valueFlag = chkDisplayDisabledData.Checked;
- DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetAccountInfo(valueFlag);
- }));
- return dsResultAccount;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 设置保存按钮的可用状态
- /// </summary>
- private void RefreshSaveBtnStatus()
- {
- if (DataJudge.IsChange((DataTable)this.dgvAccount.DataSource))
- {
- this.btnSave.Enabled = true;
- }
- else
- {
- this.btnSave.Enabled = false;
- }
- }
- /// <summary>
- /// 保存数据
- /// </summary>
- private void SaveAccountInfo()
- {
- bool bolIsValidCheck = this.IsValidCheck();
- if (!bolIsValidCheck)
- {
- return;
- }
- int resultState = this.SaveAccountData();
- // 存在相同的帐套代码 1
- if (Constant.INT_IS_ONE == resultState)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "帐套编码"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
- }
- // 保存成功 2表示有数据被修改 3表示没有数据被修改
- if (Constant.INT_IS_TWO == resultState)
- {
- this.GetAllAccount();
- this.btnSave.Enabled = false;
- 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);
- return;
- }
- this.RefreshDataGridViewData();
- this.SetAccountCodeEnable();
- this.dgvAccount.IsSetInputColumnsColor = true;
- }
- /// <summary>
- /// 调用服务保存帐套数据
- /// </summary>
- /// <returns></returns>
- private int SaveAccountData()
- {
- // 取得系统默认密码
- string defaultPassword = Constant.S_PASSWORD_DEFAULT; ;
- DataSet dtSetting = CommonModuleProxy.Service.GetSysSettingBySettingType("S_CMN_0001");
- if (dtSetting != null)
- {
- if (dtSetting.Tables.Count > Constant.INT_IS_ZERO)
- {
- if (dtSetting.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
- {
- defaultPassword = dtSetting.Tables[0].Rows[0]["SETTINGVALUE"].ToString();
- }
- }
- }
- defaultPassword = Encryption.GetMD5String(defaultPassword);
- DataTable AccountData = (DataTable)this.dgvAccount.DataSource;
- int result = (int)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.SaveAccountData(AccountData, defaultPassword);
- }));
- return result;
- }
- /// <summary>
- /// 验证是否可以进行帐套保存 True为可以保存,False为不可保存
- /// </summary>
- /// <returns>True为验证通过,False为验证不通过</returns>
- private bool IsValidCheck()
- {
- // 初始帐套不能设置成无效校验
- bool isDefaultAccountDisable = isDefaultAccountToDisable();
- if (isDefaultAccountDisable)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "系统默认的帐套不能置成无效状态"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- // 帐套数不能超过授权的帐套数
- bool isExceedLicenseAccountNumber = this.IsExceedLicenseAccountNumber();
- if (isExceedLicenseAccountNumber)
- {
- MessageBox.Show(string.Format(Messages.MSG_CMN_W007, "所创建的有效帐套数超出了授权许可的帐套数"),
- this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return false;
- }
- return true;
- }
- /// <summary>
- /// 判断是否将默认帐套设置成无效了
- /// </summary>
- /// <returns>
- /// true:将默认帐套设置成无效
- /// false:未将默认用户设置成无效
- /// </returns>
- private bool isDefaultAccountToDisable()
- {
- for (int i = 0; i < this.dgvAccount.Rows.Count; i++)
- {
- if (!this.dgvAccount.Rows[i].IsNewRow)
- {
- if (LogInUserInfo.CurrentUser.CurrentUserEntity.AccountCode.ToUpper() ==
- this.dgvAccount.Rows[i].Cells["AccountCode"].Value.ToString().ToUpper()
- && !Constant.ValueFlag.Effective.GetHashCode().ToString().Equals(
- this.dgvAccount.Rows[i].Cells["valueFlag"].Value.ToString()))
- {
- return true;
- }
- }
- }
- return false;
- }
- /// <summary>
- /// 判断当前的有效帐套数是否超过了授权帐套数
- /// </summary>
- /// <returns>
- /// true:超出
- /// false:未超出
- /// </returns>
- private bool IsExceedLicenseAccountNumber()
- {
- int accountNumber = 0;
- for (int i = 0; i < this.dgvAccount.Rows.Count; i++)
- {
- if (!this.dgvAccount.Rows[i].IsNewRow)
- {
- if (Constant.ValueFlag.Effective.GetHashCode().ToString().Equals(
- this.dgvAccount.Rows[i].Cells["valueFlag"].Value.ToString()))
- {
- accountNumber += 1;
- }
- }
- }
- int licenseCount = 999; //目前设置为最大值,正式使用后需要修改为0
- if (LogInUserInfo.CurrentUser.CurrentLicenseInfo != null)
- {
- if (LogInUserInfo.CurrentUser.CurrentLicenseInfo.Tables.Count > 0)
- {
- if (LogInUserInfo.CurrentUser.CurrentLicenseInfo.Tables.Contains("BaseInfoTable"))
- {
- licenseCount = (int)LogInUserInfo.CurrentUser.CurrentLicenseInfo.
- Tables["BaseInfoTable"].Rows[0]["AccountNumber"];
- }
- }
- }
- if (accountNumber > licenseCount)
- {
- return true;
- }
- return false;
- }
- /// <summary>
- /// 获取全部帐套信息
- /// </summary>
- private void GetAllAccount()
- {
- try
- {
- DataSet dsResultAccount = (DataSet)DoAsync(new BaseAsyncMethod(() =>
- {
- return SystemModuleProxy.Service.GetAllAccountInfo();
- }));
- this._dtSourse = dsResultAccount.Tables[0];
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- #endregion
- }
- }
|