private void exportProvidersToCSV() { try { //first step is too check if temp file exists and if it does delete it //to start again if (File.Exists(Application.StartupPath + @"\database\temp\providers.csv")) { File.Delete(Application.StartupPath + @"\database\temp\providers.csv"); } //now we get the value of all input and selection fields and convert them to appropriate data type exportToCSV CSV = new exportToCSV(); CSV.createProvidersCSVDocument(); string year = textBoxSaveToCSVEndYear.Text; try { if (File.Exists(Application.StartupPath + @"\database\" + year + @"\contractors\providers\lists\providers.xml")) { CSV.generateProvidersCSVDocument(Application.StartupPath + @"\database\" + year + @"\contractors\providers\lists\providers.xml", DateTime.Now.ToString("d/MM/yyyy"), "provider"); } } catch (Exception err) { debugTerminal terminal = new debugTerminal(); terminal.output(err.ToString()); } //now we let the user save the temp excel file SaveFileDialog save = new SaveFileDialog(); save.Filter = "Excel|*.CSV"; save.FileName = "myProvidersList.csv"; progressBar1.Value = 50; save.ShowDialog(); File.Copy(Application.StartupPath + @"\database\temp\providers.csv", save.FileName); //exportCSVValidate.Text = "File Saved"; //delete temp file File.Delete(Application.StartupPath + @"\database\temp\providers.csv"); progressBar1.Value = 100; } catch (Exception err) { exportCSVValidate.Text = "File was not saved"; progressBar1.Value = 0; if (File.Exists(Application.StartupPath + @"\database\temp\providers.csv")) { File.Delete(Application.StartupPath + @"\database\temp\providers.csv"); debugTerminal terminal = new debugTerminal(); terminal.output(err.ToString()); } } }
private void exportMaintenenceToCSV() { try { //first step is too check if temp file exists and if it does delete it //to start again if (File.Exists(Application.StartupPath + @"\database\temp\maintenence.csv")) { File.Delete(Application.StartupPath + @"\database\temp\maintenence.csv"); } //now we get the value of all input and selection fields and convert them to appropriate data type int sd = Convert.ToInt32(textBoxSaveToCSVStartDate.Text); int fd = Convert.ToInt32(textBoxSaveToCSVEndDay.Text); if (sd > 0 && sd < 31 && fd > 0 && fd < 31) { string sm = comboBoxSaveToCSVStartMonth.Text; string fm = comboBoxSaveToCSVEndMonth.Text; string sy = textBoxSaveToCSVStartYear.Text; string fy = textBoxSaveToCSVEndYear.Text; applicationCore apc = new applicationCore(fileNameDate); exportToCSV CSV = new exportToCSV(); //get selected months as numbers int startMonth = apc.getMonthAsInt(sm); int endMonth = apc.getMonthAsInt(fm); int nsy = Convert.ToInt32(sy); int nfy = Convert.ToInt32(fy); //now we get data from each file between te selected time period //based on its date based file name CSV.createMaintenenceCSVDocument(); //loop through years for (int y = nsy; y <= nfy; y++) { //loop through months for (int m = startMonth; m <= endMonth; m++) { //loop through days for (int d = sd; d <= 31; d++) { try { if (File.Exists(Application.StartupPath + @"\database\" + y + @"\maintenence\" + d + "-" + m + "-" + y + ".xml")) { CSV.generateMaintenenceCSVDocument(Application.StartupPath + @"\database\" + y + @"\maintenence\" + d + "-" + m + "-" + y + ".xml", DateTime.Now.ToString("d/MM/yyyy"), "item"); } } catch (Exception err) { debugTerminal terminal = new debugTerminal(); terminal.output(err.ToString()); } } } } //now we let the user save the temp excel file SaveFileDialog save = new SaveFileDialog(); save.Filter = "Excel|*.CSV"; save.FileName = "myMaintenenceCheckList.csv"; progressBar1.Value = 50; save.ShowDialog(); File.Copy(Application.StartupPath + @"\database\temp\maintenence.csv", save.FileName); //exportCSVValidate.Text = "File Saved"; //delete temp file File.Delete(Application.StartupPath + @"\database\temp\maintenence.csv"); progressBar1.Value = 100; } else { exportCSVValidate.Text = "The days added were not correct month numbers"; } } catch (Exception err) { exportCSVValidate.Text = "File was not saved"; progressBar1.Value = 0; if (File.Exists(Application.StartupPath + @"\database\temp\maintenence.csv")) { File.Delete(Application.StartupPath + @"\database\temp\maintenence.csv"); debugTerminal terminal = new debugTerminal(); terminal.output(err.ToString()); } } }