Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. public List<List<Item>> CreateLists(bool showError)
  2.             {
  3.                 List<List<Item>> l = new List<List<Item>>();
  4.  
  5.                 for (int x = 1; x <= Workbook.Worksheets.Count; x++)
  6.                 {
  7.                     l.Add(new List<Item>());
  8.                     for (int index = 2; ; index++)
  9.                     {
  10.                         using (var val = Workbook.Worksheet(x))
  11.                         {
  12.                             if (val.Cell("A" + index).Value == null || val.Cell("A" + index).Value.ToString() == "")
  13.                             {
  14.                                 break;
  15.                             }
  16.                         }
  17.                         var i = new Item();
  18.                         try
  19.                         {
  20.                             switch (x)
  21.                             {
  22.                                 case 1:
  23.                                     i = new CPU();
  24.                                     i.ReadExcelData(Workbook.Worksheet(x).Row(index));
  25.                                     break;
  26.                                 case 2:
  27.                                     i = new RAM();
  28.                                     i.ReadExcelData(Workbook.Worksheet(x).Row(index));
  29.                                     break;
  30.                                 case 3:
  31.                                     i = new RAM();
  32.                                     i.ReadExcelData(Workbook.Worksheet(x).Row(index));
  33.                                     break;
  34.                                 case 4:
  35.                                     i = new Flash();
  36.                                     i.ReadExcelData(Workbook.Worksheet(x).Row(index));
  37.                                     break;
  38.                                 default:
  39.                                     break;
  40.                             }
  41.                         }
  42.                         catch (Exception e)
  43.                         {
  44.                             Thread.Sleep(5000);
  45.                             if (e.GetType().Name == "IOException")
  46.                             {
  47.                                 index--;
  48.                                 continue;
  49.                             }
  50.                             else if (showError)
  51.                             {
  52.                                 System.Windows.MessageBox.Show("Data entered incorrectly in row " + index + " of " + Workbook.Worksheet(x).Name + ". Please correct the data and reload.", "Data Entry Error", MessageBoxButton.OK, MessageBoxImage.Error);
  53.                                 continue;
  54.                             }
  55.                             else
  56.                             {
  57.                                 continue;
  58.                             }
  59.                         }
  60.                         System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  61.                         {
  62.                             i.CreateCardGrid();
  63.                         }));
  64.                         l[x - 1].Add(i);
  65.                     }
  66.                 }
  67.                 return l;
  68.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement