Esempio n. 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (!PageValidate.IsDateTime(txtOrderDate.Text))
            {
                strErr += "OrderDate格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtUserId.Text))
            {
                strErr += "UserId格式错误!\\n";
            }
            if (!PageValidate.IsDecimal(txtTotalPrice.Text))
            {
                strErr += "TotalPrice格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            DateTime OrderDate  = DateTime.Parse(this.txtOrderDate.Text);
            int      UserId     = int.Parse(this.txtUserId.Text);
            decimal  TotalPrice = decimal.Parse(this.txtTotalPrice.Text);

            OLBookstore.Model.Orders model = new OLBookstore.Model.Orders();
            model.OrderDate  = OrderDate;
            model.UserId     = UserId;
            model.TotalPrice = TotalPrice;

            OLBookstore.BLL.OrdersManager bll = new OLBookstore.BLL.OrdersManager();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OLBookstore.Model.Orders model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Orders set ");
            strSql.Append("OrderDate=@OrderDate,");
            strSql.Append("UserId=@UserId,");
            strSql.Append("TotalPrice=@TotalPrice");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@OrderDate",  SqlDbType.DateTime),
                new SqlParameter("@UserId",     SqlDbType.Int,       4),
                new SqlParameter("@TotalPrice", SqlDbType.Money,     8),
                new SqlParameter("@Id",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.OrderDate;
            parameters[1].Value = model.UserId;
            parameters[2].Value = model.TotalPrice;
            parameters[3].Value = model.Id;

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

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

            strSql.Append("insert into Orders(");
            strSql.Append("OrderDate,UserId,TotalPrice)");
            strSql.Append(" values (");
            strSql.Append("@OrderDate,@UserId,@TotalPrice)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@OrderDate",  SqlDbType.DateTime),
                new SqlParameter("@UserId",     SqlDbType.Int,4),
                new SqlParameter("@TotalPrice", SqlDbType.Money, 8)
            };
            parameters[0].Value = model.OrderDate;
            parameters[1].Value = model.UserId;
            parameters[2].Value = model.TotalPrice;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 4
0
 private void ShowInfo(int Id)
 {
     OLBookstore.BLL.OrdersManager bll   = new OLBookstore.BLL.OrdersManager();
     OLBookstore.Model.Orders      model = bll.GetModel(Id);
     this.lblId.Text         = model.Id.ToString();
     this.lblOrderDate.Text  = model.OrderDate.ToString();
     this.lblUserId.Text     = model.UserId.ToString();
     this.lblTotalPrice.Text = model.TotalPrice.ToString();
 }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public OLBookstore.Model.Orders DataRowToModel(DataRow row)
 {
     OLBookstore.Model.Orders model = new OLBookstore.Model.Orders();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["OrderDate"] != null && row["OrderDate"].ToString() != "")
         {
             model.OrderDate = DateTime.Parse(row["OrderDate"].ToString());
         }
         if (row["UserId"] != null && row["UserId"].ToString() != "")
         {
             model.UserId = int.Parse(row["UserId"].ToString());
         }
         if (row["TotalPrice"] != null && row["TotalPrice"].ToString() != "")
         {
             model.TotalPrice = decimal.Parse(row["TotalPrice"].ToString());
         }
     }
     return(model);
 }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OLBookstore.Model.Orders GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,OrderDate,UserId,TotalPrice from Orders ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

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

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