Esempio n. 1
0
        private void load_button_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog;
            ExcelFile      loadedFile;
            string         day = null, start_hour = null, stop_hour = null, final_hours = null, curs_hours = null, pregatire_hours = null, recuperare_hours = null;
            bool           first_run = true, finish = false, write = true;
            int            j = 0;

            openFileDialog = new OpenFileDialog
            {
                Title = "Browse Excel Files",

                CheckFileExists  = true,
                CheckPathExists  = true,
                RestoreDirectory = true,

                DefaultExt  = "xlsx",
                Filter      = "xlsx files (*.xlsx)|*.xlsx",
                FilterIndex = 2,

                ShowReadOnly = true
            };

            if (openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            loadedFile = ExcelFile.Load(openFileDialog.FileName);

            total_rows = 0;

            foreach (ExcelWorksheet worksheet in loadedFile.Worksheets)
            {
                foreach (ExcelRow row in worksheet.Rows)
                {
                    if (write && !first_run && !finish)
                    {
                        foreach (ExcelCell cell in row.AllocatedCells)
                        {
                            if (cell.ValueType != CellValueType.Null)
                            {
                                if (String.Equals(cell.Value.ToString(), "TOTAL:"))
                                {
                                    finish = true;
                                    break;
                                }
                                setLoad(cell, j, ref day, ref start_hour, ref stop_hour, ref curs_hours, ref pregatire_hours, ref recuperare_hours, ref final_hours);
                                ++j;
                                write = true;
                            }
                            write = false;
                        }
                        elements.Add(new WorkStuff(day, start_hour, stop_hour, curs_hours, pregatire_hours, recuperare_hours, final_hours));
                        setLoad(total_rows);
                        ++total_rows;
                        j = 0;
                    }
                    first_run = false;
                }
            }

            MessageBox.Show("File loaded!");

            load_button.Enabled      = false;
            save_button.Enabled      = true;
            get_hours_normal.Enabled = true;
        }