Ejemplo n.º 1
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <returns></returns>
        public static bool insert(Trans.Db.Model.NBlock_Error NBlock_Error_obj)
        {
            SqlCommand    cmd        = new SqlCommand();
            StringBuilder cols       = new StringBuilder();
            StringBuilder parameters = new StringBuilder();
            string        sql        = "INSERT INTO NBlock_Error({0}) values({1})";

            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[BlockCode]");
            parameters.Append("@BlockCode");
            if (!string.IsNullOrEmpty(NBlock_Error_obj.BlockCode))
            {
                cmd.Parameters.AddWithValue("@BlockCode", NBlock_Error_obj.BlockCode);
            }
            else
            {
                cmd.Parameters.AddWithValue("@BlockCode", "");
            }
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[Command]");
            parameters.Append("@Command");
            if (!string.IsNullOrEmpty(NBlock_Error_obj.Command))
            {
                cmd.Parameters.AddWithValue("@Command", NBlock_Error_obj.Command);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Command", "");
            }
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[SendTime]");
            parameters.Append("@SendTime");
            if (NBlock_Error_obj.SendTime == null || NBlock_Error_obj.SendTime == DateTime.MinValue)
            {
                cmd.Parameters.AddWithValue("@SendTime", DateTime.Now);
            }
            else
            {
                cmd.Parameters.AddWithValue("@SendTime", NBlock_Error_obj.SendTime);
            }
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[Action]");
            parameters.Append("@Action");
            if (!string.IsNullOrEmpty(NBlock_Error_obj.Action))
            {
                cmd.Parameters.AddWithValue("@Action", NBlock_Error_obj.Action);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Action", "");
            }
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[IsDel]");
            parameters.Append("@IsDel");
            cmd.Parameters.AddWithValue("@IsDel", NBlock_Error_obj.IsDel);
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[CreateTime]");
            parameters.Append("@CreateTime");
            if (NBlock_Error_obj.CreateTime == null || NBlock_Error_obj.CreateTime == DateTime.MinValue)
            {
                cmd.Parameters.AddWithValue("@CreateTime", DateTime.Now);
            }
            else
            {
                cmd.Parameters.AddWithValue("@CreateTime", NBlock_Error_obj.CreateTime);
            }
            sql             = string.Format(sql, cols.ToString(), parameters.ToString());
            cmd.CommandText = sql;
            bool b = true;

            try
            {
                int QueryCount = new Trans.Db.DBUtility.DBHelper(false).ExecNonQuery(cmd);
                if (QueryCount < 1)
                {
                    b = false;
                }
            }
            catch { b = false; }
            return(b);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 插入数据,返回自增列ID
        /// </summary>
        /// <returns></returns>
        public static bool Add(Trans.Db.Model.NBlock_Error NBlock_Error_obj, out Int64 ID)
        {
            ID = 0;
            SqlCommand    cmd        = new SqlCommand();
            StringBuilder cols       = new StringBuilder();
            StringBuilder parameters = new StringBuilder();
            string        sql        = "INSERT INTO NBlock_Error({0}) values({1});SELECT @@IDENTITY;";

            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[BlockCode]");
            parameters.Append("@BlockCode");
            if (!string.IsNullOrEmpty(NBlock_Error_obj.BlockCode))
            {
                cmd.Parameters.AddWithValue("@BlockCode", NBlock_Error_obj.BlockCode);
            }
            else
            {
                cmd.Parameters.AddWithValue("@BlockCode", "");
            }
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[Command]");
            parameters.Append("@Command");
            if (!string.IsNullOrEmpty(NBlock_Error_obj.Command))
            {
                cmd.Parameters.AddWithValue("@Command", NBlock_Error_obj.Command);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Command", "");
            }
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[SendTime]");
            parameters.Append("@SendTime");
            if (NBlock_Error_obj.SendTime == null || NBlock_Error_obj.SendTime == DateTime.MinValue)
            {
                cmd.Parameters.AddWithValue("@SendTime", DateTime.Now);
            }
            else
            {
                cmd.Parameters.AddWithValue("@SendTime", NBlock_Error_obj.SendTime);
            }
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[Action]");
            parameters.Append("@Action");
            if (!string.IsNullOrEmpty(NBlock_Error_obj.Action))
            {
                cmd.Parameters.AddWithValue("@Action", NBlock_Error_obj.Action);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Action", "");
            }
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[IsDel]");
            parameters.Append("@IsDel");
            cmd.Parameters.AddWithValue("@IsDel", NBlock_Error_obj.IsDel);
            if (cols.Length > 0)
            {
                cols.Append(",");
                parameters.Append(",");
            }
            cols.Append("[CreateTime]");
            parameters.Append("@CreateTime");
            if (NBlock_Error_obj.CreateTime == null || NBlock_Error_obj.CreateTime == DateTime.MinValue)
            {
                cmd.Parameters.AddWithValue("@CreateTime", DateTime.Now);
            }
            else
            {
                cmd.Parameters.AddWithValue("@CreateTime", NBlock_Error_obj.CreateTime);
            }
            sql             = string.Format(sql, cols.ToString(), parameters.ToString());
            cmd.CommandText = sql;
            bool b = true;

            try
            {
                object idobj = new Trans.Db.DBUtility.DBHelper(false).ExecScalar(cmd);
                ID = Convert.ToInt64(idobj);
                if (ID == 0)
                {
                    b = false;
                }
            }
            catch { b = false; }
            return(b);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 更新数据,行级数据锁定
        /// 返回:操作影响记录数,-1表示没有需要更新的列
        /// </summary>
        /// <param name="NBlock_Error_obj"></param>
        /// <param name="IsRowLock">是否锁行</param>
        /// <returns></returns>
        public static int Update(Trans.Db.Model.NBlock_Error NBlock_Error_obj, bool IsRowLock)
        {
            if (NBlock_Error_obj.ModifiedColumns.Count <= 0)
            {
                return(-1);
            }
            StringBuilder sqlSet   = new StringBuilder();
            StringBuilder sqlWhere = new StringBuilder();
            string        sql      = string.Empty;

            if (IsRowLock)
            {
                sql = "UPDATE NBlock_Error WITH(ROWLOCK) SET {0} WHERE {1}";
            }
            else
            {
                sql = "UPDATE NBlock_Error SET {0} WHERE {1}";
            }
            SqlCommand cmd = new SqlCommand();

            cmd.Parameters.AddWithValue("@ID", NBlock_Error_obj.ID);
            cmd.Parameters["@ID"].SqlDbType = System.Data.SqlDbType.BigInt;
            if (sqlWhere.Length > 0)
            {
                sqlWhere.Append(" AND ");
            }
            sqlWhere.Append("[ID]=@ID");
            if (NBlock_Error_obj.ModifiedColumns.Contains("[BlockCode]"))
            {
                if (string.IsNullOrEmpty(NBlock_Error_obj.BlockCode))
                {
                    NBlock_Error_obj.BlockCode = "";
                }
                if (sqlSet.Length > 0)
                {
                    sqlSet.Append(",");
                }
                sqlSet.Append("[BlockCode]=@BlockCode");
                cmd.Parameters.AddWithValue("@BlockCode", NBlock_Error_obj.BlockCode);
                cmd.Parameters["@BlockCode"].SqlDbType = System.Data.SqlDbType.NVarChar;
            }
            if (NBlock_Error_obj.ModifiedColumns.Contains("[Command]"))
            {
                if (string.IsNullOrEmpty(NBlock_Error_obj.Command))
                {
                    NBlock_Error_obj.Command = "";
                }
                if (sqlSet.Length > 0)
                {
                    sqlSet.Append(",");
                }
                sqlSet.Append("[Command]=@Command");
                cmd.Parameters.AddWithValue("@Command", NBlock_Error_obj.Command);
                cmd.Parameters["@Command"].SqlDbType = System.Data.SqlDbType.NVarChar;
            }
            if (NBlock_Error_obj.SendTime != null && NBlock_Error_obj.SendTime > DateTime.MinValue && NBlock_Error_obj.ModifiedColumns.Contains("[SendTime]"))
            {
                if (sqlSet.Length > 0)
                {
                    sqlSet.Append(",");
                }
                sqlSet.Append("[SendTime]=@SendTime");
                cmd.Parameters.AddWithValue("@SendTime", NBlock_Error_obj.SendTime);
                cmd.Parameters["@SendTime"].SqlDbType = System.Data.SqlDbType.DateTime2;
            }
            if (NBlock_Error_obj.ModifiedColumns.Contains("[Action]"))
            {
                if (string.IsNullOrEmpty(NBlock_Error_obj.Action))
                {
                    NBlock_Error_obj.Action = "";
                }
                if (sqlSet.Length > 0)
                {
                    sqlSet.Append(",");
                }
                sqlSet.Append("[Action]=@Action");
                cmd.Parameters.AddWithValue("@Action", NBlock_Error_obj.Action);
                cmd.Parameters["@Action"].SqlDbType = System.Data.SqlDbType.NVarChar;
            }
            if (NBlock_Error_obj.ModifiedColumns.Contains("[IsDel]"))
            {
                if (sqlSet.Length > 0)
                {
                    sqlSet.Append(",");
                }
                sqlSet.Append("[IsDel]=@IsDel");
                cmd.Parameters.AddWithValue("@IsDel", NBlock_Error_obj.IsDel);
                cmd.Parameters["@IsDel"].SqlDbType = System.Data.SqlDbType.Int;
            }
            if (NBlock_Error_obj.CreateTime != null && NBlock_Error_obj.CreateTime > DateTime.MinValue && NBlock_Error_obj.ModifiedColumns.Contains("[CreateTime]"))
            {
                if (sqlSet.Length > 0)
                {
                    sqlSet.Append(",");
                }
                sqlSet.Append("[CreateTime]=@CreateTime");
                cmd.Parameters.AddWithValue("@CreateTime", NBlock_Error_obj.CreateTime);
                cmd.Parameters["@CreateTime"].SqlDbType = System.Data.SqlDbType.DateTime2;
            }
            sql             = string.Format(sql, sqlSet.ToString(), sqlWhere.ToString());
            cmd.CommandText = sql;
            try
            {
                return(new Trans.Db.DBUtility.DBHelper(false).ExecNonQuery(cmd));
            }
            catch { return(-1); }
        }