예제 #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string        LogsTitle   = TextBox1.Text;
            string        LogsContent = TextArea1.Value;
            Info_Logs_BLL infoLogsBll = new Info_Logs_BLL();

            if (LogsID != null)
            {
                Info_Logs_Model infoLogsModel = infoLogsBll.GetModel(new Guid(LogsID));
                // 更新
                infoLogsModel.LogsTitle   = LogsTitle;
                infoLogsModel.LogsContent = LogsContent;
                infoLogsModel.isDelete    = false;
                infoLogsModel.UpdateTime  = DateTime.Now;
                infoLogsModel.UpdateUser  = infoLogsModel.CreateUser;

                // 添加日志
                Sys_ProcessLog_Model sysProcessLogModel = new Sys_ProcessLog_Model();
                sysProcessLogModel.ID             = Guid.NewGuid();
                sysProcessLogModel.LogType        = (int)SystemLogType.LogsAdd;
                sysProcessLogModel.LogDescription = "更新了一条日志";
                sysProcessLogModel.CreateUser     = new Guid(UserID);
                sysProcessLogModel.CreateTime     = DateTime.Now;


                bool result = infoLogsBll.Update(infoLogsModel, sysProcessLogModel);
                if (result)
                {
                    Response.Write("更新成功");
                    Response.Redirect("LogList.aspx?LogsID=" + LogsID + "&AccountNum=" + AccountNum + "&UserID=" + UserID);
                }
            }
            // 为空.添加
            if (UserID != null)
            {
                // 两种写法
                Info_Logs_Model infoLogsModel = new Info_Logs_Model()
                {
                    LogsTitle   = LogsTitle,
                    LogsContent = LogsContent,
                    isDelete    = false,
                    CreateTime  = DateTime.Now,
                    CreateUser  = new Guid(UserID)
                };
                // 添加日志
                Sys_ProcessLog_Model sysProcessLogModel = new Sys_ProcessLog_Model();
                sysProcessLogModel.ID             = Guid.NewGuid();
                sysProcessLogModel.LogType        = (int)SystemLogType.LogsAdd;
                sysProcessLogModel.LogDescription = "添加了一条日志";
                sysProcessLogModel.CreateUser     = new Guid(UserID);
                sysProcessLogModel.CreateTime     = DateTime.Now;
                bool result = infoLogsBll.Add(infoLogsModel, sysProcessLogModel);
                if (result)
                {
                    Response.Write("添加成功");
                    Response.Redirect("LogList.aspx?LogsID=" + LogsID + "&AccountNum=" + AccountNum + "&UserID=" + UserID);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_ProcessLog_Model DataRowToModel(DataRow row)
        {
            Sys_ProcessLog_Model model = new Sys_ProcessLog_Model();

            if (row != null)
            {
                if (row["ID"] != null && row["ID"].ToString() != "")
                {
                    model.ID = new Guid(row["ID"].ToString());
                }
                if (row["LogType"] != null && row["LogType"].ToString() != "")
                {
                    model.LogType = int.Parse(row["LogType"].ToString());
                }
                if (row["LogDescription"] != null)
                {
                    model.LogDescription = row["LogDescription"].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["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);
        }
예제 #3
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("添加失败,请联系管理员");
            }
        }
예제 #4
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Sys_ProcessLog_Model model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Sys_ProcessLog set ");
            strSql.Append("LogType=@LogType,");
            strSql.Append("LogDescription=@LogDescription,");
            strSql.Append("CreateUser=@CreateUser,");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("IsDelete=@IsDelete,");
            strSql.Append("Remark=@Remark");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@LogType",        SqlDbType.Int,               4),
                new SqlParameter("@LogDescription", SqlDbType.NVarChar,         50),
                new SqlParameter("@CreateUser",     SqlDbType.UniqueIdentifier, 16),
                new SqlParameter("@CreateTime",     SqlDbType.DateTime),
                new SqlParameter("@IsDelete",       SqlDbType.Bit,               1),
                new SqlParameter("@Remark",         SqlDbType.NVarChar,         50),
                new SqlParameter("@ID",             SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value = model.LogType;
            parameters[1].Value = model.LogDescription;
            parameters[2].Value = model.CreateUser;
            parameters[3].Value = model.CreateTime;
            parameters[4].Value = model.IsDelete;
            parameters[5].Value = model.Remark;
            parameters[6].Value = model.ID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #5
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Sys_ProcessLog_Model model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Sys_ProcessLog(");
            strSql.Append("ID,LogType,LogDescription,CreateUser,CreateTime,IsDelete,Remark)");
            strSql.Append(" values (");
            strSql.Append("@ID,@LogType,@LogDescription,@CreateUser,@CreateTime,@IsDelete,@Remark)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID",             SqlDbType.UniqueIdentifier, 16),
                new SqlParameter("@LogType",        SqlDbType.Int,               4),
                new SqlParameter("@LogDescription", SqlDbType.NVarChar,         50),
                new SqlParameter("@CreateUser",     SqlDbType.UniqueIdentifier, 16),
                new SqlParameter("@CreateTime",     SqlDbType.DateTime),
                new SqlParameter("@IsDelete",       SqlDbType.Bit,               1),
                new SqlParameter("@Remark",         SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = Guid.NewGuid();
            parameters[1].Value = model.LogType;
            parameters[2].Value = model.LogDescription;
            parameters[3].Value = model.CreateUser;
            parameters[4].Value = model.CreateTime;
            parameters[5].Value = model.IsDelete;
            parameters[6].Value = model.Remark;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_ProcessLog_Model GetModel(Guid ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,LogType,LogDescription,CreateUser,CreateTime,IsDelete,Remark from Sys_ProcessLog ");
            strSql.Append(" where ID=@ID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.UniqueIdentifier, 16)
            };
            parameters[0].Value = ID;

            Sys_ProcessLog_Model model = new Sys_ProcessLog_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);
            }
        }
예제 #7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Sys_ProcessLog_Model model)
 {
     return(dal.Update(model));
 }
예제 #8
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(Sys_ProcessLog_Model model)
 {
     return(dal.Add(model));
 }
예제 #9
0
        /// <summary>
        /// 更新一条数据,使用事务
        /// </summary>
        public bool Update(Info_Logs_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("update Info_Logs set ");
                        strSql.Append("LogsTitle=@LogsTitle,");
                        strSql.Append("LogsContent=@LogsContent,");
                        strSql.Append("CoverPictureUrl=@CoverPictureUrl,");
                        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 LogsID=@LogsID ");
                        strSql.Append(";select @LogsID;");

                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@LogsTitle",       SqlDbType.NVarChar,          50),
                            new SqlParameter("@LogsContent",     SqlDbType.NVarChar,          -1),
                            new SqlParameter("@CoverPictureUrl", 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("@LogsID",          SqlDbType.UniqueIdentifier, 16)
                        };
                        parameters[0].Value = model.LogsTitle;
                        parameters[1].Value = model.LogsContent;
                        parameters[2].Value = model.CoverPictureUrl;
                        parameters[3].Value = model.CreateUser;
                        parameters[4].Value = model.CreateTime;
                        parameters[5].Value = model.UpdateUser;
                        parameters[6].Value = model.UpdateTime;
                        parameters[7].Value = model.isDelete;
                        parameters[8].Value = model.Remark;
                        parameters[9].Value = model.LogsID;

                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters);
                        if (obj != null)
                        {
                            model.LogsID = 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);
        }
예제 #10
0
 /// <summary>
 /// 更新一条数据,使用事务
 /// </summary>
 public bool Update(Info_Logs_Model model, Sys_ProcessLog_Model sysProcessLogModel)
 {
     return(dal.Update(model, sysProcessLogModel));
 }
예제 #11
0
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion BasicMethod

        #region ExtensionMethod

        /// <summary>
        /// 增加一条数据,使用事务
        /// </summary>
        public bool Add(Info_Logs_Model model, Sys_ProcessLog_Model sysProcessLogModel)
        {
            return(dal.Add(model, sysProcessLogModel));
        }
예제 #12
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);
        }