Пример #1
0
        private void exportInventoryToCSV()
        {
            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\inventory.csv"))
                {
                    File.Delete(Application.StartupPath + @"\database\temp\inventory.csv");
                }
                //now we get the value of all input and selection fields and convert them to appropriate data type
                exportToCSV CSV = new exportToCSV();
                CSV.createInventoryCSVDocument();

                string year = textBoxSaveToCSVEndYear.Text;
                try
                {
                    if (File.Exists(Application.StartupPath + @"\database\" + year + @"\maintenence\inventory\list.xml"))
                    {

                        CSV.generateInventoryCSVDocument(Application.StartupPath + @"\database\" + year + @"\maintenence\inventory\list.xml",
                        DateTime.Now.ToString("d/MM/yyyy"), "items");
                    }

                }
                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 = "myInventory.csv";
                progressBar1.Value = 50;

                save.ShowDialog();
                File.Copy(Application.StartupPath + @"\database\temp\inventory.csv", save.FileName);
                //exportCSVValidate.Text = "File Saved";
                //delete temp file
                File.Delete(Application.StartupPath + @"\database\temp\inventory.csv");
                progressBar1.Value = 100;

            }
            catch (Exception err)
            {

                exportCSVValidate.Text = "File was not saved";
                progressBar1.Value = 0;
                if (File.Exists(Application.StartupPath + @"\database\temp\inventory.csv"))
                {
                    File.Delete(Application.StartupPath + @"\database\temp\inventory.csv");
                    debugTerminal terminal = new debugTerminal();
                    terminal.output(err.ToString());
                }
            }
        }