Exemple #1
0
        private void buttonCreateManually_Click(object sender, EventArgs e)
        {
            List <StudentUserModel> studentList = new List <StudentUserModel>();
            var createManual = new CreateManualFrom(faculty, studentList);

            createManual.FormClosed += new FormClosedEventHandler(dash_FormClosed);
            createManual.Show();
            this.Hide();
        }
        private void buttonOpen_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(textBoxFileName.Text))
                {
                    throw new Exception("Please select an Excel file using the browse button");
                }
                if (!textBoxFileName.Text.EndsWith(".xlsx"))
                {
                    throw new Exception("Invalid file. Please select an .xlsx file");
                }
                if (comboBoxSheet.Items.Count == 0)
                {
                    throw new Exception("Sheets failed to load. Please try again");
                }
                if (comboBoxSheet.SelectedIndex == -1)
                {
                    throw new Exception("Please select a sheet from the dropdown to import that sheet");
                }
                if (dt.Columns.Count < 2)
                {
                    throw new Exception("Sheet doesn't contain enough columns. Please select a proper sheet");
                }

                if (dt.Columns.Count > 2)
                {
                    DialogResult dialogResult = MessageBox.Show("Sheet contains more than two columns. Column 1 will be rendered as Academic ID and column 2 will be rendered as Name. Continue?", "Confirm", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        try
                        {
                            var createManual = new CreateManualFrom(faculty, GenerateStudents(dt));
                            createManual.FormClosed += new FormClosedEventHandler(dash_FormClosed);
                            createManual.Show();
                            this.Hide();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                else
                {
                    try
                    {
                        var createManual = new CreateManualFrom(faculty, GenerateStudents(dt));
                        createManual.FormClosed += new FormClosedEventHandler(dash_FormClosed);
                        createManual.Show();
                        this.Hide();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }