Example #1
0
        public bool DAL_AddProductChosenToDetailOrder(int ID_SellingHistory, DTO_ProductChosen product)
        {
            try
            {
                _conn.Open();

                using (SqlCommand cmd = new SqlCommand("ThemChiTietDonHang", _conn)
                {
                    CommandType = CommandType.StoredProcedure,
                })
                {
                    cmd.Parameters.AddWithValue("@ID_LichSuBanHang", ID_SellingHistory);
                    cmd.Parameters.AddWithValue("@ID_MaSP", product.ProductID);
                    cmd.Parameters.AddWithValue("@SoLuong", product.ProductQuantity);
                    cmd.Parameters.AddWithValue("@DonGia", product.ProductPrice);

                    if (cmd.ExecuteNonQuery() <= 0)
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                _conn.Close();
            }
            return(true);
        }
Example #2
0
        private void BtnPayment_Click(object sender, EventArgs e)
        {
            // thanh toán
            // kiểm tra các trường dữ liệu có bị rỗng hay không
            if (txbCustomerName.Text == "" || txbCustomerID.Text == "" || txbCustomerPhone.Text == "" || txbCustomerAddr.Text == "")
            {
                MessageBox.Show("Các trường dữ liệu không được để rỗng!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // kiểm tra gridview có sản phẩm nào chưa
            if (dtgvShowProduct.Rows.Count == 0)
            {
                MessageBox.Show("Không có sản phẩm nào trong giỏ hàng!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // kiểm tra CMND và số điện thoại có kí tự "lạ" hay không
            if (MySupportMethods.isNumberic(txbCustomerID.Text) == false)
            {
                MessageBox.Show("Chứng minh nhân dân phải là chữ số!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (MySupportMethods.isNumberic(txbCustomerPhone.Text) == false)
            {
                MessageBox.Show("Số điện thoại phải là chữ số!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DialogResult dlgRes = MessageBox.Show("Bạn có muốn thanh toán?", "Thông báo",
                                                  MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dlgRes == DialogResult.Cancel)
            {
                return;
            }

            // đóng gói thông tin khách hàng
            DTO_Customer customer = new DTO_Customer()
            {
                CustomerName    = txbCustomerName.Text,
                CustomerID      = txbCustomerID.Text,
                CustomerPhone   = txbCustomerPhone.Text,
                CustomerAddress = txbCustomerAddr.Text
            };

            // đóng gói lại các sản phẩm được chọn
            List <DTO_ProductChosen> listProductChosen = new List <DTO_ProductChosen>();

            foreach (DataGridViewRow row in dtgvShowProduct.Rows)
            {
                DTO_ProductChosen temp = new DTO_ProductChosen()
                {
                    ProductID       = (int)row.Cells["ProductID"].Value,
                    ProductPrice    = (int)row.Cells["ProductPrice"].Value,
                    ProductQuantity = (int)row.Cells["ProductQuantity"].Value
                };

                listProductChosen.Add(temp);
            }

            BUS_BanHang bus_SellProducts = new BUS_BanHang();

            int TotalPrice = MySupportMethods.StrCurrencyToInt(txbTotalCost.Text);

            // lưu dữ liệu vào database.
            bool res = bus_SellProducts.BUS_InsertNewOrder(customer, listProductChosen, dtpkDateSell.Value, TotalPrice, listPromotion);

            if (res == false)
            {
                MessageBox.Show("Lập phiếu thanh toán thất bại!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Lập phiếu thanh toán thành công!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            this.IsSelling = false;

            EmptyAllFields();

            TurnOnOffFieldsAnhButtons();
        }