Exemplo n.º 1
0
        private void sb_ok_Click(object sender, EventArgs e)
        {
            //数据校验
            string s_uc002   = txtedit_uc002.Text;
            string s_uc003   = txtedit_uc003.Text;
            string s_uc004   = txtedit_pwd.Text;
            string s_uc004_2 = txtedit_pwd2.Text;

            if (String.IsNullOrEmpty(s_uc002))
            {
                txtedit_uc002.ErrorImageOptions.Alignment = ErrorIconAlignment.MiddleRight;
                txtedit_uc002.ErrorText = "用户登录代码必须输入!";
                txtedit_uc002.Focus();
                return;
            }

            if (String.IsNullOrEmpty(s_uc003))
            {
                txtedit_uc003.ErrorImageOptions.Alignment = ErrorIconAlignment.MiddleRight;
                txtedit_uc003.ErrorText = "用户姓名必须输入!";
                txtedit_uc003.Focus();
                return;
            }

            if (action == "add")
            {
                if (String.IsNullOrEmpty(s_uc004))
                {
                    txtedit_pwd.ErrorImageOptions.Alignment = ErrorIconAlignment.MiddleRight;
                    txtedit_pwd.ErrorText = "密码必须输入!";
                    txtedit_pwd.Focus();
                    return;
                }
                else if (!String.Equals(s_uc004, s_uc004_2))
                {
                    txtedit_pwd2.ErrorImageOptions.Alignment = ErrorIconAlignment.MiddleRight;
                    txtedit_pwd2.ErrorText = "密码不一致!";
                    txtedit_pwd2.Focus();
                    return;
                }
            }

            /////////// 保存过程  ////////
            if (action == "add")
            {
                uc01        = new UC01(unitOfWork1);
                uc01.UC001  = MiscAction.GetEntityPK("UC01");
                uc01.STATUS = '1';
                uc01.UC004  = SecurityTool.EncryptWithMD5(s_uc004);
            }
            uc01.UC002 = s_uc002;
            uc01.UC003 = s_uc003;

            try
            {
                ///unitOfWork1.BeginTransaction();
                uc01.Save();

                SqlHelper.ExecuteNonQuery("delete from ur_mapper where uc001 = :uc001", new string[] { "uc001" }, new string[] { uc01.UC001 });

                foreach (RO01 r in clbx_roles.CheckedItems)
                {
                    UR_MAPPER mapper = new UR_MAPPER(unitOfWork1);
                    mapper.UM001 = MiscAction.GetEntityPK("MAPPER");
                    mapper.UC001 = uc01.UC001;
                    mapper.RO001 = r.RO001;
                    mapper.Save();
                }

                unitOfWork1.CommitChanges();
                XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            catch (Exception ee)
            {
                unitOfWork1.RollbackTransaction();
                LogUtils.Error(ee.Message);
                XtraMessageBox.Show(ee.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }