Esempio n. 1
0
        private void btnThemMoi_Click(object sender, EventArgs e)
        {
            MoKhoaDieuKhien();

            dENgayLap.Text = DateTime.Now.ToString();
            hdObj          = new HoaDon();
            try
            {
                hdObj.MAKH = int.Parse(luKhachHang.EditValue.ToString());
            }
            catch { hdObj.MAKH = 0; }
            hdObj.MAHD     = DateTime.Now.ToString("yyyyMMddhhmmss");
            hdObj.NGAYLAP  = DateTime.Parse(dENgayLap.Text.ToString());
            hdObj.MANV     = nvObj.MANV;
            hdObj.TONGTIEN = 0;


            hdBus.Insert(hdObj);
            hdObj = hdBus.GetNewHoaDon();
        }
        private void btnThanhToan_Click(object sender, EventArgs e)
        {
            DialogResult dr = XtraMessageBox.Show("Bạn có chắc chắn thanh toán hóa đơn này không?", "Xác nhận thanh toán",
                                                  MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (dr == DialogResult.Yes)
            {
                /* Remind user to choose customer */
                if (cbbKhachHang.Text == string.Empty)
                {
                    XtraMessageBox.Show("Bạn chưa chọn khách hàng thanh toán", "Thông báo", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    return;
                }
                tien  = 0;
                count = 0;
                /* Save data HoaDon */
                hoadon.MaNhanVien  = MaNhanVien;
                hoadon.NgayLap     = DateTime.Today;
                hoadon.MaKhachHang = int.Parse(cbbKhachHang.EditValue.ToString());
                hoadon.TongTien    = int.Parse(txtTongTien.Text);
                /* Print receipt implement */
                if (hoaDonBus.Insert(hoadon) > 0)
                {
                    DialogResult tt = XtraMessageBox.Show("Hóa đơn đã được lưu. Bạn có muốn in phiếu thanh toán không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (tt == DialogResult.Yes)
                    {
                        try
                        {
                            for (int i = 0; i < gridView2.RowCount; i++)
                            {
                                /* Save data ChiTietHoaDon */
                                cthd.MaHoaDon = hoaDonBus.GetHoaDonId();
                                cthd.MaXe     = gridView2.GetRowCellValue(i, gridView2.Columns["MaXe"]).ToString();
                                cthd.MauSac   = gridView2.GetRowCellValue(i, gridView2.Columns["MauSac"]).ToString();
                                cthd.SoLuong  =
                                    int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["SoLuong"]).ToString());
                                cthd.DonGia = int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["DonGia"]).ToString());
                                cthdBus.Insert(cthd);

                                /* Update number of product attribute after paying bill */
                                int a = int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["LuongTon"]).ToString());
                                int b = int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["SoLuong"]).ToString());
                                thuoctinh.MaXe =
                                    gridView2.GetRowCellValue(i, gridView2.Columns["MaXe"]).ToString();
                                thuoctinh.SoLuong = a - b;
                                thuoctinh.MauSac  = gridView2.GetRowCellValue(i, gridView2.Columns["MauSac"]).ToString();
                                thuocTinhBus.Update_SoLuong(thuoctinh);

                                /* Update number of product after paying bill */
                                int c = int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["LuongTonXe"]).ToString());
                                xe.LuongTon = c - b;
                                xe.MaXe     =
                                    gridView2.GetRowCellValue(i, gridView2.Columns["MaXe"]).ToString();
                                xeBus.Update_SoLuong(xe);
                            }
                            /* Print receipt */
                            Print();
                            /* Refresh the database in gridView after purchased */
                            DisplayThuocTinh();
                            DisplayXe();
                            Clear();
                            LockControl();
                            btnThem.Enabled = true;
                            XtraMessageBox.Show("Thanh toán thành công", "Thông báo", MessageBoxButtons.OK,
                                                MessageBoxIcon.Information);
                        }
                        catch
                        {
                            XtraMessageBox.Show("Lỗi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        try
                        {
                            tien  = 0;
                            count = 0;
                            for (int i = 0; i < gridView2.RowCount; i++)
                            {
                                /* Save data ChiTietHoaDon */
                                cthd.MaHoaDon = hoaDonBus.GetHoaDonId();
                                cthd.MaXe     = gridView2.GetRowCellValue(i, gridView2.Columns["MaXe"]).ToString();
                                cthd.MauSac   = gridView2.GetRowCellValue(i, gridView2.Columns["MauSac"]).ToString();
                                cthd.SoLuong  =
                                    int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["SoLuong"]).ToString());
                                cthd.DonGia = int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["DonGia"]).ToString());
                                cthdBus.Insert(cthd);

                                /* Update number of product attribute after paying bill */
                                int a = int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["LuongTon"]).ToString());
                                int b = int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["SoLuong"]).ToString());
                                thuoctinh.MaXe =
                                    gridView2.GetRowCellValue(i, gridView2.Columns["MaXe"]).ToString();
                                thuoctinh.SoLuong = a - b;
                                thuoctinh.MauSac  = gridView2.GetRowCellValue(i, gridView2.Columns["MauSac"]).ToString();
                                thuocTinhBus.Update_SoLuong(thuoctinh);

                                /* Update number of product after paying bill */
                                int c = int.Parse(gridView1.GetRowCellValue(i, gridView1.Columns["LuongTon"]).ToString());
                                int d = int.Parse(gridView2.GetRowCellValue(i, gridView2.Columns["SoLuong"]).ToString());
                                xe.LuongTon = c - d;
                                xe.MaXe     =
                                    gridView2.GetRowCellValue(i, gridView2.Columns["MaXe"]).ToString();
                                xeBus.Update_SoLuong(xe);
                            }
                            /* Refresh the database in gridView after paying */
                            DisplayThuocTinh();
                            DisplayXe();
                            Clear();
                            LockControl();
                            btnThem.Enabled = true;
                            XtraMessageBox.Show("Thanh toán thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        catch
                        {
                            XtraMessageBox.Show("Lỗi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
        }