예제 #1
0
 private void btnBrowse_Click(object sender, EventArgs e)
 {
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         if (openFileDialog1.SafeFileName.Split('.').Last() == "xlsx")
         {
             txtLoaded.Text = openFileDialog1.FileName;
             this.Text      = "Effay - " + openFileDialog1.SafeFileName;
             Effay.Text     = "Effay - " + openFileDialog1.SafeFileName;
             populateList(openFileDialog1.FileName);
         }
         else
         {
             msgbox err = new msgbox("Please select a valid Excel file.", "Error", 1);
             err.Show();
         }
     }
 }
예제 #2
0
        void populateList(string filePath)
        {
            drivers.Clear();
            listDrivers.Items.Clear();

            int[] emptyColumns = { 18, 16, 6, 4, 1 };

            try {
                using (cXML.XLWorkbook workbook = new cXML.XLWorkbook(filePath))
                {
                    var worksheet = workbook.Worksheets.First();
                    var range     = worksheet.RangeUsed();

                    for (int i = 1; i < range.RowCount() + 1; i++)
                    {
                        drivers.Add(new Driver());
                        int skipped = 0;
                        for (int j = 1; j < range.ColumnCount() + 2; j++)
                        {
                            if (!emptyColumns.Contains(j) && (!String.IsNullOrEmpty(worksheet.Cell(i, 3).Value.ToString())) && worksheet.Cell(i, 3).Value.ToString() != "Driver")
                            {
                                drivers[i - 1].SetAttrib(j - skipped, worksheet.Cell(i, j).Value.ToString());
                                //MessageBox.Show((j - skipped).ToString() + "::" + worksheet.Cell(i, j).Value.ToString());
                            }
                            else if (started && !emptyColumns.Contains(j) && String.IsNullOrEmpty(worksheet.Cell(i, 3).Value.ToString()))
                            {
                                averageDriver.SetAttrib(j - skipped, worksheet.Cell(i, j).Value.ToString());
                            }
                            else
                            {
                                skipped++;
                            }
                        }
                        started = averageDriver.Empty();
                    }
                }
            } catch
            {
                msgbox err = new msgbox("Error, selected Excel file is currently being used by another program.", "Error", 1);
                err.Show();
            }

            for (int i = drivers.Count - 1; i >= 0; i--)
            {
                if (drivers[i].Empty())
                {
                    drivers.RemoveAt(i);
                }
                else if (drivers[i].RunCount < nmMinimum.Value)
                {
                    drivers.RemoveAt(i);
                }
            }

            foreach (Driver driver in drivers)
            {
                try
                {
                    float skip       = 0;
                    float efficiency = 0;
                    float divideBy   = 0;

                    if (attributes.ContainsKey(8))
                    {
                        skip += attributes[8].weight;                                // Skip NegWait
                    }
                    foreach (int attrib in attributes.Keys)
                    {
                        efficiency += CompareAttrib(attrib, driver, averageDriver) * (attributes[attrib].weight);
                        divideBy   += attributes[attrib].weight;
                    }

                    efficiency       /= divideBy - skip;
                    efficiency       *= 100;
                    driver.Efficiency = efficiency;
                } catch
                {
                }
            }

            sortDrivers();

            foreach (Driver driver in drivers)
            {
                listDrivers.Items.Add(driver.Name + "\t" + driver.Efficiency.ToString("0.00") + "%");
            }
        }