Esempio n. 1
0
        private void обновитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Tmass.Clear();
            Aud.Clear();
            Auditor.ClearExistc();
            comboBox1.Items.Clear();
            Cursor.Current = Cursors.WaitCursor;
            mass.Clear();
            start(linkb, linkm);
            comboBox1.SelectedIndex = 0;

            Cursor.Current = Cursors.Arrow;
        }
Esempio n. 2
0
        private void загрузитьРасписаниеВсехToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Tmass.Clear();
            Aud.Clear();
            Auditor.ClearExistc();
            comboBox1.Items.Clear();
            Cursor.Current = Cursors.WaitCursor;
            mass.Clear();
            List <string> massOther = new List <string>();

            for (int i = 1; i <= 53; i++)
            {
                start(("https://portal.esstu.ru/bakalavriat/Caf" + i.ToString() + ".htm").ToString(), ("https://portal.esstu.ru/spezialitet/Caf" + i.ToString() + ".htm").ToString());
            }
            comboBox1.SelectedIndex = 0;

            Cursor.Current = Cursors.Arrow;
        }
Esempio n. 3
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                Tmass.Clear();
                Aud.Clear();
                Auditor.ClearExistc();
                comboBox1.Items.Clear();
                Cursor.Current = Cursors.WaitCursor;
                mass.Clear();
                start(linkb, linkm);
                comboBox1.SelectedIndex = 0;

                Cursor.Current = Cursors.Arrow;
            }
            else if (e.KeyCode == Keys.F2)
            {
                string fileName = System.Windows.Forms.Application.StartupPath + "\\" + "Shablon" + ".xlsx";
                Cursor.Current = Cursors.WaitCursor;
                //fileName_new = System.Windows.Forms.Application.StartupPath + "\\" + "Shablon_new" + ".xlsx";
                try
                {
                    //Приложение самого Excel
                    var excelapp = new Excel.Application();
                    excelapp.Visible = false;
                    //Книга.
                    var excelappworkbooks = excelapp.Workbooks;
                    excelapp.Workbooks.Open(fileName,
                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                            Type.Missing, Type.Missing);
                    var excelappworkbook = excelappworkbooks[1];
                    //Получаем массив ссылок на листы выбранной книги
                    var excelsheets = excelappworkbook.Worksheets;
                    //Выбираем лист 1
                    var excelworksheet = (Excel.Worksheet)excelsheets.get_Item(1);


                    for (int m = 3; m < 2 + Tmass.Count * 2; m += 2)
                    {
                        var excelcells = (Excel.Range)excelworksheet.Cells[2, m];
                        excelcells.Value2 = Tmass[(m - 2) / 2].getname();
                    }
                    for (int m = 2; m < 2 + Tmass.Count * 2; m++)
                    {
                        for (int n = 3; n < 50; n++)
                        {
                            var excelcells = (Excel.Range)excelworksheet.Cells[n, m + 1];
                            int plus       = 0;
                            if ((m + 1) % 2 == 0)
                            {
                                plus = 6;
                            }
                            if ((n - 3) % 8 < 6)
                            {
                                excelcells.Value2 = Tmass[(m - 2) / 2].getsubject((n - 3) / 8 + (plus), (n - 3) % 8);
                            }
                            //excelworksheet.Cells[m, n] = Tmass[(m - 2) / 2].getsubject((n - 2) / 8, (n - 2) % 8);
                        }
                    }

                    if (saveFileDialog1.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                    // получаем выбранный файл
                    string filename_new = saveFileDialog1.FileName;
                    // сохраняем текст в файл
                    excelworksheet.SaveAs(filename_new);
                    Cursor.Current = Cursors.Arrow;
                    MessageBox.Show("Файл сохранен", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);


                    excelappworkbook.Close();
                    excelappworkbooks.Close();

                    excelapp.Quit();
                }
                catch
                {
                    MessageBox.Show("Нету доступа к Excel файлу шаблона.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (e.KeyCode == Keys.F3)
            {
                Form2 Input = new Form2();
                for (int i = 0; i < Aud.Count; i++)
                {
                    Input.comboBox1.Items.Add(Aud[i].getname());
                }
                Input.comboBox1.SelectedIndex = 0;
                Input.ShowDialog();
                int selected = Input.comboBox1.SelectedIndex;
                if (Input.flagger == false)
                {
                    return;
                }
                ///////////
                Cursor.Current = Cursors.WaitCursor;


                string fileName = System.Windows.Forms.Application.StartupPath + "\\" + "Shabaud" + ".xlsx";
                //fileName_new = System.Windows.Forms.Application.StartupPath + "\\" + "Shabaud_new" + ".xlsx";

                try
                {
                    //Приложение самого Excel
                    var excelapp = new Excel.Application();
                    excelapp.Visible = false;
                    //Книга.
                    var excelappworkbooks = excelapp.Workbooks;
                    excelapp.Workbooks.Open(fileName,
                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                            Type.Missing, Type.Missing);
                    var excelappworkbook = excelappworkbooks[1];
                    //Получаем массив ссылок на листы выбранной книги
                    var excelsheets = excelappworkbook.Worksheets;
                    //Выбираем лист 1
                    var excelworksheet = (Excel.Worksheet)excelsheets.get_Item(1);

                    ///ввод названия ячейки
                    {
                        var excelcells = (Excel.Range)excelworksheet.Cells[2, 1];
                        excelcells.Value2 = Aud[selected].getname();
                    }
                    for (int m = 2; m < 8; m++)//столбцы
                    {
                        for (int n = 3; n < 14; n++)
                        {
                            var excelcells = (Excel.Range)excelworksheet.Cells[n, m];
                            int plus       = 0;
                            if (n % 2 == 0)
                            {
                                plus = 6;
                            }
                            if (Aud[selected].getsubject(m - 2 + plus, (n - 3) / 2) != null)
                            {
                                excelcells.Value2 = Aud[selected].getsubject(m - 2 + plus, (n - 3) / 2);
                            }
                            //excelworksheet.Cells[m, n] = Tmass[(m - 2) / 2].getsubject((n - 2) / 8, (n - 2) % 8);
                        }
                    }



                    saveFileDialog1.FileName = Input.comboBox1.SelectedItem.ToString();
                    if (saveFileDialog1.ShowDialog() == DialogResult.Cancel)
                    {
                        return;
                    }
                    // получаем выбранный файл
                    string filename_new = saveFileDialog1.FileName;
                    excelworksheet.SaveAs(filename_new);
                    Cursor.Current = Cursors.Arrow;
                    MessageBox.Show("Файл сохранен", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);


                    excelappworkbook.Close();
                    excelappworkbooks.Close();

                    excelapp.Quit();
                }
                catch
                {
                    MessageBox.Show("Нету доступа к Excel файлу шаблона.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }