Пример #1
0
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static myPortal.Model.saUserRoleInfo ReaderBind(IDataReader dataReader)
        {
            myPortal.Model.saUserRoleInfo model = new myPortal.Model.saUserRoleInfo();
            object ojb;
            ojb = dataReader["iIden"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.iIden = (int)ojb;
            }
            ojb = dataReader["iUserId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.iUserId = (int)ojb;
            }


            ojb = dataReader["iRoleId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.iRoleId = (int)ojb;
            }

            return model;
        }
Пример #2
0
        protected void buttonOK_Click(object sender, EventArgs e)
        {
            if (CheckInput())
            {
                myMembershipProvider provider = Membership.Provider as myMembershipProvider;
                try
                {
                    saUserInfo user = new saUserInfo();
                    user.sUserNo = txtUserNo.Text.Trim();
                    user.sUserName = txtUserName.Text.Trim();
                    user.sPassword = txtUserNo.Text.Trim();
                    user.sEmail = txtEmail.Text.Trim();
                    user.sRemark = txtRemark.Text.Trim();

                    user.bUsable = !cbxUsable.Checked;

                    if (!this.txtRoles.Value.IsNullOrWhiteSpace())
                    {
                        string[] roles = this.txtRoles.Value.Split(',');

                        for (int i = 0; i < roles.Length; i++)
                        {
                            var a = user.UserOrgRole.FirstOrDefault(p =>
                                p.iUserId == user.iIden
                                && p.iRoleId == int.Parse(roles[i]));
                            if (a == null)
                            {
                                saUserRoleInfo uor = new saUserRoleInfo();
                                uor.iIden = IdenGenerator.Current.NewIden(saUserRoleInfo.sTableName);
                                uor.iRoleId = int.Parse(roles[i]);
                                user.UserOrgRole.Add(uor);
                            }
                        }
                    }

                    if (this.IsModifyAction)
                    {
                        int.TryParse(Request["iUserId"], out iUserId);
                        user.iIden = iUserId;
                        user.UserOrgRole.ToList().ForEach(p => p.iUserId = iUserId);
                        provider.UpdateUser(user);
                        Response.Clear();

                        ClientScript.RegisterStartupScript(this.GetType(), string.Empty,
                                                      "<script type=\"text/javascript\">alert('{0}');location.href='UserManage.aspx';</script>".FormatEx(Resources.GlobalResources.ModifiedSuccess));


                    }
                    else
                    {
                        MembershipCreateStatus status;
                        int iUserId = IdenGenerator.Current.NewIden(saUserInfo.sTableName);
                        user.iIden = iUserId;
                        user.UserOrgRole.ToList().ForEach(p => p.iUserId = iUserId);
                        saUserInfo nuser = provider.CreateUser(user, out status) as saUserInfo;
                        if (nuser == null)
                        {
                            hasError = true;
                            switch (status)
                            {
                                case MembershipCreateStatus.DuplicateUserName:
                                    errorMsg = "用户ID已经存在";
                                    break;
                                case MembershipCreateStatus.InvalidPassword:
                                    errorMsg = "密码的格式设置不正确";
                                    break;
                                default:
                                    errorMsg = "未知错误!";
                                    break;
                            }

                            return;
                        }
                        Response.Clear();

                        ClientScript.RegisterStartupScript(this.GetType(), string.Empty,
                           "<script type=\"text/javascript\">alert('{0}');location.href='UserManage.aspx';</script>".FormatEx(Resources.GlobalResources.AddedSuccess));


                    }
                }
                catch (Exception ex)
                {
                    hasError = true;
                    errorMsg = ex.Message;
                }
            }
        }