private void buttonImport_Click(object sender, EventArgs e) { MaximizeForm(); buttonImport.Visible = false; buttonCancel.Visible = true; buttonClose.Enabled = false; String[] files = Directory.GetFiles(textBoxFolderLocation.Text, "*.xlsx"); importitems = new importItem[files.Length]; importitemscount = 0; importitemscounter = 0; foreach (String file in files) { importItem importitem = new importItem(file); importitems[importitemscount] = importitem; importitemscount++; } cancelclicked = false; listViewStatus.Items.Clear(); addStatusItem("Import started...", "", 1); timerImport.Start(); }
private void timerImport_Tick(object sender, EventArgs e) { timerImport.Stop(); if (!cancelclicked) { importItem importitem = importitems[importitemscounter]; if (!importitem.Processed) { if (importitem.Import()) { if (importitem.Imported) { addStatusItem("Imported " + importitem.File, importitem.InvoiceNumber.ToString(), 1); } else { addStatusItem("Failed to import " + importitem.File, importitem.ErrorMessage, 3); } } } importitemscounter++; if (this.importitemscounter < this.importitemscount) { timerImport.Start(); } else { buttonImport.Visible = true; buttonCancel.Visible = false; buttonClose.Enabled = true; addStatusItem("Import completed", "", 1); } } }