コード例 #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OLBookstore.Model.TemporaryCart model)
        {
            StringBuilder strSql = new StringBuilder();

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

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

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

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

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (!PageValidate.IsDateTime(txtCreateTime.Text))
            {
                strErr += "CreateTime格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtBookId.Text))
            {
                strErr += "BookId格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtUserId.Text))
            {
                strErr += "UserId格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            DateTime CreateTime = DateTime.Parse(this.txtCreateTime.Text);
            int      BookId     = int.Parse(this.txtBookId.Text);
            int      UserId     = int.Parse(this.txtUserId.Text);

            OLBookstore.Model.TemporaryCart model = new OLBookstore.Model.TemporaryCart();
            model.CreateTime = CreateTime;
            model.BookId     = BookId;
            model.UserId     = UserId;

            OLBookstore.BLL.TemporaryCartManager bll = new OLBookstore.BLL.TemporaryCartManager();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx");
        }
コード例 #4
0
 private void ShowInfo(int Id)
 {
     OLBookstore.BLL.TemporaryCartManager bll   = new OLBookstore.BLL.TemporaryCartManager();
     OLBookstore.Model.TemporaryCart      model = bll.GetModel(Id);
     this.lblCreateTime.Text = model.CreateTime.ToString();
     this.lblBookId.Text     = model.BookId.ToString();
     this.lblUserId.Text     = model.UserId.ToString();
     this.lblId.Text         = model.Id.ToString();
 }
コード例 #5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public OLBookstore.Model.TemporaryCart DataRowToModel(DataRow row)
 {
     OLBookstore.Model.TemporaryCart model = new OLBookstore.Model.TemporaryCart();
     if (row != null)
     {
         if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
         {
             model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
         }
         if (row["BookId"] != null && row["BookId"].ToString() != "")
         {
             model.BookId = int.Parse(row["BookId"].ToString());
         }
         if (row["UserId"] != null && row["UserId"].ToString() != "")
         {
             model.UserId = int.Parse(row["UserId"].ToString());
         }
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
     }
     return(model);
 }
コード例 #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OLBookstore.Model.TemporaryCart GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

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

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

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