2 using System.Collections.Generic;
5 using System.Threading.Tasks;
10 namespace GUI.IO_Modules
28 private Dictionary<String, int> locationDictionary =
new Dictionary<String, int>();
44 OleDbConnectionStringBuilder csbuilder =
new OleDbConnectionStringBuilder();
45 csbuilder.Provider =
"Microsoft.ACE.OLEDB.12.0";
46 csbuilder.DataSource = Dir;
47 csbuilder.Add(
"Extended Properties",
"Excel 12.0 Xml");
49 DataTable sheet1 =
new DataTable();
50 using (OleDbConnection connection =
new OleDbConnection(csbuilder.ConnectionString))
54 string sqlQuery =
@"SELECT * FROM [Allgemein$]";
55 using (OleDbDataAdapter adapter =
new OleDbDataAdapter(sqlQuery, connection))
59 createLocations(sheet1);
63 foreach (String SheetName
in locationNames)
65 sheet1 =
new DataTable();
66 using (OleDbConnection connection =
new OleDbConnection(csbuilder.ConnectionString))
70 string sqlQuery =
@"SELECT * FROM [Standort_" + SheetName +
"$]";
71 using (OleDbDataAdapter adapter =
new OleDbDataAdapter(sqlQuery, connection))
75 createMachines(sheet1, SheetName);
97 return locationDictionary;
115 return machinesAtLocation;
124 return productsAtLocation;
133 locationNames =
new String[Convert.ToInt32(sheet.Columns[0].Caption)];
134 for (
int i = 0; i < locationNames.Length; i++)
137 locationNames[i] = sheet.Rows[i].ItemArray[0].ToString();
140 int numberOfLocations = locationNames.Length;
141 locations =
new LocationCB[numberOfLocations];
142 machinesAtLocation =
new List<MachineCB>[numberOfLocations];
143 productsAtLocation =
new List<ProductCB>[numberOfLocations];
146 foreach (String s
in locationNames)
148 locationDictionary.Add(s, counter);
149 locations[counter] =
new LocationCB(s, Convert.ToDouble(sheet.Rows[counter].ItemArray[4]));
150 machinesAtLocation[counter] =
new List<MachineCB>();
151 productsAtLocation[counter] =
new List<ProductCB>();
163 int numOfMachines = (sheet.Columns.Count - 1) / 3;
164 LocationCB loc = locations[locationDictionary[LocationName]];
165 for (
int i = 0; i < numOfMachines; i++)
167 String Machinename = sheet.Columns[1 + 3 * i].ToString();
169 machinesAtLocation[locationDictionary[LocationName]].Add(m);
170 createProducts(sheet, m, 1 + 3 * i);
182 for (
int i = 1; i < sheet.Rows.Count;i++)
184 DataRow d= sheet.Rows[i];
185 if (!d[indexOfMachine].ToString().Equals(
""))
187 ProductCB p =
new ProductCB(d[0].ToString(), m, Convert.ToDouble(d[indexOfMachine]), Convert.ToDouble(d[indexOfMachine+1]), Convert.ToDouble(d[indexOfMachine+2]));
188 productsAtLocation[0].Add(p);
void createMachines(DataTable sheet, String LocationName)
Creates the machine Checkboxes.
This class reads all the important data out of an Excel file and creates all the Checkboxes we need...
LocationCB[] GetAllLocations()
Grants access to the location array.
String Dir
Directory CheckboxCreator reads from.
LocationCB[] locations
Array that contains all of the locations.
CheckboxCreator(String dir)
Constructor.
void Create()
Reads all the Data from Dir + "\\Dataset.xlsx".
List< MachineCB >[] GetAllMachines()
Grants access to the machine checkboxes.
A wrapper class for products.
A wrapper class for locations.
List< ProductCB >[] GetAllProducts()
Grants access to the product checkboxes.
void createLocations(DataTable sheet)
Creates the location Checkboxes.
List< ProductCB >[] productsAtLocation
All products at a specific location.
String[] locationNames
Array that contains all of the locations' names.
A wrapper class for machines.
List< MachineCB >[] machinesAtLocation
All machines at a specific location.
Dictionary< String, int > GetLocationDict()
Grants access to the location dictionary.
void createProducts(DataTable sheet, MachineCB m, int indexOfMachine)
Creates the product Checkboxes.
String[] GetLocationNames()
Grants access to the all the location names.