Example #1
0
 /// <summary>
 /// 参数准备
 /// </summary>
 /// <returns></returns>
 public static SqlCommand ParameterElse(SqlCommand cmd, ORM.Test.FreeLink FreeLink_obj)
 {
     if (FreeLink_obj.LinkTitle != null)
     {
         cmd.Parameters.AddWithValue("@LinkTitle", FreeLink_obj.LinkTitle);
         cmd.Parameters["@LinkTitle"].SqlDbType = System.Data.SqlDbType.NVarChar;
     }
     if (FreeLink_obj.LinkContent != null)
     {
         cmd.Parameters.AddWithValue("@LinkContent", FreeLink_obj.LinkContent);
         cmd.Parameters["@LinkContent"].SqlDbType = System.Data.SqlDbType.NVarChar;
     }
     if (FreeLink_obj.LinkDescription != null)
     {
         cmd.Parameters.AddWithValue("@LinkDescription", FreeLink_obj.LinkDescription);
         cmd.Parameters["@LinkDescription"].SqlDbType = System.Data.SqlDbType.NVarChar;
     }
     if (FreeLink_obj.LinkMark != null)
     {
         cmd.Parameters.AddWithValue("@LinkMark", FreeLink_obj.LinkMark);
         cmd.Parameters["@LinkMark"].SqlDbType = System.Data.SqlDbType.NVarChar;
     }
     return(cmd);
 }
Example #2
0
        /// <summary>
        /// 插入数据
        /// </summary>
        /// <returns></returns>
        public static bool insert(ORM.Test.FreeLink FreeLink_obj)
        {
            StringBuilder cols       = new StringBuilder();
            StringBuilder parameters = new StringBuilder();
            string        sql        = "INSERT INTO FreeLink({0}) values({1})";

            if (cols.Length > 0)
            {
                cols.Append(",[LinkTitle]");
                parameters.Append(",@LinkTitle");
            }
            else
            {
                cols.Append("[LinkTitle]");
                parameters.Append("@LinkTitle");
            }
            if (cols.Length > 0)
            {
                cols.Append(",[LinkContent]");
                parameters.Append(",@LinkContent");
            }
            else
            {
                cols.Append("[LinkContent]");
                parameters.Append("@LinkContent");
            }
            if (cols.Length > 0)
            {
                cols.Append(",[LinkDescription]");
                parameters.Append(",@LinkDescription");
            }
            else
            {
                cols.Append("[LinkDescription]");
                parameters.Append("@LinkDescription");
            }
            if (cols.Length > 0)
            {
                cols.Append(",[LinkMark]");
                parameters.Append(",@LinkMark");
            }
            else
            {
                cols.Append("[LinkMark]");
                parameters.Append("@LinkMark");
            }
            sql = string.Format(sql, cols.ToString(), parameters.ToString());
            SqlCommand cmd = new SqlCommand(sql);

            cmd = ParameterElse(cmd, FreeLink_obj);
            bool b = true;

            try
            {
                int QueryCount = new ORM.DBUtility.DBHelper(true).ExecNonQuery(cmd);
                if (QueryCount != 1)
                {
                    b = false;
                }
            }
            catch { b = false; }
            return(b);
        }
Example #3
0
        /// <summary>
        /// 插入数据,返回自增列ID
        /// </summary>
        /// <returns></returns>
        public static bool Add(ORM.Test.FreeLink FreeLink_obj, out Int32 ID)
        {
            ID = 0;
            StringBuilder cols       = new StringBuilder();
            StringBuilder parameters = new StringBuilder();
            string        sql        = "INSERT INTO FreeLink({0}) values({1});SELECT @@IDENTITY;";

            if (cols.Length > 0)
            {
                cols.Append(",[LinkTitle]");
                parameters.Append(",@LinkTitle");
            }
            else
            {
                cols.Append("[LinkTitle]");
                parameters.Append("@LinkTitle");
            }
            if (cols.Length > 0)
            {
                cols.Append(",[LinkContent]");
                parameters.Append(",@LinkContent");
            }
            else
            {
                cols.Append("[LinkContent]");
                parameters.Append("@LinkContent");
            }
            if (cols.Length > 0)
            {
                cols.Append(",[LinkDescription]");
                parameters.Append(",@LinkDescription");
            }
            else
            {
                cols.Append("[LinkDescription]");
                parameters.Append("@LinkDescription");
            }
            if (cols.Length > 0)
            {
                cols.Append(",[LinkMark]");
                parameters.Append(",@LinkMark");
            }
            else
            {
                cols.Append("[LinkMark]");
                parameters.Append("@LinkMark");
            }
            sql = string.Format(sql, cols.ToString(), parameters.ToString());
            SqlCommand cmd = new SqlCommand(sql);

            cmd = ParameterElse(cmd, FreeLink_obj);
            bool b = true;

            try
            {
                object idobj = new ORM.DBUtility.DBHelper(true).ExecScalar(cmd);
                ID = Convert.ToInt32(idobj);
                if (ID == 0)
                {
                    b = false;
                }
            }
            catch { b = false; }
            return(b);
        }
Example #4
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="FreeLink_obj"></param>
        /// <param name="IsRowLock">是否锁行</param>
        /// <returns></returns>
        public static int Update(ORM.Test.FreeLink FreeLink_obj, bool IsRowLock)
        {
            StringBuilder sqlSet   = new StringBuilder();
            StringBuilder sqlWhere = new StringBuilder();
            string        sql      = string.Empty;

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

            cmd.Parameters.AddWithValue("@ID", FreeLink_obj.ID);
            cmd.Parameters["@ID"].SqlDbType = System.Data.SqlDbType.Int;
            if (sqlWhere.Length == 0)
            {
                sqlWhere.Append("[ID]=@ID");
            }
            else
            {
                sqlWhere.Append(" AND [ID]=@ID");
            }
            if (FreeLink_obj.LinkTitle != null)
            {
                cmd.Parameters.AddWithValue("@LinkTitle", FreeLink_obj.LinkTitle);
                cmd.Parameters["@LinkTitle"].SqlDbType = System.Data.SqlDbType.NVarChar;
                if (sqlSet.Length == 0)
                {
                    sqlSet.Append("[LinkTitle]=@LinkTitle");
                }
                else
                {
                    sqlSet.Append(",[LinkTitle]=@LinkTitle");
                }
            }
            if (FreeLink_obj.LinkContent != null)
            {
                cmd.Parameters.AddWithValue("@LinkContent", FreeLink_obj.LinkContent);
                cmd.Parameters["@LinkContent"].SqlDbType = System.Data.SqlDbType.NVarChar;
                if (sqlSet.Length == 0)
                {
                    sqlSet.Append("[LinkContent]=@LinkContent");
                }
                else
                {
                    sqlSet.Append(",[LinkContent]=@LinkContent");
                }
            }
            if (FreeLink_obj.LinkDescription != null)
            {
                cmd.Parameters.AddWithValue("@LinkDescription", FreeLink_obj.LinkDescription);
                cmd.Parameters["@LinkDescription"].SqlDbType = System.Data.SqlDbType.NVarChar;
                if (sqlSet.Length == 0)
                {
                    sqlSet.Append("[LinkDescription]=@LinkDescription");
                }
                else
                {
                    sqlSet.Append(",[LinkDescription]=@LinkDescription");
                }
            }
            if (FreeLink_obj.LinkMark != null)
            {
                cmd.Parameters.AddWithValue("@LinkMark", FreeLink_obj.LinkMark);
                cmd.Parameters["@LinkMark"].SqlDbType = System.Data.SqlDbType.NVarChar;
                if (sqlSet.Length == 0)
                {
                    sqlSet.Append("[LinkMark]=@LinkMark");
                }
                else
                {
                    sqlSet.Append(",[LinkMark]=@LinkMark");
                }
            }
            sql             = string.Format(sql, sqlSet.ToString(), sqlWhere.ToString());
            cmd.CommandText = sql;
            try
            {
                return(new ORM.DBUtility.DBHelper(true).ExecNonQuery(cmd));
            }
            catch { return(-1); }
        }