Exemplo n.º 1
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var selectedInvoice = dgInvoices.SelectedItem != null ? new InvoicesLogic().GetInvoice((dgInvoices.SelectedItem as Model.InvoiceDataGridView).InvoiceId) : null;
                if (selectedInvoice != null)
                {
                    if (MessageBox.Show("ยืนยันที่จะลบข้อมูลใบแจ้งหนี้ " + selectedInvoice.InvoiceNo, "ยืนยันการลบข้อมูล", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
                    {
                        InvoicesLogic l = new InvoicesLogic();
                        l.DeleteInvoice(selectedInvoice);

                        Model.Invoice latestInvoice = new InvoicesLogic().GetLatestInvoice(selectedInvoice.Room.RoomId);
                        if (latestInvoice != null)
                        {
                            selectedInvoice.Room.WUnitStart = latestInvoice.WMeterStart;
                            selectedInvoice.Room.EUnitStart = latestInvoice.EMeterStart;
                            new RoomsLogic().UpdateRoomMeterStart(selectedInvoice.Room);
                        }

                        SearchInvoice();
                    }
                }
                else
                {
                    MessageBox.Show("กรุณาเลือกข้อมูลที่จะลบ", "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
 private void PopulateFieldsOnRoomSelect()
 {
     Model.Invoice latestInvoive = new InvoicesLogic().GetLatestInvoice(_selectedRoom.RoomId);
     lblContactName.Content     = _selectedRoom.Customer.ContactName;
     tbxWaterStart.Text         = latestInvoive != null ? (latestInvoive.WMeterStart + latestInvoive.WUsedUnit).ToString() : _selectedRoom.WUnitStart.ToString();
     tbxElectricStart.Text      = latestInvoive != null ? (latestInvoive.EMeterStart + latestInvoive.EUsedUnit).ToString() : _selectedRoom.EUnitStart.ToString();
     tbxWaterUnitPrices.Text    = Global.CurrentSystemVariable.WUnit.ToString("N2", thCulture);
     tbxElectricUnitPrices.Text = Global.CurrentSystemVariable.EUnit.ToString("N2", thCulture);
     tbxMonthCost.Text          = _selectedRoom.MonthCost.ToString("N2", thCulture);
 }
Exemplo n.º 3
0
        private void PopulateFieldsOnRoomSelect()
        {
            Model.Invoice searchInvoice;
            if (DateTime.Now.Month == 1 && _selectedMonth == 12)
            {
                searchInvoice = new InvoicesLogic().GetInvoiceForReceipt(_selectedRoom.RoomId, _selectedMonth, DateTime.Now.Year - 1);
            }
            else
            {
                searchInvoice = new InvoicesLogic().GetInvoiceForReceipt(_selectedRoom.RoomId, _selectedMonth, DateTime.Now.Year);
            }
            if (searchInvoice != null)
            {
                _relatedInvoice            = searchInvoice;
                tbkApartmentName.Text      = Global.CurrentApartment.ApartmentName;
                tbkApartmentAddress.Text   = Global.CurrentApartment.Address;
                tbxReceiptNo.Text          = _relatedInvoice.InvoiceNo;
                tbxRoomNo.Text             = _relatedInvoice.Room.RoomNo;
                tbxMonth.Text              = _relatedInvoice.MonthNo.ToString();
                tbxWaterStart.Text         = _relatedInvoice.WMeterStart.ToString();
                tbxElectricStart.Text      = _relatedInvoice.EMeterStart.ToString();
                tbxWaterEnd.Text           = (_relatedInvoice.WMeterStart + _relatedInvoice.WUsedUnit).ToString();
                tbxElectricEnd.Text        = (_relatedInvoice.EMeterStart + _relatedInvoice.EUsedUnit).ToString();
                tbxWaterUnitPrices.Text    = _relatedInvoice.WUnit.ToString("N2", thCulture);
                tbxElectricUnitPrices.Text = _relatedInvoice.EUnit.ToString("N2", thCulture);
                tbxWaterUnits.Text         = _relatedInvoice.WUsedUnit.ToString();
                tbxElectricUnits.Text      = _relatedInvoice.EUsedUnit.ToString();
                tbxTelephoneAmount.Text    = _relatedInvoice.TelCost.ToString("N2", thCulture);
                tbxMonthCost.Text          = _relatedInvoice.Room.MonthCost.ToString("N2", thCulture);
                tbxImproveCost.Text        = _relatedInvoice.ImproveCost.ToString("N2", thCulture);
                tbxImproveText.Text        = _relatedInvoice.ImproveText;
                tbxComment.Text            = _relatedInvoice.Comment;

                CalculateAllAmounts();
            }
            else
            {
                ClearForm();
                MessageBox.Show("ไม่พบใบแจ้งหนี้ของเดือนที่กำหนด", "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 4
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int      reportMonth = cbbMonth.SelectedIndex + 1;
                int      reportYear  = int.Parse(cbbYear.SelectedItem.ToString());
                DateTime fromDate    = new DateTime(reportYear - 543, reportMonth, 1);
                DateTime toDate      = fromDate.AddMonths(1).AddDays(-1);
                List <Model.InvoiceForPrinting> printInvoices = new List <Model.InvoiceForPrinting>();
                ReportPreviewer rp = new ReportPreviewer();

                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (o, ea) =>
                {
                    List <Model.Invoice> invoices = new InvoicesLogic().GetInvoices(fromDate, toDate, Global.CurrentApartment.ApartmentId);

                    foreach (var inv in invoices)
                    {
                        printInvoices.AddRange(new InvoicesLogic().GetInvoiceForPrinting(inv));
                    }
                };

                worker.RunWorkerCompleted += (o, ea) =>
                {
                    rp.SetDataSet("InvoiceDataSet", printInvoices);
                    rp.SetReportPath(@".\Reports\Invoice.rdlc");
                    rp.ShowDialog();
                    loadingPanel.IsBusy = false;
                };

                loadingPanel.IsBusy = true;

                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 5
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string reportMonth = cbbMonth.SelectedItem.ToString();
                string reportYear  = cbbYear.SelectedItem.ToString();
                List <Model.IncomeReportRecord> reportDataSet = new List <Model.IncomeReportRecord>();
                DateTime        fromDate            = new DateTime(int.Parse(reportYear) - 543, cbbMonth.SelectedIndex + 1, 1);
                DateTime        toDate              = fromDate.AddMonths(1).AddDays(-1);
                bool            isDeductImproveCost = Convert.ToBoolean(cbDeductImproveCost.IsChecked);
                ReportPreviewer rp = new ReportPreviewer();

                List <ReportParameter> parameters = new List <ReportParameter>();
                parameters.Add(new ReportParameter("ReportYear", reportYear));
                parameters.Add(new ReportParameter("ReportMonth", reportMonth));

                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (o, ea) =>
                {
                    List <Model.Invoice> invoices = new InvoicesLogic().GetInvoices(fromDate, toDate, Global.CurrentApartment.ApartmentId);
                    foreach (var invoice in invoices)
                    {
                        Decimal electricCost = invoice.EUsedUnit * invoice.EUnit;
                        Decimal waterCost    = invoice.WUsedUnit * invoice.WUnit;
                        Decimal total        = electricCost + waterCost + invoice.TelCost + invoice.Room.MonthCost + invoice.ImproveCost;

                        Model.IncomeReportRecord rec = new Model.IncomeReportRecord()
                        {
                            RoomNo        = invoice.Room.RoomNo,
                            ContactName   = invoice.Room.Customer.ContactName,
                            MonthName     = reportYear,
                            ElectricCost  = electricCost,
                            WaterCost     = waterCost,
                            TelephoneCost = invoice.TelCost,
                            MonthCost     = invoice.Room.MonthCost,
                            ImproveCost   = isDeductImproveCost ? 0 : invoice.ImproveCost,
                            Total         = isDeductImproveCost ? (total - invoice.ImproveCost) : total
                        };

                        reportDataSet.Add(rec);
                    }
                    rp.SetDataSet("IncomeReportDataSet", reportDataSet);
                };

                worker.RunWorkerCompleted += (o, ea) =>
                {
                    rp.SetReportPath(@".\Reports\IncomeReport.rdlc");
                    rp.SetParameters(parameters);
                    rp.ShowDialog();
                    loadingPanel.IsBusy = false;
                };

                loadingPanel.IsBusy = true;

                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }