Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(guanbingking.Model.OrderProduct model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update OrderProduct set ");
            strSql.Append("ProductName=@ProductName,");
            strSql.Append("ProductClass=@ProductClass,");
            strSql.Append("Unit=@Unit,");
            strSql.Append("Price=@Price,");
            strSql.Append("Cost=@Cost,");
            strSql.Append("Spec=@Spec,");
            strSql.Append("ProductCount=@ProductCount,");
            strSql.Append("OrderId=@OrderId");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ProductName",  SqlDbType.VarChar,   1),
                new SqlParameter("@ProductClass", SqlDbType.Int,       4),
                new SqlParameter("@Unit",         SqlDbType.VarChar,   1),
                new SqlParameter("@Price",        SqlDbType.Money,     8),
                new SqlParameter("@Cost",         SqlDbType.Money,     8),
                new SqlParameter("@Spec",         SqlDbType.VarChar, 255),
                new SqlParameter("@ProductCount", SqlDbType.Int,       4),
                new SqlParameter("@OrderId",      SqlDbType.Int,       4),
                new SqlParameter("@Id",           SqlDbType.Int, 4)
            };
            parameters[0].Value = model.ProductName;
            parameters[1].Value = model.ProductClass;
            parameters[2].Value = model.Unit;
            parameters[3].Value = model.Price;
            parameters[4].Value = model.Cost;
            parameters[5].Value = model.Spec;
            parameters[6].Value = model.ProductCount;
            parameters[7].Value = model.OrderId;
            parameters[8].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public guanbingking.Model.OrderProduct DataRowToModel(DataRow row)
 {
     guanbingking.Model.OrderProduct model = new guanbingking.Model.OrderProduct();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["ProductName"] != null)
         {
             model.ProductName = row["ProductName"].ToString();
         }
         if (row["ProductClass"] != null && row["ProductClass"].ToString() != "")
         {
             model.ProductClass = int.Parse(row["ProductClass"].ToString());
         }
         if (row["Unit"] != null)
         {
             model.Unit = row["Unit"].ToString();
         }
         if (row["Price"] != null && row["Price"].ToString() != "")
         {
             model.Price = decimal.Parse(row["Price"].ToString());
         }
         if (row["Cost"] != null && row["Cost"].ToString() != "")
         {
             model.Cost = decimal.Parse(row["Cost"].ToString());
         }
         if (row["Spec"] != null)
         {
             model.Spec = row["Spec"].ToString();
         }
         if (row["ProductCount"] != null && row["ProductCount"].ToString() != "")
         {
             model.ProductCount = int.Parse(row["ProductCount"].ToString());
         }
         if (row["OrderId"] != null && row["OrderId"].ToString() != "")
         {
             model.OrderId = int.Parse(row["OrderId"].ToString());
         }
     }
     return(model);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(guanbingking.Model.OrderProduct model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into OrderProduct(");
            strSql.Append("Id,ProductName,ProductClass,Unit,Price,Cost,Spec,ProductCount,OrderId)");
            strSql.Append(" values (");
            strSql.Append("@Id,@ProductName,@ProductClass,@Unit,@Price,@Cost,@Spec,@ProductCount,@OrderId)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id",           SqlDbType.Int,       4),
                new SqlParameter("@ProductName",  SqlDbType.VarChar,   1),
                new SqlParameter("@ProductClass", SqlDbType.Int,       4),
                new SqlParameter("@Unit",         SqlDbType.VarChar,   1),
                new SqlParameter("@Price",        SqlDbType.Money,     8),
                new SqlParameter("@Cost",         SqlDbType.Money,     8),
                new SqlParameter("@Spec",         SqlDbType.VarChar, 255),
                new SqlParameter("@ProductCount", SqlDbType.Int,       4),
                new SqlParameter("@OrderId",      SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Id;
            parameters[1].Value = model.ProductName;
            parameters[2].Value = model.ProductClass;
            parameters[3].Value = model.Unit;
            parameters[4].Value = model.Price;
            parameters[5].Value = model.Cost;
            parameters[6].Value = model.Spec;
            parameters[7].Value = model.ProductCount;
            parameters[8].Value = model.OrderId;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public guanbingking.Model.OrderProduct GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,ProductName,ProductClass,Unit,Price,Cost,Spec,ProductCount,OrderId from OrderProduct ");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

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

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