private void DisplayDSSoHoaDonXuatTruoc() { Result result = HoaDonXuatTruocBus.GetSoHoaDonXuatTruocList(_fromNgayThayDoiHD, _toNgayThayDoiHD); if (result.IsOK) { MethodInvoker method = delegate { dgSoHoaDon.DataSource = result.QueryResult; HighlightSoHoaDonDaXuat(); }; if (InvokeRequired) { BeginInvoke(method); } else { method.Invoke(); } } else { MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXuatTruocBus.GetSoHoaDonXuatTruocList"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXuatTruocBus.GetSoHoaDonXuatTruocList")); } }
private void DisplayDSHoaDonXuatTruoc() { Result result = HoaDonXuatTruocBus.GetHoaDonXuatTruocList(_fromDate, _toDate, _tenBenhNhan, _tenDonVi, _maSoThue, _type); if (result.IsOK) { MethodInvoker method = delegate { dgInvoice.DataSource = result.QueryResult; }; if (InvokeRequired) { BeginInvoke(method); } else { method.Invoke(); } } else { MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXuatTruocBus.GetHoaDonXuatTruocList"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXuatTruocBus.GetHoaDonXuatTruocList")); } }
private void btnOK_Click(object sender, EventArgs e) { string inviceGUID = _drInvoice["HoaDonXuatTruocGUID"].ToString(); bool daThuTien = chkDaThuTien.Checked; Result result = HoaDonXuatTruocBus.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("InvoiceBus.UpdateDaThuTienInvoice"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("InvoiceBus.UpdateDaThuTienInvoice")); } }
private void OnSaveInfo() { try { MethodInvoker method = delegate { List <QuanLySoHoaDon> qlshdList = new List <QuanLySoHoaDon>(); DataTable dt = dgSoHoaDon.DataSource as DataTable; foreach (DataRow row in dt.Rows) { QuanLySoHoaDon qlshd = new QuanLySoHoaDon(); qlshd.SoHoaDon = Convert.ToInt32(row["SoHoaDon"]); qlshd.DaXuat = false; qlshd.XuatTruoc = true; qlshdList.Add(qlshd); } Result result = HoaDonXuatTruocBus.InsertQuanLySoHoaDon(qlshdList, _fromDate, _toDate); if (!result.IsOK) { MsgBox.Show(this.Text, result.GetErrorAsString("HoaDonXuatTruocBus.InsertInsertQuanLySoHoaDonService"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXuatTruocBus.InsertQuanLySoHoaDon")); this.DialogResult = System.Windows.Forms.DialogResult.Cancel; } }; if (InvokeRequired) { BeginInvoke(method); } else { method.Invoke(); } } catch (Exception e) { MsgBox.Show(this.Text, e.Message, IconType.Error); Utility.WriteToTraceLog(e.Message); } }
private void OnDeleteDangKy() { List <string> checkedKeys = SoHoaDonCheckedKeys; if (checkedKeys == null || checkedKeys.Count <= 0) { MsgBox.Show(Application.ProductName, "Vui lòng đánh dấu những số hóa đơn cần xóa.", IconType.Information); return; } if (MsgBox.Question(Application.ProductName, "Bạn có muốn xóa những số hóa đơn mà bạn đã đánh dấu ?") == DialogResult.Yes) { Result result = HoaDonXuatTruocBus.DeleteQuanLySoHoaDon(checkedKeys); if (result.IsOK) { DisplayDSSoHoaDonXuatTruoc(); } else { MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXuatTruocBus.DeleteQuanLySoHoaDon"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXuatTruocBus.DeleteQuanLySoHoaDon")); } } }
private bool ExportInvoice() { try { if (!CheckInfo()) { return(false); } HoaDonXuatTruoc invoice = new HoaDonXuatTruoc(); 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 = _mauSo; invoice.KiHieu = _kiHieu; invoice.HinhThucNhanHoaDon = raKhachTuLay.Checked ? "Khách tự lấy" : "Gởi qua bưu điện"; invoice.Notes = txtGhiChu.Text; List <ChiTietHoaDonXuatTruoc> addedDetails = new List <ChiTietHoaDonXuatTruoc>(); for (int i = 0; i < dgDetail.RowCount - 1; i++) { DataGridViewRow row = dgDetail.Rows[i]; ChiTietHoaDonXuatTruoc detail = new ChiTietHoaDonXuatTruoc(); detail.CreatedDate = DateTime.Now; detail.CreatedBy = Guid.Parse(Global.UserGUID); detail.TenMatHang = row.Cells["TenMatHang"].Value.ToString(); detail.DonViTinh = row.Cells["DonViTinh"].Value.ToString(); 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; addedDetails.Add(detail); } Result result = HoaDonXuatTruocBus.InsertHoaDonXuatTruoc(invoice, addedDetails, _fromDate, _toDate); 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")); } _hoaDonXuatTruoc = invoice; if (!_isPrinted) { return(true); } OnPrint(invoice.HoaDonXuatTruocGUID.ToString()); return(true); } else { MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXuatTruocBus.InsertHoaDonXuatTruoc"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXuatTruocBus.InsertHoaDonXuatTruoc")); } } catch (Exception ex) { MsgBox.Show(Application.ProductName, ex.Message, IconType.Error); Utility.WriteToTraceLog(ex.Message); } return(false); }
private bool CheckInfo() { Result result = HoaDonXuatTruocBus.CheckHoaDonXuatTruocExistCode(Convert.ToInt32(_invoiceCode), _fromDate, _toDate); 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(); return(false); } } else { MsgBox.Show(this.Text, result.GetErrorAsString("HoaDonXuatTruocBus.CheckHoaDonXuatTruocExistCode"), 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[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 == null || row.Cells[2].Value == DBNull.Value || 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); }
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; 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"]); txtGhiChu.Text = _drInvoice["Notes"] as string; 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 = HoaDonXuatTruocBus.GetChiTietHoaDonXuatTruoc(_drInvoice["HoaDonXuatTruocGUID"].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("HoaDonXuatTruocBus.GetChiTietHoaDonXuatTruoc"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXuatTruocBus.GetChiTietHoaDonXuatTruoc")); } } else { GenerateCode(); lbMauSo.Text = string.Format("Mẫu số: {0}", _mauSo); lbKiHieu.Text = string.Format("Kí hiệu: {0}", _kiHieu); Result result = HoaDonXuatTruocBus.GetNgayXuatHoaDon(_invoiceCode, _fromDate, _toDate); 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("HoaDonXuatTruocBus.GetNgayXuatHoaDon"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXuatTruocBus.GetNgayXuatHoaDon")); } lbBangChu.Text = string.Format("Số tiền viết bằng chữ: {0}", Utility.ReadNumberAsString((long)_totalPayment)); } }
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())) { //deletedInvoiceList.Add(row["HoaDonXuatTruocGUID"].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 hoaDonXuatTruocGUID = row["HoaDonXuatTruocGUID"].ToString(); dlgLyDoXoa dlg = new dlgLyDoXoa(soHoaDon, 1); if (dlg.ShowDialog(this) == DialogResult.OK) { noteList.Add(dlg.Notes); deletedInvoiceList.Add(hoaDonXuatTruocGUID); } } if (deletedInvoiceList.Count > 0) { Result result = HoaDonXuatTruocBus.DeleteHoaDonXuatTruoc(deletedInvoiceList, noteList); if (result.IsOK) { foreach (DataRow row in deletedRows) { string hoaDonXuatTruocGUID = row["HoaDonXuatTruocGUID"].ToString(); if (deletedInvoiceList.Contains(hoaDonXuatTruocGUID)) { dt.Rows.Remove(row); } } DisplayDSSoHoaDonXuatTruoc(); } else { MsgBox.Show(Application.ProductName, result.GetErrorAsString("HoaDonXuatTruocBus.DeleteHoaDonXuatTruoc"), IconType.Error); Utility.WriteToTraceLog(result.GetErrorAsString("HoaDonXuatTruocBus.DeleteHoaDonXuatTruoc")); } } } } else { MsgBox.Show(Application.ProductName, "Vui lòng đánh dấu những hóa đơn cần xóa.", IconType.Information); } }