コード例 #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.UserLogModel GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 * from " + databaseprefix + "UserLog ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                model = GetModelByDataRow(ds.Tables[0].Rows[0]);
                return(model);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        /// <summary>
        /// 转化为model
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private Model.UserLogModel GetModelByDataRow(DataRow item)
        {
            Model.UserLogModel model = new Model.UserLogModel();
            //[UserID],[UserName],[UserRealName],[ActionType],[Remark],[Ip],[ProjectID],[ProjectName],[ProjectPath],[ClientPath],[AddTime]
            if (item["id"].ToString() != "")
            {
                model.ID = int.Parse(item["id"].ToString());
            }
            if (item["UserID"].ToString() != "")
            {
                model.UserID = int.Parse(item["UserID"].ToString());
            }
            if (item["UserName"].ToString() != "")
            {
                model.UserName = item["UserName"].ToString();
            }
            model.UserRealName = item["UserRealName"].ToString();
            model.ActionType   = item["ActionType"].ToString();
            model.ActionName   = item["ActionName"].ToString();
            model.Remark       = item["Remark"].ToString();
            model.Ip           = item["Ip"].ToString();
            model.ProjectID    = int.Parse(item["ProjectID"].ToString());
            model.ProjectName  = item["ProjectName"].ToString();
            model.ProjectPath  = item["ProjectPath"].ToString();
            model.ClientPath   = item["ClientPath"].ToString();

            if (item["AddTime"].ToString() != "")
            {
                model.AddTime = DateTime.Parse(item["AddTime"].ToString());
            }
            return(model);
        }
コード例 #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.UserLogModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "UserLog(");
            strSql.Append("[UserID],[UserName],[UserRealName],[ActionType],ActionName,[Remark],[Ip],[ProjectID],[ProjectName],[ProjectPath],[ClientPath],[AddTime],[ActionCode])");
            strSql.Append(" values (");
            strSql.Append("@UserID,@UserName,@UserRealName,@ActionType,@ActionName,@Remark,@Ip,@ProjectID,@ProjectName,@ProjectPath,@ClientPath,@AddTime,@ActionCode)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserID",       SqlDbType.Int,          4),
                new SqlParameter("@UserName",     SqlDbType.NVarChar,   100),
                new SqlParameter("@UserRealName", SqlDbType.NVarChar,   100),
                new SqlParameter("@ActionType",   SqlDbType.NVarChar,   100),
                new SqlParameter("@ActionName",   SqlDbType.NVarChar,   100),
                new SqlParameter("@Remark",       SqlDbType.NVarChar,  1000),
                new SqlParameter("@Ip",           SqlDbType.NVarChar,   200),
                new SqlParameter("@ProjectID",    SqlDbType.Int,          4),
                new SqlParameter("@ProjectName",  SqlDbType.NVarChar,   100),
                new SqlParameter("@ProjectPath",  SqlDbType.NVarChar,  2000),
                new SqlParameter("@ClientPath",   SqlDbType.NVarChar,  2000),
                new SqlParameter("@AddTime",      SqlDbType.DateTime),
                new SqlParameter("@ActionCode",   SqlDbType.NVarChar),
                new SqlParameter("@ReturnValue",  SqlDbType.Int)
            };
            parameters[0].Value  = model.UserID;
            parameters[1].Value  = model.UserName;
            parameters[2].Value  = model.UserRealName;
            parameters[3].Value  = model.ActionType;
            parameters[4].Value  = model.ActionName;
            parameters[5].Value  = model.Remark;
            parameters[6].Value  = model.Ip;
            parameters[7].Value  = model.ProjectID;
            parameters[8].Value  = model.ProjectName;
            parameters[9].Value  = model.ProjectPath;
            parameters[10].Value = model.ClientPath;
            parameters[11].Value = model.AddTime;
            parameters[12].Value = model.ActionCode;
            parameters[13].Value = ParameterDirection.Output;

            List <CommandInfo> sqllist = new List <CommandInfo>();
            CommandInfo        cmd     = new CommandInfo(strSql.ToString(), parameters);

            sqllist.Add(cmd);
            DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist);
            int obj = (int)parameters[13].Value;

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #4
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.UserLogModel model)
 {
     return(dal.Add(model));
 }