public void Completed(bool cancelled) { try { ActivityBar.Stop(); } catch (Exception ex) { ErrorManagement.Log(ex); } }
public void Start() { try { while (mController.Running) { mController.Display(); Thread.Sleep(100); } } catch (Exception ex) { ErrorManagement.Log(ex); } }
internal void CloseMessage() { try { if (thrMessage != null) { switch (thrMessage.ThreadState) { case ThreadState.Running: case ThreadState.WaitSleepJoin: { if (!thrMessage.Join(100)) { frmMessage.Cancel(); thrMessage.Abort(); } break; } default: { if (!frmMessage.Visible) { frmMessage.Cancel(); thrMessage.Abort(); } break; } } } } catch (ThreadAbortException ex) { ErrorManagement.Log(ex); } catch (Exception ex) { ErrorManagement.Log(ex); } }
internal WaitingMessage(string message, string title = "", int amountProgressBars = 1, bool cancelButton = false) { try { frmMessage = new F_Message(message, title, amountProgressBars, cancelButton); thrMessage = new Thread(frmMessage.ShowMe); thrMessage.Start(); } catch (ThreadAbortException ex) { ErrorManagement.Log(ex); } catch (Exception ex) { ErrorManagement.Log(ex); } }
private void F_Message_Shown(object sender, EventArgs e) { try { Cursor.Current = Cursors.WaitCursor; mController.Start(new TacheDeportee()); } catch (ThreadAbortException) { } catch (Exception ex) { ErrorManagement.Log(ex); } finally { Cursor.Current = Cursors.Default; } }
private void Delete(bool confirm) { WaitingMessage.WaitingMessage waitingMessage = null; try { if (confirm && MessageBox.Show("Are you sure you want to DEFINITIVELY delete the opened workbook?", "Delete a workbook", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } waitingMessage = new WaitingMessage.WaitingMessage("Please wait while data are being erased from the database." + Environment.NewLine + "This may take few seconds...", "Delete a workbook", 0); if (!Workbook_BLL.Delete(OpenedFile.Id)) { return; } CboFiles.DataSource = GetWorkbooks(); UnloadWorkBook(); } catch (Exception ex) { ErrorManagement.Log(ex); } finally { if (waitingMessage != null) { waitingMessage.CloseMessage(); } } }
private void BtnExport_Click(object sender, EventArgs e) { WaitingMessage.WaitingMessage waitingMessage = null; try { if (BtnSave.Enabled) { if (MessageBox.Show("Do you want to save changes before exporting data?" + Environment.NewLine + "All changes will otherwise be discarded!", "Usaved changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Save(); } } string fileName = Path.Combine(new FileInfo(Application.ExecutablePath.Replace("/", "\\")).Directory.FullName, OpenedFile.Name); if (File.Exists(fileName)) { File.Delete(fileName); } using (ExcelPackage pck = new ExcelPackage(new FileInfo(fileName))) { waitingMessage = new WaitingMessage.WaitingMessage("Please wait while data are being exported." + Environment.NewLine + "This may take few seconds", "Exporting data", 2); int amountWorksheets = OpenedFile.WorkSheets.Count; int indexWs = 0; foreach (WorkSheet ws in OpenedFile.WorkSheets.Values) { pck.Workbook.Worksheets.Add(ws.Name); int amountCells = ws.Cells.Count; int indexCell = 0; waitingMessage.Controller.ReinitPercent(); ExcelWorksheet worksheet = pck.Workbook.Worksheets[ws.Name]; foreach (Cell cell in ws.Cells.Values) { worksheet.Cells[cell.Row, ColumnToInt(cell.Column)].Value = cell.CurrentValue; indexCell += 100; waitingMessage.SetPercent(indexCell / amountCells, 1); } indexWs += 100; waitingMessage.SetPercent(indexWs / amountWorksheets); } saveFileDialog.FileName = OpenedFile.Name; saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (saveFileDialog.ShowDialog() != DialogResult.OK) { return; } FileInfo fileInfo = new FileInfo(saveFileDialog.FileName); if (fileInfo.Exists) { fileInfo.IsReadOnly = false; fileInfo.Delete(); } pck.SaveAs(fileInfo); Process.Start(saveFileDialog.FileName); } } catch (Exception ex) { ErrorManagement.Log(ex); } finally { if (waitingMessage != null) { waitingMessage.CloseMessage(); } } }
private void CboWorkSheets_SelectedIndexChanged(object sender, EventArgs e) { WaitingMessage.WaitingMessage waitingMessage = null; LvWorksheet.Clear(); if (CboWorkSheets.SelectedIndex == -1) { return; } try { Cursor.Current = Cursors.WaitCursor; LvWorksheet.Columns.Add(string.Empty); List <string> columns = new List <string> { " " }; WorkSheet workSheet = OpenedFile.WorkSheets[((ItemData)CboWorkSheets.SelectedItem).Name]; waitingMessage = new WaitingMessage.WaitingMessage("Loading worksheet", "Please wait while the worksheet is loading." + Environment.NewLine + "This may take few seconds...", 0); // First loop to create as many columns in the ListView as there were in the Excel file foreach (KeyValuePair <int, string> kvp in workSheet.Cells.Keys) { string column = kvp.Value; if (!columns.Contains(column)) { LvWorksheet.Columns.Add(column, column, -1, HorizontalAlignment.Center, string.Empty); columns.Add(column); } } // and as many items as there were rows in the file Dictionary <int, List <Cell> > cells = workSheet.Cells.Values .GroupBy(c => c.Row) .OrderBy(cgb => cgb.Key) .ToDictionary(cgb => cgb.Key, cgb => cgb.Select(c => c) .ToList()); foreach (int row in cells.Keys) { ListViewItem lvi = new ListViewItem(row.ToString()); for (int noColumn = 1; noColumn < columns.Count; noColumn += 1) { lvi.SubItems.Add(string.Empty); } LvWorksheet.Items.Add(lvi); foreach (Cell cell in cells[row]) { cell.ListViewItem = lvi; } } // Second loop to actually fill in the ListView with the data read from the Excel file int index = 0; foreach (Cell cell in workSheet.Cells.Values) { ListViewItem lvi = cell.ListViewItem; lvi.SubItems[columns.IndexOf(cell.Column)].Text = cell.OriginalValue; lvi.SubItems[columns.IndexOf(cell.Column)].Tag = cell; lvi.Checked = cell.Included; index += 1; } // Ajust the columns width LvWorksheet.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); LblWSNameTxt.Text = workSheet.Name; LblAmountRowsTxt.Text = LvWorksheet.Items.Count.ToString(); LblOriginalAmountRowsTxt.Text = LvWorksheet.Items[LvWorksheet.Items.Count - 1].Text; LblAmountColumnsTxt.Text = (LvWorksheet.Columns.Count - 1).ToString(); } catch (Exception ex) { ErrorManagement.Log(ex); } finally { if (waitingMessage != null) { waitingMessage.CloseMessage(); } EnableSaving(false); EnableExport(true); EnableDelete(true); Cursor.Current = Cursors.Default; } }