private void AddWorkerIDButton(object sender, System.Windows.RoutedEventArgs e) { if (globalDatabasePath != null) { CommonOpenFileDialog dialogFileSelect = new CommonOpenFileDialog(); dialogFileSelect.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dialogFileSelect.Filters.Add(new CommonFileDialogFilter("Arkusz programu Microsoft Excel (*.xlsx)", ".xlsx")); if (dialogFileSelect.ShowDialog() == CommonFileDialogResult.Ok) { //Update DB if (DatabaseHandling.AddWorkerID(globalDatabasePath, dialogFileSelect.FileName) == 0) { this.ShowMessageAsync("Błąd pliku", "Wybrany plik jest niepoprawny, pusty lub otwarty"); return; } //Fill list MainList.ItemsSource = DatabaseHandling.LoadAllByDate(globalDatabasePath); this.ShowMessageAsync("Gotowe", "Załadowano kodowanie."); } } else { this.ShowMessageAsync("Brak danych", "Dodaj najpierw plik"); } }
private void ResetFilterButton(object sender, System.Windows.RoutedEventArgs e) { DateFromPicker.SelectedDate = null; DateToPicker.SelectedDate = null; CardID.Text = "Kod karty"; ServiceCard.Text = "Kod karty"; if (globalDatabasePath != null) { MainList.ItemsSource = DatabaseHandling.LoadAllByDate(globalDatabasePath); } }
private void PerformFilterButton(object sender, System.Windows.RoutedEventArgs e) { if (globalDatabasePath != null) { var tempList = DatabaseHandling.PerformFilter(DateFromPicker.SelectedDate, DateToPicker.SelectedDate, CardID.Text, ServiceCard.Text, globalDatabasePath); if (tempList != null) { MainList.ItemsSource = tempList; } else { this.ShowMessageAsync("Błąd danych", "Niepoprawne dane filtra"); } } else { this.ShowMessageAsync("Brak danych", "Dodaj najpierw plik"); } }
static public void SaveSmallAudit(string path, string pathSaveFile, IEnumerable <ListDisplay.ListItem> data, DateTime?dateFrom, DateTime?dateTo, string sumPaid) { Document document = new Document(); document.Info.Title = "Mały audyt"; Section section = document.AddSection(); section.PageSetup.LeftMargin = "1cm"; Paragraph paragraph; Table table; Column column; Row row; paragraph = section.AddParagraph("Wyciąg z audytu wygenerowany " + DateTime.Now); paragraph.Format.Font.Size = 6; if (dateFrom == null) { paragraph = section.AddParagraph("Data od: " + DateTime.Parse(data.First().ItemDate).ToShortDateString()); paragraph.Format.Font.Size = 6; } else { paragraph = section.AddParagraph("Data od: " + dateFrom.Value.ToShortDateString()); paragraph.Format.Font.Size = 6; } if (dateTo == null) { paragraph = section.AddParagraph("Data do: " + DateTime.Parse(data.Last().ItemDate).ToShortDateString()); paragraph.Format.Font.Size = 6; } else { paragraph = section.AddParagraph("Data do: " + dateTo.Value.ToShortDateString()); paragraph.Format.Font.Size = 6; } paragraph = section.AddParagraph("\n\n"); //Table section table = section.AddTable(); table.Style = "Table"; table.Borders.Color = Color.Parse("Black"); table.Borders.Width = 0.25; table.Borders.Left.Width = 0.5; table.Borders.Right.Width = 0.5; table.Format.Alignment = ParagraphAlignment.Center; table.Rows.LeftIndent = 0; column = table.AddColumn("2,5cm"); column.Format.Alignment = ParagraphAlignment.Center; column.Format.Font.Size = 5; column = table.AddColumn("2,5cm"); column.Format.Alignment = ParagraphAlignment.Center; column.Format.Font.Size = 5; column = table.AddColumn("2,5cm"); column.Format.Alignment = ParagraphAlignment.Center; column.Format.Font.Size = 5; column = table.AddColumn("2cm"); column.Format.Alignment = ParagraphAlignment.Center; column.Format.Font.Size = 5; row = table.AddRow(); row.Format.Font.Bold = true; row.Format.Font.Size = 6; row.Cells[0].AddParagraph("Kod pracownika"); row.Cells[1].AddParagraph("ID"); row.Cells[2].AddParagraph("Televend ID"); row.Cells[3].AddParagraph("Suma zakupów"); List <string> IDs = DatabaseHandling.GetCardIDs(path); int i; IEnumerable <ListDisplay.ListItem> currentIDItem; for (i = 0; i < IDs.Count(); i++) { currentIDItem = (data as IEnumerable <ListDisplay.ListItem>).Where(item => item.ItemID == IDs[i]); if (currentIDItem.FirstOrDefault().ItemID == null) { continue; } row = table.AddRow(); row.Cells[0].AddParagraph(currentIDItem.FirstOrDefault().ItemWorkerID); row.Cells[2].AddParagraph(IDs[i]); row.Cells[1].AddParagraph(currentIDItem.FirstOrDefault().ItemStickerID); row.Cells[3].AddParagraph(currentIDItem.Sum(item => Convert.ToDecimal(item.ItemPurchase)).ToString()); } row = table.AddRow(); row.Format.Font.Bold = true; row.Format.Font.Size = 7; row.Cells[0].AddParagraph("Suma"); row.Cells[3].AddParagraph(sumPaid); //Final PDF generation PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always); renderer.Document = document; renderer.RenderDocument(); if (!pathSaveFile.EndsWith(".pdf")) { pathSaveFile += ".pdf"; } renderer.PdfDocument.Save(pathSaveFile); Process.Start(pathSaveFile); }
private async void SelectFileButton(object sender, System.Windows.RoutedEventArgs e) { CommonOpenFileDialog dialogFileSelect = new CommonOpenFileDialog(); dialogFileSelect.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); dialogFileSelect.Filters.Add(new CommonFileDialogFilter("Arkusz programu Microsoft Excel (*.xlsx)", ".xlsx")); if (dialogFileSelect.ShowDialog() == CommonFileDialogResult.Ok) { //Remove previous DB (if exists) if (globalDatabasePath != null) { GC.Collect(); GC.WaitForPendingFinalizers(); File.Delete(globalDatabasePath); } globalDatabasePath = dialogFileSelect.FileName.Remove(dialogFileSelect.FileName.Length - 4, 4) + "sqlite"; //Get size and verify file int rowNumber = DatabaseHandling.GetRowNumber(globalDatabasePath); //////////////////////////////////////////////////////////////////////// // DEMO // //////////////////////////////////////////////////////////////////////// //if (rowNumber > 50) //{ // await this.ShowMessageAsync("DEMO", "Wersja demo obsługuje do 50 wierszy pliku wsadowego."); // globalDatabasePath = null; // return; //} //////////////////////////////////////////////////////////////////////// // DEMO // //////////////////////////////////////////////////////////////////////// if (rowNumber == -1) { await this.ShowMessageAsync("Błąd pliku", "Załadowany plik jest niepoprawny"); globalDatabasePath = null; return; } else if (rowNumber == -2) { await this.ShowMessageAsync("Plik w użyciu", "Wybrany plik jest otwarty. Zamknij go i spróbuj ponownie."); globalDatabasePath = null; return; } //Create DB ProgressDialogController controller = await this.ShowProgressAsync("Ładowanie", "Dane są odczytywane"); controller.Maximum = (double)rowNumber; controller.Minimum = 0; IProgress <double> progress = new Progress <double>(value => controller.SetProgress(value)); progress.Report(0); await Task.Run(() => { DatabaseHandling.CreateTempDB(globalDatabasePath); DatabaseHandling.FillDB(globalDatabasePath, progress); }); await controller.CloseAsync(); //Fill list MainList.ItemsSource = DatabaseHandling.LoadAllByDate(globalDatabasePath); //Invalid file was loaded if (MainList.Items.Count == 0) { await this.ShowMessageAsync("Błąd pliku", "Załadowany plik jest pusty lub niepoprawny."); globalDatabasePath = null; } } else { return; } }
static public void SaveSmallAudit(string path, string pathSaveFile, IEnumerable <ListDisplay.ListItem> data, DateTime?dateFrom, DateTime?dateTo, string sumPaid) { XSSFWorkbook xlWorkBook = new XSSFWorkbook(); ISheet sheet = xlWorkBook.CreateSheet("1"); IRow firstRow, row; firstRow = sheet.CreateRow(0); row = sheet.CreateRow(1); row.CreateCell(0).SetCellValue("Data od"); row.CreateCell(2).SetCellValue("Data do"); if (dateTo == null) { row.CreateCell(3).SetCellValue(DateTime.Parse(data.Last().ItemDate).ToShortDateString()); } else { row.CreateCell(3).SetCellValue(dateTo.Value.ToShortDateString()); } if (dateFrom == null) { row.CreateCell(1).SetCellValue(DateTime.Parse(data.First().ItemDate).ToShortDateString()); } else { row.CreateCell(1).SetCellValue(dateFrom.Value.ToShortDateString()); } row = sheet.CreateRow(2); row.CreateCell(0).SetCellValue("Kod pracownika"); row.CreateCell(1).SetCellValue("ID"); row.CreateCell(2).SetCellValue("Televend ID"); row.CreateCell(3).SetCellValue("Suma zakupów"); List <string> IDs = DatabaseHandling.GetCardIDs(path); int i; int rowCounter = 3; IEnumerable <ListDisplay.ListItem> currentIDItem; for (i = 0; i < IDs.Count(); i++) { currentIDItem = (data as IEnumerable <ListDisplay.ListItem>).Where(item => item.ItemID == IDs[i]); if (currentIDItem.FirstOrDefault().ItemID == null) { continue; } string currentSum = currentIDItem.Sum(item => Convert.ToDecimal(item.ItemPurchase)).ToString(); if (currentSum == "0") { continue; } row = sheet.CreateRow(rowCounter); row.CreateCell(0).SetCellValue(currentIDItem.FirstOrDefault().ItemWorkerID); row.CreateCell(2).SetCellValue(IDs[i]); row.CreateCell(1).SetCellValue(currentIDItem.FirstOrDefault().ItemStickerID); row.CreateCell(3).SetCellValue(currentSum); rowCounter++; } row = sheet.CreateRow(i + 3); row.CreateCell(0).SetCellValue("Suma"); row.CreateCell(3).SetCellValue(sumPaid); for (int j = 0; j < 4; j++) { sheet.AutoSizeColumn(j); } //Add after auto sizing to avoid enormous first column firstRow.CreateCell(0).SetCellValue("Wyciąg z audytu wygenerowany " + DateTime.Now); if (!pathSaveFile.EndsWith(".xlsx")) { pathSaveFile += ".xlsx"; } using (var fs = new FileStream(pathSaveFile, FileMode.Create, FileAccess.Write)) { xlWorkBook.Write(fs); } }