Ejemplo n.º 1
0
        private void OnDeleteInvoice()
        {
            List <string>  deletedInvoiceList = new List <string>();
            List <DataRow> deletedRows        = new List <DataRow>();
            DataTable      dt = dgInvoice.DataSource as DataTable;

            foreach (DataRow row in dt.Rows)
            {
                if (Boolean.Parse(row["Checked"].ToString()))
                {
                    deletedRows.Add(row);
                }
            }

            if (deletedRows.Count > 0)
            {
                if (MsgBox.Question(Application.ProductName, "Bạn có muốn xóa những hóa đơn mà bạn đã đánh dấu ?") == DialogResult.Yes)
                {
                    List <string> noteList = new List <string>();

                    foreach (DataRow row in deletedRows)
                    {
                        string soHoaDon            = row["SoHoaDon"].ToString();
                        string hoaDonXetNghiemGUID = row["HoaDonXetNghiemGUID"].ToString();

                        dlgLyDoXoa dlg = new dlgLyDoXoa(soHoaDon, 1);
                        if (dlg.ShowDialog(this) == DialogResult.OK)
                        {
                            noteList.Add(dlg.Notes);
                            deletedInvoiceList.Add(hoaDonXetNghiemGUID);
                        }
                    }

                    if (deletedInvoiceList.Count > 0)
                    {
                        Result result = HoaDonXetNghiemBus.DeleteHoaDonXetNghiem(deletedInvoiceList, noteList);
                        if (result.IsOK)
                        {
                            foreach (DataRow row in deletedRows)
                            {
                                string hoaDonXetNghiemGUID = row["HoaDonXetNghiemGUID"].ToString();
                                if (deletedInvoiceList.Contains(hoaDonXetNghiemGUID))
                                {
                                    dt.Rows.Remove(row);
                                }
                            }
                        }
                        else
                        {
                            MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXetNghiemBus.DeleteHoaDonXetNghiem"), IconType.Error);
                            Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXetNghiemBus.DeleteHoaDonXetNghiem"));
                        }
                    }
                }
            }
            else
            {
                MsgBox.Show(Application.ProductName, "Vui lòng đánh dấu những hóa đơn cần xóa.", IconType.Information);
            }
        }
Ejemplo n.º 2
0
        private void OnDisplayInvoiceList()
        {
            Result result = HoaDonXetNghiemBus.GetHoaDonXetNghiemList(_fromDate, _toDate, _tenBenhNhan, _tenDonVi, _maSoThue, _type);

            if (result.IsOK)
            {
                MethodInvoker method = delegate
                {
                    ClearData();
                    dgInvoice.DataSource = result.QueryResult;
                };

                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method.Invoke();
                }
            }
            else
            {
                MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXetNghiemBus.GetHoaDonXetNghiemList"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXetNghiemBus.GetHoaDonXetNghiemList"));
            }
        }
Ejemplo n.º 3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string inviceGUID = _drInvoice["HoaDonXetNghiemGUID"].ToString();
            bool   daThuTien  = chkDaThuTien.Checked;
            Result result     = HoaDonXetNghiemBus.UpdateDaThuTienInvoice(inviceGUID, daThuTien);

            if (result.IsOK)
            {
                _drInvoice["DaThuTien"] = daThuTien;
                this.DialogResult       = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXetNghiemBus.UpdateDaThuTienInvoice"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXetNghiemBus.UpdateDaThuTienInvoice"));
            }
        }
Ejemplo n.º 4
0
        private bool ExportInvoice()
        {
            try
            {
                if (!CheckInfo())
                {
                    return(false);
                }

                HoaDonXetNghiem invoice = new HoaDonXetNghiem();
                invoice.SoHoaDon          = _invoiceCode;
                invoice.NgayXuatHoaDon    = dtpkNgay.Value;
                invoice.TenNguoiMuaHang   = cboTenNguoiMuaHang.Text;
                invoice.DiaChi            = txtAddress.Text;
                invoice.TenDonVi          = cboTenDonVi.Text;
                invoice.MaDonVi           = cboMaDonVi.Text;
                invoice.MaSoThue          = txtMaSoThue.Text;
                invoice.SoTaiKhoan        = txtSoTaiKhoan.Text;
                invoice.HinhThucThanhToan = (byte)cboHinhThucThanhToan.SelectedIndex;
                invoice.VAT                = (double)numVAT.Value;
                invoice.CreatedDate        = DateTime.Now;
                invoice.CreatedBy          = Guid.Parse(Global.UserGUID);
                invoice.Status             = (byte)Status.Actived;
                invoice.ChuaThuTien        = !chkDaThuTien.Checked;
                invoice.MauSo              = Global.MauSoXetNghiemSauCung;
                invoice.KiHieu             = Global.KiHieuXetNghiemSauCung;
                invoice.HinhThucNhanHoaDon = raKhachTuLay.Checked ? "Khách tự lấy" : "Gởi qua bưu điện";
                invoice.Notes              = txtGhiChu.Text;

                List <ChiTietHoaDonXetNghiem> addedDetails = new List <ChiTietHoaDonXetNghiem>();
                for (int i = 0; i < dgDetail.RowCount - 1; i++)
                {
                    DataGridViewRow        row    = dgDetail.Rows[i];
                    ChiTietHoaDonXetNghiem detail = new ChiTietHoaDonXetNghiem();
                    detail.CreatedDate = DateTime.Now;
                    detail.CreatedBy   = Guid.Parse(Global.UserGUID);
                    detail.TenHangHoa  = row.Cells["TenHangHoa"].Value.ToString();

                    //if (row.Cells["DonViTinh"].Value != null)
                    //    detail.DonViTinh = row.Cells["DonViTinh"].Value.ToString();
                    //else
                    detail.DonViTinh = "Lần";

                    int soLuong = 1;
                    //if (row.Cells["SoLuong"].Value != null && row.Cells["SoLuong"].Value != DBNull.Value)
                    //    soLuong = Convert.ToInt32(row.Cells["SoLuong"].Value);
                    detail.SoLuong = soLuong;

                    //int donGia = 0;
                    //if (row.Cells["DonGia"].Value != null && row.Cells["DonGia"].Value != DBNull.Value)
                    //    donGia = Convert.ToInt32(row.Cells["DonGia"].Value);

                    //detail.DonGia = donGia;

                    int thanhTien = 0;
                    if (row.Cells["ThanhTien"].Value != null && row.Cells["ThanhTien"].Value != DBNull.Value)
                    {
                        thanhTien = Convert.ToInt32(row.Cells["ThanhTien"].Value);
                    }

                    detail.ThanhTien = thanhTien;
                    detail.DonGia    = thanhTien;

                    addedDetails.Add(detail);
                }

                Result result = HoaDonXetNghiemBus.InsertHoaDonXetNghiem(invoice, addedDetails);
                if (result.IsOK)
                {
                    //Insert thông tin khách hàng
                    ThongTinKhachHang thongTinKhachHang = new ThongTinKhachHang();
                    thongTinKhachHang.TenKhachHang = invoice.TenNguoiMuaHang;
                    //thongTinKhachHang.TenDonVi = invoice.TenDonVi;
                    thongTinKhachHang.MaDonVi = invoice.MaDonVi;
                    //thongTinKhachHang.MaSoThue = invoice.MaSoThue;
                    //thongTinKhachHang.DiaChi = invoice.DiaChi;
                    thongTinKhachHang.SoTaiKhoan        = invoice.SoTaiKhoan;
                    thongTinKhachHang.HinhThucThanhToan = invoice.HinhThucThanhToan;
                    result = ThongTinKhachHangBus.InsertThongTinKhachHang(thongTinKhachHang);
                    if (!result.IsOK)
                    {
                        MsgBox.Show(Application.ProductName, result.GetErrorAsString("ThongTinKhachHangBus.InsertThongTinKhachHang"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("ThongTinKhachHangBus.InsertThongTinKhachHang"));
                    }

                    _hoaDonXetNghiem = invoice;
                    if (!_isPrinted)
                    {
                        return(true);
                    }
                    OnPrint(invoice.HoaDonXetNghiemGUID.ToString());
                    return(true);
                }
                else
                {
                    MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXetNghiemBus.InsertHoaDonXetNghiem"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXetNghiemBus.InsertHoaDonXetNghiem"));
                }
            }
            catch (Exception ex)
            {
                MsgBox.Show(Application.ProductName, ex.Message, IconType.Error);
                Utility.WriteToTraceLog(ex.Message);
            }

            return(false);
        }
Ejemplo n.º 5
0
        private bool CheckInfo()
        {
            Result result = HoaDonXetNghiemBus.CheckHoaDonXetNghiemExistCode(Convert.ToInt32(_invoiceCode));

            if (result.Error.Code == ErrorCode.EXIST || result.Error.Code == ErrorCode.NOT_EXIST)
            {
                if (result.Error.Code == ErrorCode.EXIST)
                {
                    MsgBox.Show(this.Text, "Số hóa đơn này đã được xuất rồi. Chương trình sẽ tạo lại số hóa đơn khác.", IconType.Information);
                    GenerateCode();
                    //this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    //this.Close();
                    return(false);
                }
            }
            else
            {
                MsgBox.Show(this.Text, result.GetErrorAsString("HoaDonXetNghiemBus.CheckHoaDonXetNghiemExistCode"), IconType.Error);
                return(false);
            }

            if (cboTenNguoiMuaHang.Text.Trim() == string.Empty && cboTenDonVi.Text.Trim() == string.Empty)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập tên người mua hàng hoặc tên đơn vị.", IconType.Information);
                cboTenNguoiMuaHang.Focus();
                return(false);
            }

            //if (cboMaDonVi.SelectedValue == null)
            //{
            //    MsgBox.Show(this.Text, "Mã đơn vị không tồn tại vui lòng nhập lại.", IconType.Information);
            //    cboMaDonVi.Focus();
            //    return false;
            //}

            //if (cboTenDonVi.Text.Trim() != string.Empty && cboTenDonVi.SelectedValue == null)
            //{
            //    MsgBox.Show(this.Text, "Tên đơn vị không tồn tại vui lòng nhập lại.", IconType.Information);
            //    cboTenDonVi.Focus();
            //    return false;
            //}

            if (dgDetail.RowCount <= 1)
            {
                MsgBox.Show(this.Text, "Vui lòng nhập ít nhất 1 dịch vụ để xuất hóa đơn.", IconType.Information);
                return(false);
            }

            for (int i = 0; i < dgDetail.RowCount - 1; i++)
            {
                DataGridViewRow row = dgDetail.Rows[i];

                if (row.Cells[2].Value == null || row.Cells[2].Value == DBNull.Value)
                {
                    row.Cells[2].Value = "Lần";
                }

                if (row.Cells[1].Value == null || row.Cells[1].Value == DBNull.Value || row.Cells[1].Value.ToString().Trim() == string.Empty)
                {
                    MsgBox.Show(this.Text, "Vui lòng nhập tên dịch vụ.", IconType.Information);
                    return(false);
                }

                //if (row.Cells[2].Value.ToString().Trim() == string.Empty)
                //{
                //    MsgBox.Show(this.Text, "Vui lòng nhập đơn vị tính.", IconType.Information);
                //    return false;
                //}

                //int donGia = 0;
                //if (row.Cells[4].Value != null && row.Cells[4].Value != DBNull.Value && row.Cells[4].Value.ToString().Trim() != string.Empty)
                //    donGia = Convert.ToInt32(row.Cells[4].Value);

                //if (donGia <= 0)
                //{
                //    MsgBox.Show(this.Text, "Vui lòng nhập đơn giá.", IconType.Information);
                //    return false;
                //}
            }

            return(true);
        }
Ejemplo n.º 6
0
        private void DisplayInfo()
        {
            Cursor.Current = Cursors.WaitCursor;
            if (_isView)
            {
                dgDetail.AllowUserToAddRows    = false;
                dgDetail.AllowUserToDeleteRows = false;
                dgDetail.ReadOnly = true;

                lbMauSo.Text       = string.Format("Mẫu số: {0}", _drInvoice["MauSo"].ToString());
                lbKiHieu.Text      = string.Format("Kí hiệu: {0}", _drInvoice["KiHieu"].ToString());
                lbInvoiceCode.Text = string.Format("Số: {0}", _drInvoice["SoHoaDon"].ToString());
                dtpkNgay.Value     = Convert.ToDateTime(_drInvoice["NgayXuatHoaDon"]);
                cboTenDonVi.Text   = _drInvoice["TenDonVi"].ToString();
                txtTenDonVi.Text   = cboTenDonVi.Text;

                cboMaDonVi.Text = _drInvoice["MaDonVi"] as string;
                txtMaDonVi.Text = cboMaDonVi.Text;

                txtGhiChu.Text = _drInvoice["Notes"] as string;

                if (_drInvoice["MaSoThue"] != null && _drInvoice["MaSoThue"] != DBNull.Value)
                {
                    txtMaSoThue.Text = _drInvoice["MaSoThue"].ToString();
                }

                txtSoTaiKhoan.Text = _drInvoice["SoTaiKhoan"].ToString();
                cboHinhThucThanhToan.SelectedIndex = Convert.ToInt32(_drInvoice["HinhThucThanhToan"]);
                txtHinhThucThanhToan.Text          = cboHinhThucThanhToan.Text;
                numVAT.Value = (Decimal)Convert.ToDouble(_drInvoice["VAT"]);

                if (_drInvoice["TenNguoiMuaHang"] != null && _drInvoice["TenNguoiMuaHang"] != DBNull.Value &&
                    _drInvoice["TenNguoiMuaHang"].ToString().Trim() != string.Empty)
                {
                    cboTenNguoiMuaHang.Text = _drInvoice["TenNguoiMuaHang"].ToString();
                    txtTenNguoiMuaHang.Text = cboTenNguoiMuaHang.Text;
                }

                if (_drInvoice["DiaChi"] != null && _drInvoice["DiaChi"] != DBNull.Value)
                {
                    txtAddress.Text = _drInvoice["DiaChi"].ToString();
                }

                chkDaThuTien.Checked = Convert.ToBoolean(_drInvoice["DaThuTien"]);

                if (_drInvoice["HinhThucNhanHoaDon"] != null && _drInvoice["HinhThucNhanHoaDon"] != DBNull.Value)
                {
                    string hinhThucNhanHoaDon = _drInvoice["HinhThucNhanHoaDon"].ToString();
                    if (hinhThucNhanHoaDon.ToLower() == "khách tự lấy")
                    {
                        raKhachTuLay.Checked    = true;
                        raGuiQuaBuuDien.Checked = false;
                    }
                    else
                    {
                        raKhachTuLay.Checked    = false;
                        raGuiQuaBuuDien.Checked = true;
                    }
                }

                Result result = HoaDonXetNghiemBus.GetChiTietHoaDonXetNghiem(_drInvoice["HoaDonXetNghiemGUID"].ToString());

                if (result.IsOK)
                {
                    DataTable dataSource = result.QueryResult as DataTable;
                    dgDetail.DataSource = dataSource;

                    foreach (DataRow row in dataSource.Rows)
                    {
                        double thanhTien = Convert.ToDouble(row["ThanhTien"]);
                        _totalPrice += thanhTien;
                    }

                    if (_totalPrice > 0)
                    {
                        lbTotalAmount.Text = string.Format("{0}", _totalPrice.ToString("#,###"));
                    }

                    double vat = ((double)numVAT.Value * _totalPrice) / 100;
                    if (vat > 0)
                    {
                        lbVAT.Text = string.Format("{0}", vat.ToString("#,###"));
                    }

                    _totalPayment       = _totalPrice + vat;
                    _oldTotalPayment    = _totalPayment;
                    lbTotalPayment.Text = string.Format("{0}", _totalPayment.ToString("#,###"));
                    lbBangChu.Text      = string.Format("Số tiền viết bằng chữ: {0}", Utility.ReadNumberAsString((long)_totalPayment));

                    RefreshNo();
                }
                else
                {
                    MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXetNghiemBus.GetChiTietHoaDonXetNghiem"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXetNghiemBus.GetChiTietHoaDonXetNghiem"));
                }
            }
            else
            {
                GenerateCode();

                lbMauSo.Text  = string.Format("Mẫu số: {0}", Global.MauSoXetNghiemSauCung);
                lbKiHieu.Text = string.Format("Kí hiệu: {0}", Global.KiHieuXetNghiemSauCung);

                Result result = HoaDonXetNghiemBus.GetNgayXuatHoaDon(_invoiceCode);
                if (result.IsOK)
                {
                    if (result.QueryResult != null)
                    {
                        DateTime dt = Convert.ToDateTime(result.QueryResult);
                        if (dt < dtpkNgay.MinDate)
                        {
                            dt = dtpkNgay.MinDate;
                        }
                        if (dt > dtpkNgay.MaxDate)
                        {
                            dt = dtpkNgay.MaxDate;
                        }

                        dtpkNgay.Value = dt;
                    }
                }
                else
                {
                    MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXetNghiemBus.GetNgayXuatHoaDon"), IconType.Error);
                    Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXetNghiemBus.GetNgayXuatHoaDon"));
                }
            }
        }