Beispiel #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (UserInputCheck())
            {
                if (!_isModify)
                {
                    if (OracleHelper.Exists(OracleHelper.conn, string.Format("SELECT COUNT(*) FROM SYS_USERINFO WHERE USERLOGINNAME='{0}'", this.txtLoginName.Text.ToLower().Trim())))
                    {
                        XtraMessageBox.Show(string.Format("用户账号{0}已存在", this.txtLoginName.Text), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }

                string OperatorName = this.txtName.Text.Trim();
                string LoginName    = this.txtLoginName.Text.Trim();
                string strRoleID    = string.Empty;
                foreach (System.Collections.DictionaryEntry de in htRole)
                {
                    if (de.Value.ToString() == this.cbRole.Text.Trim())
                    {
                        strRoleID = de.Key.ToString(); //得到key
                        break;                         //退出foreach遍历
                    }
                }
                string DeptID = string.Empty;
                foreach (System.Collections.DictionaryEntry de in htDept)
                {
                    if (de.Value.ToString() == this.cbDept.Text)
                    {
                        DeptID = de.Key.ToString(); //得到key
                        break;                      //退出foreach遍历
                    }
                }

                string Phone = String.IsNullOrEmpty(this.txtPhone.Text) ? null : this.txtPhone.Text;
                string Email = String.IsNullOrEmpty(this.txtEmail.Text) ? null : this.txtEmail.Text;

                int status = this.chkState.Checked ? 0 : 1;//0有效1无效
                if (string.IsNullOrEmpty(userId))
                {
                    userId = Guid.NewGuid().ToString();
                }
                string Password = EncryptUtil.Md532(LoginName.ToLower().Trim()); //string.Empty;//初始密码跟账号保持一致

                //新增
                StringBuilder sbInsSQL = new StringBuilder();
                sbInsSQL.Append("INSERT INTO SYS_USERINFO (ID,MODIFYTIME,USERDEPTID");
                sbInsSQL.Append(",USEREMAIL,USERLOGINNAME,USERNAME,PWD,USERROLEID,USERTEL,STATUS) VALUES ('{0}',sysdate,'{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8}) ");
                string strInsSQL = string.Format(sbInsSQL.ToString(), userId, DeptID, Email, LoginName.ToLower().Trim(), OperatorName, Password, strRoleID, Phone, status);

                //修改
                StringBuilder sbUpdSQL = new StringBuilder();
                sbUpdSQL.AppendFormat("UPDATE SYS_USERINFO SET MODIFYTIME=sysdate");
                sbUpdSQL.AppendFormat(",USEREMAIL='{0}',USERLOGINNAME='{1}',USERNAME='******',USERDEPTID='{3}'", Email, LoginName, OperatorName, DeptID);
                sbUpdSQL.AppendFormat(",USERROLEID='{0}',USERTEL='{1}',STATUS={2} ", strRoleID, Phone, status);
                sbUpdSQL.AppendFormat("WHERE ID='{0}' ", userId);

                using (OracleConnection con = new OracleConnection(OracleHelper.conn))
                {
                    con.Open();

                    int count = OracleHelper.ExecuteNonQuery(con, _isModify ? sbUpdSQL.ToString() : strInsSQL, null);
                    if (count > 0)
                    {
                        this.Close();
                        UserForm uf = new UserForm();
                        uf.SearchLocal(1);
                        XtraMessageBox.Show("操作成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        XtraMessageBox.Show("操作失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }