Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace Multi_Demo
  13. {
  14.     public partial class mainForm : Form
  15.     {
  16.         public struct Invoices
  17.         {
  18.             public int number;
  19.             public DateTime date;
  20.             public int customerNumber;
  21.             public double invoiceAmount;
  22.             public int Aging;
  23.         }
  24.  
  25.         public static Invoices[] theInvoice = new Invoices[100];
  26.         public static int arraySize = 0;
  27.         public mainForm()
  28.         {
  29.             InitializeComponent();
  30.         }
  31.  
  32.         private void loadButton_Click(object sender, EventArgs e)
  33.         {
  34.             openDialog.ShowDialog();
  35.  
  36.             String fileName = "";
  37.  
  38.             try
  39.             {
  40.                 fileName = openDialog.FileName;
  41.             }
  42.             catch { }
  43.  
  44.             if (File.Exists(fileName) && fileName.Contains(".csv") )
  45.             {
  46.                 loadCSV(fileName);
  47.  
  48.                 showButton.Enabled = true;
  49.  
  50.             }
  51.             else
  52.             {
  53.                 MessageBox.Show("Invalid Filename...");
  54.             }
  55.  
  56.         }
  57.  
  58.         public static void loadCSV(String theFileName)
  59.         {
  60.             StreamReader inFile = new StreamReader(theFileName);
  61.             int currentIndex = 0;
  62.             bool isOk = true;
  63.             while (!inFile.EndOfStream)
  64.             {
  65.                 String aLine = inFile.ReadLine();
  66.                 String[] theInvoices = aLine.Split(',');
  67.                 Invoices aInvoice;
  68.  
  69.                 isOk = Int32.TryParse(theInvoices[0], out aInvoice.number);
  70.                 if (isOk == false)
  71.                 {
  72.                     MessageBox.Show("Invalid Invoice Number" + theInvoices[0] + " Line" + currentIndex+1);
  73.                 }
  74.  
  75.                 isOk = DateTime.TryParse(theInvoices[1], out aInvoice.date);
  76.                 if (isOk == false)
  77.                 {
  78.                     MessageBox.Show("Invalide Date" + theInvoices[1] + " Line" + currentIndex + 1);
  79.                 }
  80.  
  81.                 isOk = Int32.TryParse(theInvoices[2], out aInvoice.customerNumber);
  82.                 if (isOk == false)
  83.                 {
  84.                     MessageBox.Show("Invalid Customer Number" + theInvoices[2] + " Line" + currentIndex + 1);
  85.                 }
  86.                        
  87.                 isOk = Double.TryParse(theInvoices[3], out aInvoice.invoiceAmount);
  88.                 if (isOk == false)
  89.                 {
  90.                     MessageBox.Show("Invalid Amount" + theInvoices[3] + " Line" + currentIndex + 1);
  91.                 }
  92.                            
  93.                 isOk = Int32.TryParse(theInvoices[4], out aInvoice.Aging);
  94.                 if (isOk == false)
  95.                 {
  96.                     MessageBox.Show("Invalid Aging" + theInvoices[4] + " Line" + currentIndex + 1);
  97.                 }
  98.  
  99.                 theInvoice[currentIndex] = aInvoice;
  100.                 currentIndex++;
  101.             }
  102.             inFile.Close();
  103.  
  104.             arraySize = currentIndex;
  105.         }
  106.  
  107.         private void showButton_Click(object sender, EventArgs e)
  108.         {
  109.             detailedForm details = new detailedForm();
  110.             details.Show();
  111.         }
  112.  
  113.         private void button1_Click(object sender, EventArgs e)
  114.         {
  115.             Environment.Exit(0);
  116.         }
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement