private void btnFind_Click(object sender, RoutedEventArgs e) { DateTime?datepicker = dpDateStart.SelectedDate; if (datepicker.ToString() == "") { start = new DateTime(1900, 1, 1, 0, 0, 0); } else { start = datepicker.Value; } datepicker = dpDateEnd.SelectedDate; if (datepicker.ToString() == "") { end = DateTime.Today; } else { end = datepicker.Value; } if (DateTime.Compare(start, end) > 0) { MessageBox.Show("Ngày bắt đầu phải trước ngày kết thúc."); return; } keyword = tbFind.Text; BUS_Receipt busReceipt = new BUS_Receipt(); int empCount = busReceipt.CountReceipt(start, end, keyword); if (empCount % limitRow == 0) { lblMaxPage.Content = empCount / limitRow; } else { lblMaxPage.Content = empCount / limitRow + 1; } if (currentPage == (int)lblMaxPage.Content) { btnPageNext.IsEnabled = false; } else { btnPageNext.IsEnabled = true; } currentPage = 1; tbNumPage.Text = currentPage.ToString(); ReloadDGReceipt(); }
private void tbFind_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Return) { DateTime?datepicker = dpDateStart.SelectedDate; if (datepicker.ToString() == "") { start = new DateTime(2021, 1, 1, 0, 0, 0); } else { start = datepicker.Value; } datepicker = dpDateEnd.SelectedDate; if (datepicker.ToString() == "") { end = DateTime.Today; } else { end = datepicker.Value; } keyword = tbFind.Text; BUS_Receipt busReceipt = new BUS_Receipt(); int empCount = busReceipt.CountReceipt(start, end, keyword); if (empCount % limitRow == 0) { lblMaxPage.Content = empCount / limitRow; } else { lblMaxPage.Content = empCount / limitRow + 1; } if (currentPage == (int)lblMaxPage.Content) { btnPageNext.IsEnabled = false; } else { btnPageNext.IsEnabled = true; } currentPage = 1; tbNumPage.Text = currentPage.ToString(); ReloadDGReceipt(); } }
private void btnCash_Click(object sender, RoutedEventArgs e) { if (billItems.Count == 0) { /// return; } if (newReceiptID != "") { MessageBox.Show($"Hóa đơn này đã thanh toán, mã hóa đơn là {newReceiptID}!"); return; } BUS_Discount busDiscount = new BUS_Discount(); DTO_Discount curDiscount = busDiscount.GetCurrentDiscount(); string disID = ""; if (curDiscount.DiscountValue != 0) { disID = curDiscount.DiscountID; } DTO_Receipt newReceipt = new DTO_Receipt("", user, disID); BUS_Receipt busReceipt = new BUS_Receipt(); newReceiptID = busReceipt.CreateReceipt(newReceipt); if (newReceiptID != "") { BUS_ReceiptDetail busReceiptDetail = new BUS_ReceiptDetail(); bool result = true; foreach (BillItem item in billItems) { DTO_ReceiptDetail newReceiptDetail = new DTO_ReceiptDetail(newReceiptID, item.id, item.amount, item.unitCost); result = result & busReceiptDetail.CreateReceiptDetail(newReceiptDetail); } if (result) { MessageBox.Show("Tạo hóa đơn thành công!"); } else { MessageBox.Show("Đã xảy ra lỗi trong quá trình tạo chi tiết hóa đơn!"); } } else { MessageBox.Show("Đã xảy ra lỗi trong quá trình tạo hóa đơn!"); } }
private void btSave_Click(object sender, RoutedEventArgs e) { switch (this.type) { case 1: /// Delete Account BUS_ReceiptDetail busReceiptDetail = new BUS_ReceiptDetail(); bool result1 = busReceiptDetail.DeleteDetailByID(deleteid); if (result1) { BUS_Receipt busReceipt = new BUS_Receipt(); if (busReceipt.DeleteReceiptByID(deleteid)) { MessageBox.Show($"Đã xóa hóa đơn {deleteid}."); Window.GetWindow(this).Close(); } else { MessageBox.Show($"Đã xảy ra lỗi trong quá trình xóa hóa đơn!"); } } else { MessageBox.Show($"Đã xảy ra lỗi trong quá trình xóa chi tiết hóa đơn."); } break; case 2: BUS_Payment bus = new BUS_Payment(); if (bus.deletePayment(deleteid) > 0) { MessageBox.Show($"Đã xóa phiếu chi {deleteid}."); } else { MessageBox.Show($"Đã xảy ra lỗi trong quá trình xóa phiếu chi!"); } Window.GetWindow(this).Close(); break; } }
void LoadData(Object sender, RoutedEventArgs e) { BUS_Parameter busParameter = new BUS_Parameter(); limitRow = busParameter.GetValue("RowInList"); currentPage = 1; tbNumPage.Text = "1"; btnPagePre.IsEnabled = false; start = new DateTime(1900, 1, 1, 0, 0, 0); end = DateTime.Today; keyword = ""; tbFind.Text = ""; dpDateStart.SelectedDate = null; dpDateEnd.SelectedDate = null; BUS_Receipt busReceipt = new BUS_Receipt(); int empCount = busReceipt.CountReceipt(start, end, keyword); if (empCount % limitRow == 0) { lblMaxPage.Content = empCount / limitRow; } else { lblMaxPage.Content = empCount / limitRow + 1; } if (currentPage == (int)lblMaxPage.Content) { btnPageNext.IsEnabled = false; } else { btnPageNext.IsEnabled = true; } ReloadDGReceipt(); }
private void ReloadDGReceipt() { receiptItems = new List <ReceiptItem>(); BUS_Receipt busReceipt = new BUS_Receipt(); DataTable receipts = busReceipt.GetReceipts(start, end, keyword, limitRow, limitRow * (currentPage - 1)); foreach (DataRow row in receipts.Rows) { string id = row["ReceiptID"].ToString(); DateTime time = TimeZone.CurrentTimeZone.ToLocalTime((DateTime)row["Time"]); string creater = row["EmployeeName"].ToString(); float dis = 0; if (row["DiscountID"].ToString() != "") { dis = float.Parse(row["DiscountValue"].ToString()); } int total = (int)(Int32.Parse(row["Total"].ToString()) * (1 - dis / 100)); receiptItems.Add(new ReceiptItem(id, time, creater, total)); } dgReceipt.ItemsSource = receiptItems; dgReceipt.Items.Refresh(); }
private void LoadGeneralChartYear() { GeneralChart = new SeriesCollection(); LabelGeneralCharts = new List <string>(); ChartValues <int> Income = new ChartValues <int>(); ChartValues <int> Outcome = new ChartValues <int>(); ChartValues <int> Profit = new ChartValues <int>(); for (int i = 0; i < months; i++) { LabelGeneralCharts.Add("Tháng " + (i + 1)); Income.Add(0); Outcome.Add(0); Profit.Add(0); } BUS_Receipt busRec = new BUS_Receipt(); DataTable RecData = busRec.GetTotalIncomeByYear(dpMonthYear.SelectedDate.GetValueOrDefault().Year); foreach (DataRow row in RecData.Rows) { Income[Int32.Parse(row["Month"].ToString()) - 1] = Int32.Parse(row["TotalAfterDis"].ToString()); Profit[Int32.Parse(row["Month"].ToString()) - 1] += Int32.Parse(row["TotalAfterDis"].ToString()); } BUS_InventoryImport busInvImp = new BUS_InventoryImport(); DataTable InvImpData = busInvImp.GetTotalAmountByYear(dpMonthYear.SelectedDate.GetValueOrDefault().Year); foreach (DataRow row in InvImpData.Rows) { Outcome[Int32.Parse(row["Month"].ToString()) - 1] = Int32.Parse(row["TotalAmount"].ToString()); Profit[Int32.Parse(row["Month"].ToString()) - 1] -= Int32.Parse(row["TotalAmount"].ToString()); } BUS_Payment busPay = new BUS_Payment(); DataTable PayData = busPay.GetTotalAmountByYear(dpMonthYear.SelectedDate.GetValueOrDefault().Year); foreach (DataRow row in PayData.Rows) { Outcome[Int32.Parse(row["Month"].ToString()) - 1] += Int32.Parse(row["Total"].ToString()); Profit[Int32.Parse(row["Month"].ToString()) - 1] -= Int32.Parse(row["Total"].ToString()); } GeneralChart.Add(new ColumnSeries { Title = "Doanh thu ", Values = Income, MaxColumnWidth = 16 }); GeneralChart.Add(new ColumnSeries { Title = "Chi phí", Values = Outcome, MaxColumnWidth = 16 }); GeneralChart.Add(new ColumnSeries { Title = "Lợi nhuận", Values = Profit, MaxColumnWidth = 16 }); //FormatterGeneralCharts = value => value.ToString("N"); generalChart.AxisX.Clear(); generalChart.AxisX.Add(new Axis { Title = "", LabelFormatter = value => "Tháng " + (value + 1).ToString(), FontSize = 15, Foreground = (SolidColorBrush) new BrushConverter().ConvertFromString("#6B6158") }); generalChart.Series = GeneralChart; generalChart.Width = LabelGeneralCharts.Count * 80; generalChartTitle.Text = $"Biểu đồ thống kê tổng quát năm {dpMonthYear.SelectedDate.GetValueOrDefault().Year}"; }
private void btnDelete_Click(object sender, RoutedEventArgs e) { string id = ((Button)sender).Tag.ToString(); BUS_Receipt busReceipt = new BUS_Receipt(); BUS_Parameter busParameter = new BUS_Parameter(); int limitDay = busParameter.GetValue("DayDeleteReceipt"); if ((DateTime.Now - busReceipt.GetCreateDayByID(id)).TotalDays > limitDay) { MessageBox.Show($"Không thể xóa do hóa đơn đã được tạo cách đây hơn {limitDay} ngày!"); return; } System.Windows.Media.Effects.BlurEffect objBlur = new System.Windows.Media.Effects.BlurEffect(); ((MainWindow)App.Current.MainWindow).Opacity = 0.5; ((MainWindow)App.Current.MainWindow).Effect = objBlur; Window window = new Window { ResizeMode = ResizeMode.NoResize, WindowStyle = WindowStyle.None, Title = "Xóa hóa đơn", Content = new PopupDeleteConfirm($"Bạn có chắc chắn muốn xóa hóa đơn\n{id} không?", id, 1), Width = 420, Height = 220, WindowStartupLocation = WindowStartupLocation.CenterScreen }; window.ShowDialog(); int empCount = busReceipt.CountReceipt(start, end, keyword); if (empCount % limitRow == 0) { lblMaxPage.Content = empCount / limitRow; } else { lblMaxPage.Content = empCount / limitRow + 1; } if (currentPage > (int)lblMaxPage.Content) { tbNumPage.Text = (--currentPage).ToString(); } if (currentPage == (int)lblMaxPage.Content) { btnPageNext.IsEnabled = false; } else { btnPageNext.IsEnabled = true; } if (currentPage == 1) { btnPagePre.IsEnabled = false; } else { btnPagePre.IsEnabled = true; } ReloadDGReceipt(); ((MainWindow)App.Current.MainWindow).Opacity = 1; ((MainWindow)App.Current.MainWindow).Effect = null; }