protected void btnBuy_Click(object sender, EventArgs e) { Member member = (Member)Session["Member"]; CartTable cartTable = new CartTable(); DataTable dt = cartTable.GetCart(member); Sale sale = new Sale(); sale.SaleDate = DateTime.Now; sale.MemberId = member.MemberId; SaleDetail[] details = new SaleDetail[dt.Rows.Count]; for (int i = 0; i < details.Length; i++) { details[i] = new SaleDetail(); details[i].GoodsCode = dt.Rows[i]["GoodsCode"].ToString(); details[i].Num = (int)dt.Rows[i]["Num"]; } sale.Detail = details; SaleTable st = new SaleTable(); int cnt = st.Insert(sale); if (cnt != 0) { cartTable.Delete(member); } Server.Transfer("endmessage.aspx"); }
public int Insert(SaleDetail ditail) { int cnt = 0; string cstr = ConfigurationManager.ConnectionStrings["Db"].ConnectionString; using (SqlConnection connection = new SqlConnection(cstr)) { string sql = "insert into saledetail values(@no,@goodscode,@num)"; SqlCommand command = new SqlCommand(sql, connection); command.Parameters.Add("@no", SqlDbType.Int); command.Parameters["@no"].Value = ditail.SaleNo; command.Parameters.Add("@goodscode", SqlDbType.Char); command.Parameters["@goodscode"].Value = ditail.GoodsCode; command.Parameters.Add("@num", SqlDbType.Int); command.Parameters["@num"].Value = ditail.Num; connection.Open(); cnt = command.ExecuteNonQuery(); connection.Close(); } return(cnt); }