Exemplo n.º 1
0
        private void btnSellPay_Click(object sender, EventArgs e)
        {
            if (lvSell.Items.Count == 0)
            {
                MessageBox.Show("Vui lòng thêm hàng");
                return;
            }
            string name    = txtSellName.Text;
            string address = txtSellAddress.Text;
            string phone   = txtSellPhone.Text;

            if (String.IsNullOrWhiteSpace(name))
            {
                MessageBox.Show("Vui lòng nhập tên");
                return;
            }

            if (String.IsNullOrWhiteSpace(address))
            {
                MessageBox.Show("Vui lòng nhập địa chỉ");
            }

            if (!Regex.IsMatch(phone, @"^([\+]?33[-]?|[0])?[1-9][0-9]{8}$"))
            {
                MessageBox.Show("Số điện thoại không hợp lệ");
                return;
            }

            List <BillDetail> billDetails = new List <BillDetail>();

            foreach (ListViewItem item in lvSell.Items)
            {
                BillDetail billDetail = item.Tag as BillDetail;
                billDetails.Add(billDetail);
            }


            Bill bill = new Bill
            {
                Name        = name,
                Address     = address,
                Phone       = phone,
                BillDetails = billDetails,
                Status      = BillStatus.Unprocessed,
                Total       = decimal.Parse(txtSellTotal.Text)
            };

            if (billBUS.Add(bill))
            {
                MessageBox.Show("Thành công");
                lvSell.Items.Clear();
                txtSellTotal.Text = "0";
            }
            else
            {
                MessageBox.Show("Thất bại");
            }
        }