Exemplo n.º 1
0
        //Add to Cart
        private void addToCart_bt_Click(object sender, EventArgs e)
        {
            try
            {
                if (medId_tb.Text == "" || medName_tb.Text == "" || unitPrice_tb.Text == "" || quantity_tb.Text == "" || amount_tb.Text == "")
                {
                    MessageBox.Show("You need to add first");
                }
                else
                {
                    pursServ = new PurchaseService();
                    pur      = pursServ.Check(Convert.ToInt32(medId_tb.Text), Convert.ToInt32(saleId_tb.Text));
                    if (pur != null)
                    {
                        pur.Quantity = pur.Quantity + Convert.ToInt32(quantity_tb.Text);
                        pur.Amount   = pur.Amount + Convert.ToDouble(amount_tb.Text);

                        PurchaseService pursSer = new PurchaseService();
                        int             rs      = pursSer.UpdateCart(pur);
                    }
                    else
                    {
                        pur           = new Purchase();
                        pur.SaleId    = Convert.ToInt32(saleId_tb.Text);
                        pur.MedId     = Convert.ToInt32(medId_tb.Text);
                        pur.MedName   = medName_tb.Text;
                        pur.UnitPrice = Convert.ToDouble(unitPrice_tb.Text);
                        pur.Quantity  = Convert.ToInt32(quantity_tb.Text);
                        pur.Amount    = Convert.ToDouble(amount_tb.Text);
                        PurchaseService pursSer = new PurchaseService();
                        int             result  = pursSer.AddToCart(pur);
                    }
                    pursServ             = new PurchaseService();
                    cartTable.DataSource = pursServ.GetAll(pur.SaleId);
                }
                medId_tb.Text = ""; medName_tb.Text = ""; unitPrice_tb.Text = ""; quantity_tb.Text = ""; amount_tb.Text = "";
            }
            catch (Exception ex) { MessageBox.Show(ex.StackTrace); }
        }