Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace Multi_Demo
- {
- public partial class mainForm : Form
- {
- public struct Invoices
- {
- public int number;
- public DateTime date;
- public int customerNumber;
- public double invoiceAmount;
- public int Aging;
- }
- public static Invoices[] theInvoice = new Invoices[100];
- public static int arraySize = 0;
- public mainForm()
- {
- InitializeComponent();
- }
- private void loadButton_Click(object sender, EventArgs e)
- {
- openDialog.ShowDialog();
- String fileName = "";
- try
- {
- fileName = openDialog.FileName;
- }
- catch { }
- if (File.Exists(fileName) && fileName.Contains(".csv") )
- {
- loadCSV(fileName);
- showButton.Enabled = true;
- }
- else
- {
- MessageBox.Show("Invalid Filename...");
- }
- }
- public static void loadCSV(String theFileName)
- {
- StreamReader inFile = new StreamReader(theFileName);
- int currentIndex = 0;
- bool isOk = true;
- while (!inFile.EndOfStream)
- {
- String aLine = inFile.ReadLine();
- String[] theInvoices = aLine.Split(',');
- Invoices aInvoice;
- isOk = Int32.TryParse(theInvoices[0], out aInvoice.number);
- if (isOk == false)
- {
- MessageBox.Show("Invalid Invoice Number" + theInvoices[0] + " Line" + currentIndex+1);
- }
- isOk = DateTime.TryParse(theInvoices[1], out aInvoice.date);
- if (isOk == false)
- {
- MessageBox.Show("Invalide Date" + theInvoices[1] + " Line" + currentIndex + 1);
- }
- isOk = Int32.TryParse(theInvoices[2], out aInvoice.customerNumber);
- if (isOk == false)
- {
- MessageBox.Show("Invalid Customer Number" + theInvoices[2] + " Line" + currentIndex + 1);
- }
- isOk = Double.TryParse(theInvoices[3], out aInvoice.invoiceAmount);
- if (isOk == false)
- {
- MessageBox.Show("Invalid Amount" + theInvoices[3] + " Line" + currentIndex + 1);
- }
- isOk = Int32.TryParse(theInvoices[4], out aInvoice.Aging);
- if (isOk == false)
- {
- MessageBox.Show("Invalid Aging" + theInvoices[4] + " Line" + currentIndex + 1);
- }
- theInvoice[currentIndex] = aInvoice;
- currentIndex++;
- }
- inFile.Close();
- arraySize = currentIndex;
- }
- private void showButton_Click(object sender, EventArgs e)
- {
- detailedForm details = new detailedForm();
- details.Show();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Environment.Exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement