Beispiel #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Tc.Model.TcZidian model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update TcZidian set ");
            strSql.Append("Name=@Name,");
            strSql.Append("Types=@Types,");
            strSql.Append("Paixu=@Paixu,");
            strSql.Append("Pid=@Pid");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name",  SqlDbType.VarChar, 255),
                new SqlParameter("@Types", SqlDbType.VarChar, 255),
                new SqlParameter("@Paixu", SqlDbType.Int,       4),
                new SqlParameter("@Pid",   SqlDbType.Int,       4),
                new SqlParameter("@ID",    SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.Types;
            parameters[2].Value = model.Paixu;
            parameters[3].Value = model.Pid;
            parameters[4].Value = model.ID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Tc.Model.TcZidian model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into TcZidian(");
            strSql.Append("Name,Types,Paixu,Pid)");
            strSql.Append(" values (");
            strSql.Append("@Name,@Types,@Paixu,@Pid)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name",  SqlDbType.VarChar, 255),
                new SqlParameter("@Types", SqlDbType.VarChar, 255),
                new SqlParameter("@Paixu", SqlDbType.Int,       4),
                new SqlParameter("@Pid",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.Types;
            parameters[2].Value = model.Paixu;
            parameters[3].Value = model.Pid;

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

            if (rows > 0)
            {
                return(GetMaxId());
            }
            else
            {
                return(0);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Tc.Model.TcZidian DataRowToModel(DataRow row)
 {
     Tc.Model.TcZidian model = new Tc.Model.TcZidian();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["Name"] != null)
         {
             model.Name = row["Name"].ToString();
         }
         if (row["Types"] != null)
         {
             model.Types = row["Types"].ToString();
         }
         if (row["Paixu"] != null && row["Paixu"].ToString() != "")
         {
             model.Paixu = int.Parse(row["Paixu"].ToString());
         }
         if (row["Pid"] != null && row["Pid"].ToString() != "")
         {
             model.Pid = int.Parse(row["Pid"].ToString());
         }
     }
     return(model);
 }
Beispiel #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Tc.Model.TcZidian model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into TcZidian(");
            strSql.Append("Name,Types,Paixu,Pid)");
            strSql.Append(" values (");
            strSql.Append("@Name,@Types,@Paixu,@Pid)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name",  SqlDbType.NVarChar, 100),
                new SqlParameter("@Types", SqlDbType.NVarChar,  50),
                new SqlParameter("@Paixu", SqlDbType.Int,        4),
                new SqlParameter("@Pid",   SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Name;
            parameters[1].Value = model.Types;
            parameters[2].Value = model.Paixu;
            parameters[3].Value = model.Pid;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Tc.Model.TcZidian GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ID,Name,Types,Paixu,Pid from TcZidian ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            Tc.Model.TcZidian model = new Tc.Model.TcZidian();
            DataSet           ds    = DbHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }