using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ICSharpCode.Core; using Mesnac.Codd.Session; using Mesnac.Action.Default.Entity; namespace Mesnac.Action.Default.Purview.BasUser { public partial class FrmInsert : Form { #region 字段定义 private ActionType _actionType = ActionType.Add; //操作类别,默认为添加 #endregion #region 属性定义 /// /// 用户名 /// public string UserName { get { return this.txtUserName.Text; } } /// /// 密码 /// public string UserPWD { get { return this.txtUserPWD.Text; } } /// /// 所属角色 /// public string RoleGUID { get { return this.cmbRole.SelectedValue as string; } } /// /// 所属班组 /// /// public int ClassID { get { int intClassID = 0; int.TryParse(this.cmbClass.SelectedValue.ToString(), out intClassID); return intClassID; } } /// /// 具体的人员姓名 /// public string RealName { get { return this.txtRealName.Text; } } #endregion #region 构造方法 /// /// 无参构造方法 /// public FrmInsert() { InitializeComponent(); } /// /// 参数构造方法 /// /// 操作类型 public FrmInsert(ActionType actionType) { InitializeComponent(); this._actionType = actionType; } #endregion #region 方法定义 /// /// 初始化界面元素 /// public void InitUIMethod() { if (this._actionType == ActionType.Add) { this.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_Text")); //添加用户 this.groupBox1.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_groupBox1_Text")); //用户信息 } else { this.txtUserPWD.Enabled = false; this.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_Text_Query")); //查询用户 this.groupBox1.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_groupBox1_Text_Query")); //查询条件 } this.label1.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_label1_Text")); //用户账号 this.label2.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_label2_Text")); //密码 this.label3.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_label3_Text")); //角色 this.label4.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_label4_Text")); //班组 this.label5.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_label5_Text")); //人员姓名 this.btnOk.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnOK")); this.btnCancel.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_btnCancel")); } /// /// 初始化数据 /// public void InitData() { this.cmbRole.DataSource =PurviewHelper.GetRoleListForSelect(); this.cmbClass.DataSource = PurviewHelper.GetClassListForSelect(); } #endregion #region 事件处理 private void FrmInsert_Load(object sender, EventArgs e) { this.InitUIMethod(); this.InitData(); } private void btnOk_Click(object sender, EventArgs e) { if (this._actionType == ActionType.Add) { if (string.IsNullOrEmpty(this.txtUserName.Text.Trim())) { ICSharpCode.Core.LoggingService.Warn("用户账号不能为空,请输入用户账号!"); string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_msg1")); //用户账号不能为空,请输入用户账号! MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtUserName.Focus(); return; } if (PurviewHelper.IsExistsUserName(this.txtUserName.Text.Trim())) { ICSharpCode.Core.LoggingService.Warn("已存在此用户账号,请输入新的用户账号!"); string msg2 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_msg2")); //已存在此用户账号,请输入新的用户账号! MessageBox.Show(msg2, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtUserName.Focus(); return; } if (string.IsNullOrEmpty(this.txtUserPWD.Text.Trim())) { ICSharpCode.Core.LoggingService.Warn("密码不能为空,请输入密码!"); string msg3 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_msg3")); //密码不能为空,请输入密码! MessageBox.Show(msg3, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtUserPWD.Focus(); return; } if (String.IsNullOrEmpty(this.RoleGUID)) { ICSharpCode.Core.LoggingService.Warn("所属角色不能为空,请选择角色!"); string msg4 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_msg4")); //所属角色不能为空,请选择角色! MessageBox.Show(msg4, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this.cmbRole.Focus(); return; } if (this.ClassID == 0) { ICSharpCode.Core.LoggingService.Warn("所属班组不能为空,请选择班组!"); string msg5 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_msg5")); //所属班组不能为空,请选择班组! MessageBox.Show(msg5, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this.cmbClass.Focus(); return; } if (string.IsNullOrEmpty(this.txtRealName.Text.Trim())) { ICSharpCode.Core.LoggingService.Warn("人员姓名不能为空,请输入人员姓名!"); string msg6 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_Purview_BasUser_FrmInsert_msg6")); //人员姓名不能为空,请输入人员姓名! MessageBox.Show(msg6, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); this.txtRealName.Focus(); return; } } this.DialogResult = System.Windows.Forms.DialogResult.OK; } private void btnCancel_Click(object sender, EventArgs e) { this.DialogResult = System.Windows.Forms.DialogResult.Cancel; } #endregion } }