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

            model.sUserNo = dataReader["sUserNo"].ToString();
            model.sUserName = dataReader["sUserName"].ToString();
            model.sPassword = dataReader["sPassword"].ToString();
            model.sEmail = dataReader["sEmail"].ToString();
            model.sRemark = dataReader["sRemark"].ToString();
            ojb = dataReader["bUsable"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.bUsable = (bool)ojb;
            }
            ojb = dataReader["bIsSystem"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.bIsSystem = (bool)ojb;
            }
            return model;
        }
Пример #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        public void Update(saUserInfo model)
        {
            string errMessage = string.Empty;
            if (!CheckUQ.CheckUqBeforeUpdate(saUserInfo.sTableName, model, out errMessage))
                throw new Exception(errMessage);

            StringBuilder strSql = new StringBuilder();
            strSql.Append(" update saUser set ");
            strSql.Append(" sUserNo=@sUserNo,");
            strSql.Append(" sUserName=@sUserName,");
            strSql.Append(" sEmail=@sEmail,");
            strSql.Append(" sRemark=@sRemark,");
            strSql.Append(" bUsable=@bUsable");
            strSql.Append(" where iIden=@iIden ");

            string deleteSql = "delete saUserRole where iUserId={0}".FormatEx(model.iIden);

            StringBuilder strSqlUor = new StringBuilder();
            strSqlUor.Append("insert into saUserRole(");
            strSqlUor.Append("iIden,iUserId,iRoleId)");
            strSqlUor.Append(" values (");
            strSqlUor.Append("@iIden,@iUserId,@iRoleId)");

            Database db = DatabaseFactory.CreateDatabase();
            using (DbConnection con = db.CreateConnection())
            {
                con.Open();
                DbTransaction trans = con.BeginTransaction();
                try
                {
                    DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
                    db.AddInParameter(dbCommand, "iIden", DbType.Int32, model.iIden);
                    db.AddInParameter(dbCommand, "sUserNo", DbType.String, model.sUserNo);
                    db.AddInParameter(dbCommand, "sUserName", DbType.String, model.sUserName);
                    db.AddInParameter(dbCommand, "sEmail", DbType.String, model.sEmail);
                    db.AddInParameter(dbCommand, "sRemark", DbType.String, model.sRemark);
                    db.AddInParameter(dbCommand, "bUsable", DbType.Boolean, model.bUsable);
                    db.ExecuteNonQuery(dbCommand, trans);

                    db.ExecuteNonQuery(trans, CommandType.Text, deleteSql);

                    if (model.UserOrgRole != null && model.UserOrgRole.Count() > 0)
                    {
                        foreach (var item in model.UserOrgRole)
                        {
                            DbCommand cmd = db.GetSqlStringCommand(strSqlUor.ToString());
                            db.AddInParameter(cmd, "iIden", DbType.Int32, item.iIden);
                            db.AddInParameter(cmd, "iUserId", DbType.Int32, item.iUserId);
                            db.AddInParameter(cmd, "iRoleId", DbType.Int32, item.iRoleId);
                            db.ExecuteNonQuery(cmd, trans);
                        }
                    }
                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }
                finally
                {
                    con.Close();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        public void Create(saUserInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into saUser(iIden,sUserNo,sUserName,sPassword,sEmail,sRemark,bUsable,bIsSystem)");
            strSql.Append(" values (@iIden,@sUserNo,@sUserName,@sPassword,@sEmail,@sRemark,@bUsable,0)");

            string deleteSql = "delete saUserRole where iUserId={0}".FormatEx(model.iIden);

            StringBuilder strSqlUor = new StringBuilder();
            strSqlUor.Append("insert into saUserRole(iIden,iUserId,iRoleId)");
            strSqlUor.Append(" values (@iIden,@iUserId,@iRoleId)");

            Database db = DatabaseFactory.CreateDatabase();
            using (DbConnection con = db.CreateConnection())
            {
                con.Open();
                DbTransaction trans = con.BeginTransaction();
                try
                {
                    DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
                    db.AddInParameter(dbCommand, "iIden", DbType.Int32, model.iIden);
                    db.AddInParameter(dbCommand, "sUserNo", DbType.String, model.sUserNo);
                    db.AddInParameter(dbCommand, "sUserName", DbType.String, model.sUserName);
                    db.AddInParameter(dbCommand, "sPassword", DbType.String, model.sPassword);
                    db.AddInParameter(dbCommand, "sEmail", DbType.String, model.sEmail);

                    db.AddInParameter(dbCommand, "sRemark", DbType.String, model.sRemark);

                    db.AddInParameter(dbCommand, "bUsable", DbType.String, model.bUsable);
                    db.ExecuteNonQuery(dbCommand, trans);

                    db.ExecuteNonQuery(trans, CommandType.Text, deleteSql);

                    if (model.UserOrgRole != null && model.UserOrgRole.Count() > 0)
                    {
                        foreach (var item in model.UserOrgRole)
                        {
                            DbCommand cmd = db.GetSqlStringCommand(strSqlUor.ToString());
                            db.AddInParameter(cmd, "iIden", DbType.Int32, item.iIden);
                            db.AddInParameter(cmd, "iUserId", DbType.Int32, item.iUserId);
                            db.AddInParameter(cmd, "iRoleId", DbType.Int32, item.iRoleId);

                            db.ExecuteNonQuery(cmd, trans);
                        }
                    }
                    trans.Commit();
                }
                catch
                {
                    trans.Rollback();
                    throw;
                }
                finally
                {
                    con.Close();
                }
            }
        }
Пример #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="user"></param>
 public void UpdateUser(saUserInfo user)
 {
     if (user == null)
         throw new ApplicationException("用户不能为空。");
     dal.Update(user);
 }
Пример #5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="user"></param>
 public void CreateUser(saUserInfo user)
 {
     dal.Create(user);
 }
Пример #6
0
        public MembershipUser CreateUser(saUserInfo user, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args =
                new ValidatePasswordEventArgs(user.iIden.ToString(), user.sPassword, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }
            saUserInfo tempuser = saUser.Current.GetUser(user.sUserNo);

            if (tempuser == null)
            {
                user.sPassword = EncodePassword(user.sPassword);
                try
                {
                    saUser.Current.CreateUser(user);
                    status = MembershipCreateStatus.Success;
                }
                catch
                {
                    status = MembershipCreateStatus.UserRejected;
                    throw;
                }
                return user;
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return null;
        }
Пример #7
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;
                }
            }
        }