Пример #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public book.Model.T_Stock_InItems DataRowToModel(DataRow row)
 {
     book.Model.T_Stock_InItems model = new book.Model.T_Stock_InItems();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["BookId"] != null && row["BookId"].ToString() != "")
         {
             model.BookId = int.Parse(row["BookId"].ToString());
         }
         if (row["HeadId"] != null && row["HeadId"].ToString() != "")
         {
             model.HeadId = int.Parse(row["HeadId"].ToString());
         }
         if (row["Amount"] != null && row["Amount"].ToString() != "")
         {
             model.Amount = int.Parse(row["Amount"].ToString());
         }
         if (row["Discount"] != null && row["Discount"].ToString() != "")
         {
             model.Discount = decimal.Parse(row["Discount"].ToString());
         }
     }
     return model;
 }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(book.Model.T_Stock_InItems model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Stock_InItems(");
            strSql.Append("BookId,HeadId,Amount,Discount)");
            strSql.Append(" values (");
            strSql.Append("@BookId,@HeadId,@Amount,@Discount)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@BookId", SqlDbType.Int,4),
                    new SqlParameter("@HeadId", SqlDbType.Int,4),
                    new SqlParameter("@Amount", SqlDbType.Int,4),
                    new SqlParameter("@Discount", SqlDbType.Decimal,9)};
            parameters[0].Value = model.BookId;
            parameters[1].Value = model.HeadId;
            parameters[2].Value = model.Amount;
            parameters[3].Value = model.Discount;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
Пример #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(book.Model.T_Stock_InItems model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Stock_InItems set ");
            strSql.Append("BookId=@BookId,");
            strSql.Append("HeadId=@HeadId,");
            strSql.Append("Amount=@Amount,");
            strSql.Append("Discount=@Discount");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@BookId", SqlDbType.Int,4),
                    new SqlParameter("@HeadId", SqlDbType.Int,4),
                    new SqlParameter("@Amount", SqlDbType.Int,4),
                    new SqlParameter("@Discount", SqlDbType.Decimal,9),
                    new SqlParameter("@Id", SqlDbType.Int,4)};
            parameters[0].Value = model.BookId;
            parameters[1].Value = model.HeadId;
            parameters[2].Value = model.Amount;
            parameters[3].Value = model.Discount;
            parameters[4].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Пример #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public book.Model.T_Stock_InItems GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Id,BookId,HeadId,Amount,Discount from T_Stock_InItems ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@Id", SqlDbType.Int,4)
            };
            parameters[0].Value = Id;

            book.Model.T_Stock_InItems model = new book.Model.T_Stock_InItems();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }