Ejemplo n.º 1
0
        /// <summary>
        /// 得到登录对象实体	方法重载
        /// </summary>
        /// <param name="AccountNum">用户名</param>
        /// <param name="Pwd">密码</param>
        /// <returns></returns>
        public Info_User_Model GetModel(string AccountNum, string Pwd)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(
                "select  top 1 UserID,UserName,UserAvatar,UserSex,UserPhone,AccountNum,Pwd,CreateUser,CreateTime,UpdateUser,UpdateTime,IsDelete,Remark from Info_User ");
            strSql.Append(" where AccountNum=@AccountNum and Pwd=@Pwd ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@AccountNum", SqlDbType.NVarChar, 50),
                new SqlParameter("@Pwd",        SqlDbType.NVarChar, 255)
            };
            parameters[0].Value = AccountNum;
            parameters[1].Value = Pwd;

            Info_User_Model model = new Info_User_Model();
            DataSet         ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Info_User_Model GetModel(Guid UserID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(
                "select  top 1 UserID,UserName,UserAvatar,UserSex,UserPhone,AccountNum,Pwd,CreateUser,CreateTime,UpdateUser,UpdateTime,IsDelete,Remark from Info_User ");
            strSql.Append(" where UserID=@UserID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID", SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value = UserID;

            Info_User_Model model = new Info_User_Model();
            DataSet         ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Info_User_Model model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Info_User set ");
            strSql.Append("UserName=@UserName,");
            strSql.Append("UserAvatar=@UserAvatar,");
            strSql.Append("UserSex=@UserSex,");
            strSql.Append("UserPhone=@UserPhone,");
            strSql.Append("AccountNum=@AccountNum,");
            strSql.Append("Pwd=@Pwd,");
            strSql.Append("CreateUser=@CreateUser,");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("UpdateUser=@UpdateUser,");
            strSql.Append("UpdateTime=@UpdateTime,");
            strSql.Append("IsDelete=@IsDelete,");
            strSql.Append("Remark=@Remark");
            strSql.Append(" where UserID=@UserID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserName",   SqlDbType.NVarChar,         255),
                new SqlParameter("@UserAvatar", SqlDbType.NVarChar,         255),
                new SqlParameter("@UserSex",    SqlDbType.Int,                4),
                new SqlParameter("@UserPhone",  SqlDbType.NVarChar,          50),
                new SqlParameter("@AccountNum", SqlDbType.NVarChar,          50),
                new SqlParameter("@Pwd",        SqlDbType.NVarChar,         255),
                new SqlParameter("@CreateUser", SqlDbType.UniqueIdentifier,  16),
                new SqlParameter("@CreateTime", SqlDbType.DateTime),
                new SqlParameter("@UpdateUser", SqlDbType.UniqueIdentifier,  16),
                new SqlParameter("@UpdateTime", SqlDbType.DateTime),
                new SqlParameter("@IsDelete",   SqlDbType.Bit,                1),
                new SqlParameter("@Remark",     SqlDbType.NVarChar,          50),
                new SqlParameter("@UserID",     SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value  = model.UserName;
            parameters[1].Value  = model.UserAvatar;
            parameters[2].Value  = model.UserSex;
            parameters[3].Value  = model.UserPhone;
            parameters[4].Value  = model.AccountNum;
            parameters[5].Value  = model.Pwd;
            parameters[6].Value  = model.CreateUser;
            parameters[7].Value  = model.CreateTime;
            parameters[8].Value  = model.UpdateUser;
            parameters[9].Value  = model.UpdateTime;
            parameters[10].Value = model.IsDelete;
            parameters[11].Value = model.Remark;
            parameters[12].Value = model.UserID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Info_User_Model model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Info_User(");
            strSql.Append(
                "UserID,UserName,UserAvatar,UserSex,UserPhone,AccountNum,Pwd,CreateUser,CreateTime,UpdateUser,UpdateTime,IsDelete,Remark)");
            strSql.Append(" values (");
            strSql.Append(
                "@UserID,@UserName,@UserAvatar,@UserSex,@UserPhone,@AccountNum,@Pwd,@CreateUser,@CreateTime,@UpdateUser,@UpdateTime,@IsDelete,@Remark)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID",     SqlDbType.UniqueIdentifier,  16),
                new SqlParameter("@UserName",   SqlDbType.NVarChar,         255),
                new SqlParameter("@UserAvatar", SqlDbType.NVarChar,         255),
                new SqlParameter("@UserSex",    SqlDbType.Int,                4),
                new SqlParameter("@UserPhone",  SqlDbType.NVarChar,          50),
                new SqlParameter("@AccountNum", SqlDbType.NVarChar,          50),
                new SqlParameter("@Pwd",        SqlDbType.NVarChar,         255),
                new SqlParameter("@CreateUser", SqlDbType.UniqueIdentifier,  16),
                new SqlParameter("@CreateTime", SqlDbType.DateTime),
                new SqlParameter("@UpdateUser", SqlDbType.UniqueIdentifier,  16),
                new SqlParameter("@UpdateTime", SqlDbType.DateTime),
                new SqlParameter("@IsDelete",   SqlDbType.Bit,                1),
                new SqlParameter("@Remark",     SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = Guid.NewGuid();
            parameters[1].Value = model.UserName;
            parameters[2].Value = model.UserAvatar;
            parameters[3].Value = model.UserSex;
            parameters[4].Value = model.UserPhone;
            parameters[5].Value = model.AccountNum;
            parameters[6].Value = model.Pwd;
            // parameters[7].Value = Guid.NewGuid();
            parameters[7].Value = model.CreateUser;

            parameters[8].Value = model.CreateTime;
            // parameters[9].Value = Guid.NewGuid();
            parameters[9].Value = model.UpdateUser;

            parameters[10].Value = model.UpdateTime;
            parameters[11].Value = model.IsDelete;
            parameters[12].Value = model.Remark;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取数据库用户信息
        /// </summary>
        private void GetUserInfo()
        {
            Info_User_BLL   infoUserBll   = new Info_User_BLL();
            Info_User_Model infoUserModel = infoUserBll.GetModel(new Guid(UserID));

            TextBox1.Text     = infoUserModel.UserName;
            TextBox2.Text     = infoUserModel.UserSex.ToString();
            TextBox3.Text     = infoUserModel.UserPhone;
            TextBox4.Text     = infoUserModel.AccountNum;
            TextBox4.ReadOnly = true;
            TextBox5.Text     = infoUserModel.Pwd;
        }
Ejemplo n.º 6
0
        protected void Button1_OnClick(object sender, EventArgs e)
        {
            Info_User_BLL   infoUserBll   = new Info_User_BLL();
            Info_User_Model infoUserModel = new Info_User_Model();
            string          AccountNum    = TextBox1.Text.Trim();
            string          Pwd           = TextBox2.Text.Trim();

            List <Info_User_Model> infoUserModels = infoUserBll.GetModelList("AccountNum='" + AccountNum + "'");

            // lambda表达式 .tolist转换为list列表
            if (infoUserModels.Where(x => x.AccountNum == AccountNum).ToList().Count > 0)
            {
                Response.Write("用户账户已经重复,请输入其他的");
                return;
            }


            infoUserModel.UserID     = Guid.NewGuid();
            infoUserModel.AccountNum = AccountNum;
            infoUserModel.Pwd        = Pwd;
            infoUserModel.CreateUser = Guid.NewGuid();
            infoUserModel.CreateTime = DateTime.Now;
            // 添加日志
            Sys_ProcessLog_Model sysProcessLogModel = new Sys_ProcessLog_Model();

            sysProcessLogModel.ID             = Guid.NewGuid();
            sysProcessLogModel.LogType        = (int)SystemLogType.UserRegister;
            sysProcessLogModel.LogDescription = "插入了一个用户";
            sysProcessLogModel.CreateUser     = new Guid("CB693BE8-D36C-4B27-8E6B-892987DC5D9E");
            sysProcessLogModel.CreateTime     = DateTime.Now;
            // 修改成使用事务
            bool result = infoUserBll.Add(infoUserModel, sysProcessLogModel);

            if (result)
            {
                Response.Write("添加成功");
                Response.Redirect("Login.aspx");
            }
            else
            {
                Response.Write("添加失败,请联系管理员");
            }
        }
Ejemplo n.º 7
0
        public JsonResult GetLoginByPhone(Info_User_Model model)
        {
            JsonResult    jr          = new JsonResult();
            Result        result      = new Result();
            Info_User_BLL infoUserBll = new Info_User_BLL();
            Info_User     infoUser    = infoUserBll.Login(model.Phone, model.PassWord);

            if (infoUser != null)
            {
                result.message = "登录成功";
                result.type    = "success";
                result.data    = new { reutrnUrl = Url.Content("~/User/Index") };
            }
            else
            {
                result.message = "登录失败,请检查用户名和密码";
                result.type    = "error";
            }

            jr.Data = result;
            return(jr);
        }
Ejemplo n.º 8
0
        protected void Button1_OnClick(object sender, EventArgs e)
        {
            Info_User_BLL   infoUserBll   = new Info_User_BLL();
            Info_User_Model infoUserModel = infoUserBll.GetModel(new Guid(UserID));

            infoUserModel.UserName   = TextBox1.Text;
            infoUserModel.UserSex    = Convert.ToInt32(TextBox2.Text);
            infoUserModel.UserPhone  = TextBox3.Text;
            infoUserModel.AccountNum = TextBox4.Text;
            infoUserModel.Pwd        = TextBox5.Text;
            bool result = infoUserBll.Update(infoUserModel);

            if (result)
            {
                Response.Write("更新成功");
                Response.Redirect("Login.aspx");
            }
            else
            {
                Response.Write("更新失败,请联系管理员");
            }
        }
Ejemplo n.º 9
0
        protected void Button1_OnClick(object sender, EventArgs e)
        {
            string        AccountNum  = TextBox1.Text.Trim();
            string        Pwd         = TextBox2.Text.Trim();
            Info_User_BLL infoUserBll = new Info_User_BLL();


            /*
             * // 是否登录
             * List<Info_User_Model> ds =
             *  infoUserBll.GetModelList("AccountNum='" + AccountNum + "' and Pwd='" + Pwd + "'");
             * if (ds.Count > 0)
             * {
             *  Info_User_Model infoUserModel = ds.FirstOrDefault();
             *  Response.Write("<div class='alert alert-success' role='alert'>登录成功</div>");
             *  CookieHelper.SetCookie("UserID", infoUserModel.UserID.ToString(), DateTime.Now.AddMinutes(10));
             *  Response.Redirect("LogList.aspx?AccountNum=" + AccountNum + "&UserID=" + infoUserModel.UserID);
             * }
             * else
             * {
             *  Response.Write("<div class='alert alert-danger' role='alert'>登录失败</div>");
             * }
             */
            // 自定义登录
            Info_User_Model infoUserModel = infoUserBll.GetModel(AccountNum, Pwd);

            if (infoUserModel != null)
            {
                Response.Write("<div class='alert alert-success' role='alert'>登录成功</div>");
                CookieHelper.SetCookie("UserID", infoUserModel.UserID.ToString(), DateTime.Now.AddMinutes(10));
                Response.Redirect("LogList.aspx?AccountNum=" + AccountNum + "&UserID=" + infoUserModel.UserID);
            }
            else
            {
                Response.Write("<div class='alert alert-danger' role='alert'>登录失败</div>");
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Info_User_Model model)
 {
     return(dal.Update(model));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(Info_User_Model model)
 {
     return(dal.Add(model));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 增加一条数据,使用事务的方式
 /// </summary>
 public bool Add(Info_User_Model model, Sys_ProcessLog_Model sysProcessLogModel)
 {
     return(dal.Add(model, sysProcessLogModel));
 }
Ejemplo n.º 13
0
        /*
         * /// <summary>
         * /// 分页获取数据列表
         * /// </summary>
         * public DataSet GetList(int PageSize,int PageIndex,string strWhere)
         * {
         *  SqlParameter[] parameters = {
         *          new SqlParameter("@tblName", SqlDbType.VarChar, 255),
         *          new SqlParameter("@fldName", SqlDbType.VarChar, 255),
         *          new SqlParameter("@PageSize", SqlDbType.Int),
         *          new SqlParameter("@PageIndex", SqlDbType.Int),
         *          new SqlParameter("@IsReCount", SqlDbType.Bit),
         *          new SqlParameter("@OrderType", SqlDbType.Bit),
         *          new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
         *          };
         *  parameters[0].Value = "Info_User";
         *  parameters[1].Value = "UserID";
         *  parameters[2].Value = PageSize;
         *  parameters[3].Value = PageIndex;
         *  parameters[4].Value = 0;
         *  parameters[5].Value = 0;
         *  parameters[6].Value = strWhere;
         *  return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
         * }*/

        #endregion BasicMethod

        #region ExtensionMethod

        /// <summary>
        /// 添加一个用户并且加入日志
        /// </summary>
        public bool Add(Info_User_Model model, Sys_ProcessLog_Model sysProcessLogModel)
        {
            bool result = false;

            // 使用数据库链接
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                //使用事务 开始事务
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into Info_User(");
                        strSql.Append(
                            "UserID,UserName,UserAvatar,UserSex,UserPhone,AccountNum,Pwd,CreateUser,CreateTime,UpdateUser,UpdateTime,IsDelete,Remark)");
                        strSql.Append(" values (");
                        strSql.Append(
                            "@UserID,@UserName,@UserAvatar,@UserSex,@UserPhone,@AccountNum,@Pwd,@CreateUser,@CreateTime,@UpdateUser,@UpdateTime,@IsDelete,@Remark)");
                        // 添加查询结果
                        strSql.Append(";select @UserID;");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@UserID",     SqlDbType.UniqueIdentifier,  16),
                            new SqlParameter("@UserName",   SqlDbType.NVarChar,         255),
                            new SqlParameter("@UserAvatar", SqlDbType.NVarChar,         255),
                            new SqlParameter("@UserSex",    SqlDbType.Int,                4),
                            new SqlParameter("@UserPhone",  SqlDbType.NVarChar,          50),
                            new SqlParameter("@AccountNum", SqlDbType.NVarChar,          50),
                            new SqlParameter("@Pwd",        SqlDbType.NVarChar,         255),
                            new SqlParameter("@CreateUser", SqlDbType.UniqueIdentifier,  16),
                            new SqlParameter("@CreateTime", SqlDbType.DateTime),
                            new SqlParameter("@UpdateUser", SqlDbType.UniqueIdentifier,  16),
                            new SqlParameter("@UpdateTime", SqlDbType.DateTime),
                            new SqlParameter("@IsDelete",   SqlDbType.Bit,                1),
                            new SqlParameter("@Remark",     SqlDbType.NVarChar, 50)
                        };
                        parameters[0].Value = Guid.NewGuid();
                        parameters[1].Value = model.UserName;
                        parameters[2].Value = model.UserAvatar;
                        parameters[3].Value = model.UserSex;
                        parameters[4].Value = model.UserPhone;
                        parameters[5].Value = model.AccountNum;
                        parameters[6].Value = model.Pwd;
                        // parameters[7].Value = Guid.NewGuid();
                        parameters[7].Value = model.CreateUser;

                        parameters[8].Value = model.CreateTime;
                        // parameters[9].Value = Guid.NewGuid();
                        parameters[9].Value = model.UpdateUser;

                        parameters[10].Value = model.UpdateTime;
                        parameters[11].Value = model.IsDelete;
                        parameters[12].Value = model.Remark;


                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters);
                        if (obj != null)
                        {
                            model.UserID = new Guid(Convert.ToString(obj));
                            // 判断想不想要加入日志,如果不想加入日志,可以传null
                            bool processLogResult = true;
                            if (sysProcessLogModel != null)
                            {
                                //添加时要告诉另一个语句用的是,哪一个连接,哪一个事务
                                processLogResult = new Sys_ProcessLog_DAL().Add(conn, trans, sysProcessLogModel);
                            }
                            if (processLogResult)
                            {
                                result = true;
                                trans.Commit();
                            }
                            else
                            {
                                result = false;
                                trans.Rollback();
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        result = false;
                        trans.Rollback();
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Info_User_Model DataRowToModel(DataRow row)
        {
            Info_User_Model model = new Info_User_Model();

            if (row != null)
            {
                if (row["UserID"] != null && row["UserID"].ToString() != "")
                {
                    model.UserID = new Guid(row["UserID"].ToString());
                }

                if (row["UserName"] != null)
                {
                    model.UserName = row["UserName"].ToString();
                }

                if (row["UserAvatar"] != null)
                {
                    model.UserAvatar = row["UserAvatar"].ToString();
                }

                if (row["UserSex"] != null && row["UserSex"].ToString() != "")
                {
                    model.UserSex = int.Parse(row["UserSex"].ToString());
                }

                if (row["UserPhone"] != null)
                {
                    model.UserPhone = row["UserPhone"].ToString();
                }

                if (row["AccountNum"] != null)
                {
                    model.AccountNum = row["AccountNum"].ToString();
                }

                if (row["Pwd"] != null)
                {
                    model.Pwd = row["Pwd"].ToString();
                }

                if (row["CreateUser"] != null && row["CreateUser"].ToString() != "")
                {
                    model.CreateUser = new Guid(row["CreateUser"].ToString());
                }

                if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
                }

                if (row["UpdateUser"] != null && row["UpdateUser"].ToString() != "")
                {
                    model.UpdateUser = new Guid(row["UpdateUser"].ToString());
                }

                if (row["UpdateTime"] != null && row["UpdateTime"].ToString() != "")
                {
                    model.UpdateTime = DateTime.Parse(row["UpdateTime"].ToString());
                }

                if (row["IsDelete"] != null && row["IsDelete"].ToString() != "")
                {
                    if ((row["IsDelete"].ToString() == "1") || (row["IsDelete"].ToString().ToLower() == "true"))
                    {
                        model.IsDelete = true;
                    }
                    else
                    {
                        model.IsDelete = false;
                    }
                }

                if (row["Remark"] != null)
                {
                    model.Remark = row["Remark"].ToString();
                }
            }

            return(model);
        }