Example #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     errorProvider1.Clear();
     if (txtTenKhachHang.Text == "" || txtSDT.Text == "" || txtEmail.Text == "" || txtDiaChi.Text == "")
     {
         MessageBox.Show("Dữ liệu chưa đủ.", "Thông Báo");
         // bắt lỗi
         if (txtTenKhachHang.Text == "")
         {
             errorProvider1.SetError(txtTenKhachHang, "Chưa điền tên Khách Hàng");
         }
         if (txtSDT.Text == "")
         {
             errorProvider1.SetError(txtSDT, "Chưa điền SĐT");
         }
         if (txtEmail.Text == "")
         {
             errorProvider1.SetError(txtEmail, "Chưa điền email");
         }
         if (txtDiaChi.Text == "")
         {
             errorProvider1.SetError(txtDiaChi, "Chưa điền địa chỉ");
         }
     }
     else
     {
         if (chucnang == 1) // Nút thêm
         {
             {
                 SQL_ThongTin.Add_KhachHang(txtSDT.Text, txtTenKhachHang.Text, txtDiaChi.Text, txtEmail.Text);
                 BatDau();
             }
         }
         if (chucnang == 2)// nút sửa
         {
             SQL_ThongTin.Edit__KhachHang(txtMaKhachHang.Text, txtSDT.Text, txtTenKhachHang.Text, txtDiaChi.Text, txtEmail.Text);
             BatDau();
         }
     }
 }
Example #2
0
        private void btnThanhToan_Click(object sender, EventArgs e)
        {
            string MaKH;
            string MaHD;

            if (txtSDT.Text == "" || txtTenKH.Text == "" || txtEmail.Text == "" || txtDiaChi.Text == "" || txtMaNV.Text == "" || int.Parse(txtTongTien.Text) < 1)
            {
                /// báo lỗi
                MessageBox.Show("Lỗi dữ liệu.", "Thông báo");
                if (txtTenKH.Text == "")
                {
                    errorProvider1.SetError(txtTenKH, "chưa điền tên khách hàng.");
                }
                if (txtSDT.Text == "")
                {
                    errorProvider1.SetError(txtSDT, "chưa điền sđt khách hàng.");
                }
                if (txtDiaChi.Text == "")
                {
                    errorProvider1.SetError(txtDiaChi, "chưa điền địa chỉ.");
                }
                if (txtEmail.Text == "")
                {
                    errorProvider1.SetError(txtEmail, "chưa điền email.");
                }
                if (txtMaNV.Text == "")
                {
                    errorProvider1.SetError(cbbNhanVien, "chưa chọn nhân viên.");
                }
                if (int.Parse(txtTongTien.Text) < 1)
                {
                    errorProvider1.SetError(txtTongTien, "Chưa có thông tin mặt hàng.");
                }
                return;
            }
            else
            {
                /// lưu thông tin khách hàng
                if (khachhangcu == false)
                {
                    /// add
                    SQL_ThongTin.Add_KhachHang(txtSDT.Text, txtTenKH.Text, txtDiaChi.Text, txtEmail.Text);
                    /// lấy ra mã khách hàng của thằng khách hàng vừa add (ở vị trí cuối cùng)
                    DataTable khachhang = SQL_ThongTin.Display_KhachHang();
                    MaKH = khachhang.Rows[khachhang.Rows.Count - 1][0].ToString();
                    // }
                }
                else
                {
                    /// lấy mã KH cũ để tạo hóa đơn
                    MaKH = txtMaKH.Text;
                }

                /// lưu thông tin hóa đơn
                /// Add
                SQL_BanHang.Add_HoaDon(txtMaNV.Text, MaKH, DateTime.Now.ToString("yyyy-MM-dd"), decimal.Parse(txtTongTien.Text));
                /// lấy ra mã hóa đơn  vừa add (ở vị trí cuối cùng)
                DataTable hoadon = SQL_BanHang.Display_HoaDon();
                MaHD = hoadon.Rows[hoadon.Rows.Count - 1][0].ToString();
                // }
                /// lưu thông tin chi tiết hóa đơn
                for (int i = 0; i < listView1.Items.Count; i++)
                {
                    SQL_BanHang.Add_ChiTietHoaDon(MaHD, listView1.Items[i].SubItems[1].Text, int.Parse(listView1.Items[i].SubItems[3].Text), decimal.Parse(listView1.Items[i].SubItems[5].Text));
                }
            }
            MessageBox.Show("Thêm Hóa đơn thành công.");

            /// In Hoa Don
            gridView1.BestFitColumns();
            HoaDonBanHang report = new HoaDonBanHang();

            report.ListViewControl = listView1;
            // set thuộc tính
            string ngaythang = "Ngày " + DateTime.Now.Day.ToString() + " tháng " + DateTime.Now.Month.ToString() + " năm " + DateTime.Now.Year.ToString();

            report.SetProperties(cbbNhanVien.Text, MaHD, MaKH, txtTenKH.Text, txtSDT.Text, txtEmail.Text, txtDiaChi.Text, txtTongTien.Text, ngaythang);

            //thu nhỏ hóa đơn
            report.PaperKind = System.Drawing.Printing.PaperKind.Statement;
            report.Landscape = true;

            ReportPrintTool printTool = new ReportPrintTool(report);

            printTool.ShowPreviewDialog();
        }