Ejemplo n.º 1
0
        private void btnMove_Click(object sender, EventArgs e)
        {
            LapDonHangBLL lapDonHangBLL = new LapDonHangBLL();

            if (check) // là combo
            {
                ObjCombo obj = new ObjCombo();
                obj.Combo = lapDonHangBLL.GetCombo(id);
                if (arr_combo.Count != 0)
                {
                    foreach (ObjCombo a in arr_combo)
                    {
                        if (a.Combo.Id == id)
                        {
                            a.Quantity++;
                            flagfind = true;
                        }
                    }
                    if (flagfind == false)
                    {
                        obj.Quantity = 1;
                        arr_combo.Add(obj);
                    }
                    flagfind = false;
                }
                else
                {
                    obj.Quantity = 1;
                    arr_combo.Add(obj);
                }
            }
            else
            {
                ObjProduct obj = new ObjProduct();
                obj.Product = lapDonHangBLL.GetProduct(id);;
                if (arr_product.Count != 0)
                {
                    foreach (ObjProduct a in arr_product)
                    {
                        if (a.Product.id == id)
                        {
                            a.Quantity++;
                            flagfind = true;
                        }
                    }
                    if (flagfind == false)
                    {
                        obj.Quantity = 1;
                        arr_product.Add(obj);
                    }
                    flagfind = false;
                }
                else
                {
                    obj.Quantity = 1;
                    arr_product.Add(obj);
                }
            }
            LoadListViewSelect();
        }
Ejemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            LapDonHangBLL donHangBLL = new LapDonHangBLL();

            if (newCus)
            {
                donHangBLL.AddKhach(firstname, lastname, phone, address);
            }
            int totalqty = 0;

            foreach (ObjCombo item in arr_combo)
            {
                totalqty += item.Quantity;
                ComboBLL  comboBLL = new ComboBLL();
                ArrayList listid   = comboBLL.ListIDProduct(item.Combo.Id);
                foreach (int a in listid)
                {
                    ProductBLL productBLL = new ProductBLL();
                    productBLL.EditProduct(item.Quantity, a);
                }
            }
            foreach (ObjProduct item in arr_product)
            {
                totalqty += item.Quantity;
                ProductBLL productBLL = new ProductBLL();
                productBLL.EditProduct(item.Quantity, item.Product.id);
            }
            Invoice invoice = new Invoice();

            if (newCus)
            {
                invoice.customer_id = donHangBLL.getIdCustommer();
            }
            else
            {
                invoice.customer_id = idcus;
            }
            invoice.customeraddress = address;
            invoice.totalmoney      = txtThanhtien.Text.Replace(",", "");
            invoice.amount          = totalqty.ToString();
            invoice.creatday        = DateTime.Now;
            invoice.ordernote       = "123";
            invoice.postcode        = "123";
            invoice.status          = "Done";
            donHangBLL.AddInvoice(invoice);
            string products = "";

            if (arr_product.Count != 0)
            {
                products = JsonConvert.SerializeObject(arr_product);
            }
            string combos = "";

            if (arr_combo.Count != 0)
            {
                combos = JsonConvert.SerializeObject(arr_combo);
            }
            donHangBLL.AddInvoiceDetail(products, combos);
            LoadListViewSelect();
            arr_combo   = new ArrayList();
            arr_product = new ArrayList();
            MessageBox.Show("Đã thêm đơn hàng thành công");
        }