コード例 #1
0
ファイル: Dialog.cs プロジェクト: Ololol91/KPOFinalProject
        private void button1_Click(object sender, EventArgs e)
        {
            InitTablesList();
            DataSet dataSet = new DataSet();

            SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
            foreach (string table in Tables)
            {
                if (table == "Test")
                {
                    Test   tst = new Test();
                    string sql = tst.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }

                if (table == "Тип")
                {
                    Type   tp  = new Type();
                    string sql = tp.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }
                if (table == "Поставщик")
                {
                    Provider pr  = new Provider();
                    string   sql = pr.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }
                if (table == "Страна")
                {
                    Country c   = new Country();
                    string  sql = c.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }
                if (table == "Клиент")
                {
                    Client cl  = new Client();
                    string sql = cl.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }
                if (table == "Должность")
                {
                    Post   ps  = new Post();
                    string sql = ps.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }
                if (table == "Производитель")
                {
                    Creator cr  = new Creator();
                    string  sql = cr.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }
                if (table == "Товар")
                {
                    Product p   = new Product();
                    string  sql = p.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }
                if (table == "Заказ")
                {
                    Order  or  = new Order();
                    string sql = or.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }
                if (table == "Сотрудник")
                {
                    Employee em  = new Employee();
                    string   sql = em.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }

                if (table == "Отправка")
                {
                    Sending send = new Sending();
                    string  sql  = send.SelectShow;
                    dataSet.Tables.Add(controll.InitDT(sql));
                }
            }

            // Create new ExcelFile.
            ExcelFile workbook2 = new ExcelFile();

            // Imports all tables from DataSet to new file.
            foreach (DataTable dataTable in dataSet.Tables)
            {
                // Add new worksheet to the file.
                ExcelWorksheet worksheet = workbook2.Worksheets.Add(dataTable.TableName);
                worksheet.Cells[0, 0].Value = "Таблица: " + dataTable.TableName;
                CellRange mrgdRange = worksheet.Cells.GetSubrangeAbsolute(0, 0, 0, dataTable.Columns.Count - 1);
                mrgdRange.Merged = true;
                CellStyle cs = new CellStyle();
                cs.HorizontalAlignment = HorizontalAlignmentStyle.Center;
                cs.VerticalAlignment   = VerticalAlignmentStyle.Center;
                cs.Font.Weight         = ExcelFont.BoldWeight;
                cs.Font.Size           = 16 * 18;
                mrgdRange.Style        = cs;
                // Insert the data from DataTable to the worksheet starting at cell "A1".
                // worksheet.InsertDataTable(dataTable,
                //   new InsertDataTableOptions("A2") { ColumnHeaders = true });
                //Добавляем все остальные ячейки

                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    worksheet.Cells[1, i].Value                     = dataTable.Columns[i].ColumnName;
                    worksheet.Cells[1, i].Style.Font.Size           = 16 * 16;
                    worksheet.Cells[1, i].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
                    worksheet.Cells[1, i].Style.VerticalAlignment   = VerticalAlignmentStyle.Center;
                }
                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    worksheet.Columns[i].Width = 30 * 200;
                    for (int j = 0; j < dataTable.Columns.Count; j++)
                    {
                        worksheet.Cells[i + 2, j].Value = dataTable.Rows[i][j];
                        //_excelHeader++;
                    }
                }
            }

            // Save the file to XLS format.
            workbook2.Save(@"C:\Users\WorkUser\Desktop\DataSet.xls");
        }
コード例 #2
0
        public void ShowData()
        {
            textBox1.Visible = false;
            button2.Visible  = false;
            button3.Visible  = false;
            label3.Text      = "";

            table = treeView1.SelectedNode.ToString();
            string[] parts = table.Split(' ');
            table = parts[1];


            label4.Text = table;
            label5.Text = controll.GetSizeTable(table).ToString();

            string sql = "";

            if (table == "Test")
            {
                button2.Visible  = true;
                button3.Visible  = true;
                textBox1.Visible = true;
                label3.Text      = ((pageNumber / pageSize) + 1).ToString();

                Test tst = new Test();
                sql = tst.SelectShow;
            }
            if (table == "тип")
            {
                Type tp = new Type();
                sql = tp.SelectShow;
            }
            if (table == "поставщик")
            {
                Provider pr = new Provider();
                sql = pr.SelectShow;
            }
            if (Equals(table, "страна"))
            {
                Country c = new Country();
                sql = c.SelectShow;
            }
            if (table == "клиент")
            {
                Client cl = new Client();
                sql = cl.SelectShow;
            }
            if (table == "должность")
            {
                Post ps = new Post();
                sql = ps.SelectShow;
            }
            if (table == "производитель")
            {
                Creator cr = new Creator();
                sql = cr.SelectShow;
            }
            if (table == "товар")
            {
                Product p = new Product();
                sql = p.SelectShow;
            }
            if (table == "заказ")
            {
                Order or = new Order();
                sql = or.SelectShow;
            }
            if (table == "сотрудник")
            {
                Employee em = new Employee();
                sql = em.SelectShow;
            }

            if (table == "отправка")
            {
                Sending send = new Sending();
                sql = send.SelectShow;
            }

            ds = controll.ShowData(sql);
            dataGridView1.DataSource = ds.Tables[0];
        }