Esempio n. 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(CUSTOMRP.Model.DATABASE model)
        {
            if (String.IsNullOrEmpty(model.HASHKEY))
            {
                model.HASHKEY = "com";
            }

            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into [DATABASE](");
            strSql.Append("APPLICATIONID,NAME,[DESC],STATUS,LASTMODIFYDATE,LASTMODIFYUSER,AUDOTIME,HASHKEY)");
            strSql.Append(" values (");
            strSql.Append("@APPLICATIONID,@NAME,@DESC,@STATUS,@LASTMODIFYDATE,@LASTMODIFYUSER,@AUDOTIME,@HASHKEY)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@APPLICATIONID",  SqlDbType.Int,          4),
                new SqlParameter("@NAME",           SqlDbType.NVarChar,    50),
                new SqlParameter("@DESC",           SqlDbType.NVarChar,  2000),
                new SqlParameter("@STATUS",         SqlDbType.Int,          4),
                new SqlParameter("@LASTMODIFYDATE", SqlDbType.DateTime),
                new SqlParameter("@LASTMODIFYUSER", SqlDbType.Int,          4),
                new SqlParameter("@AUDOTIME",       SqlDbType.DateTime),
                new SqlParameter("@HASHKEY",        SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.APPLICATIONID;
            parameters[1].Value = model.NAME;
            parameters[2].Value = model.DESC;
            parameters[3].Value = model.STATUS;
            parameters[4].Value = model.LASTMODIFYDATE;
            parameters[5].Value = model.LASTMODIFYUSER;
            parameters[6].Value = model.AUDOTIME;
            parameters[7].Value = model.HASHKEY;

            object obj = DbHelperSQL.GetSingle(model.LASTMODIFYUSER, strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                model.ID = Convert.ToInt32(obj);

                Model.AUDITLOG auditobj = model.GetAuditLogObject(null);
                auditobj.UserID      = model.LASTMODIFYUSER;
                auditobj.CreateDate  = DateTime.Now;
                auditobj.MessageType = Model.AUDITLOG.Severity.Audit;
                auditobj.ModuleName  = "DAL.DATABASE.Add";
                auditobj.Message     = String.Format(AppNum.AuditMessage.DatabaseInsertSuccess, model.ID);

                AUDITLOG.Add(auditobj);

                return(model.ID);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CUSTOMRP.Model.DATABASE model)
        {
            if (String.IsNullOrEmpty(model.HASHKEY))
            {
                model.HASHKEY = "com";
            }

            StringBuilder strSql = new StringBuilder();

            strSql.Append("update [DATABASE] set ");
            strSql.Append("APPLICATIONID=@APPLICATIONID,");
            strSql.Append("NAME=@NAME,");
            strSql.Append("[DESC]=@DESC,");
            strSql.Append("STATUS=@STATUS,");
            strSql.Append("LASTMODIFYDATE=@LASTMODIFYDATE,");
            strSql.Append("LASTMODIFYUSER=@LASTMODIFYUSER,");
            strSql.Append("AUDOTIME=@AUDOTIME,");
            strSql.Append("HASHKEY=@HASHKEY");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@APPLICATIONID",  SqlDbType.Int,          4),
                new SqlParameter("@NAME",           SqlDbType.NVarChar,    50),
                new SqlParameter("@DESC",           SqlDbType.NVarChar,  2000),
                new SqlParameter("@STATUS",         SqlDbType.Int,          4),
                new SqlParameter("@LASTMODIFYDATE", SqlDbType.DateTime),
                new SqlParameter("@LASTMODIFYUSER", SqlDbType.Int,          4),
                new SqlParameter("@AUDOTIME",       SqlDbType.DateTime),
                new SqlParameter("@HASHKEY",        SqlDbType.NVarChar,    50),
                new SqlParameter("@ID",             SqlDbType.Int, 4)
            };
            parameters[0].Value = model.APPLICATIONID;
            parameters[1].Value = model.NAME;
            parameters[2].Value = model.DESC;
            parameters[3].Value = model.STATUS;
            parameters[4].Value = model.LASTMODIFYDATE;
            parameters[5].Value = model.LASTMODIFYUSER;
            parameters[6].Value = model.AUDOTIME;
            parameters[7].Value = model.HASHKEY;
            parameters[8].Value = model.ID;

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

            if (rows > 0)
            {
                Model.AUDITLOG auditobj = model.GetAuditLogObject(null);
                auditobj.UserID      = model.LASTMODIFYUSER;
                auditobj.CreateDate  = DateTime.Now;
                auditobj.MessageType = Model.AUDITLOG.Severity.Audit;
                auditobj.ModuleName  = "DAL.DATABASE.Update";
                auditobj.Message     = String.Format(AppNum.AuditMessage.DatabaseUpdateSuccess, model.ID);

                AUDITLOG.Add(auditobj);

                return(true);
            }
            else
            {
                return(false);
            }
        }