Esempio n. 1
0
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            MyDB       mydb    = new MyDB();
            SqlCommand command = new SqlCommand("SELECT * FROM NguoiLaoDong WHERE CONCAT(HoTen,ChucVu,DonViTrucThuoc) LIKE N'%" + textBoxSearch.Text + "%'", mydb.getConnection);

            mydb.openConnection();
            DataTable table = new DataTable();

            table.Load(command.ExecuteReader());
            if (table.Rows.Count > 0)
            {
                try
                {
                    BindingSource bsource = new BindingSource();   //dong nay xuat hien khi dua datasource vao
                    bsource.DataSource       = table;
                    DataGridView1.DataSource = bsource;
                    DataGridViewImageColumn piccol = new DataGridViewImageColumn();
                    piccol             = (DataGridViewImageColumn)DataGridView1.Columns[10];
                    piccol.ImageLayout = DataGridViewImageCellLayout.Stretch;
                    ExcelNguoiLaoDong ex = new ExcelNguoiLaoDong();
                    ex.ExportExcel(table, "Người Lao Động", "Danh sách Người Lao Động cần tìm");

                    labelNguoiLaoDong.Text = ("Tổng Người Lao Động trong danh sách: " + DataGridView1.RowCount);
                    mydb.closeConnection();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Not Found");
            }
        }
Esempio n. 2
0
        private void buttonInFile_Click_1(object sender, EventArgs e)
        {
            MyDB       mydb    = new MyDB();
            SqlCommand command = new SqlCommand("SELECT * FROM NguoiLaoDong", mydb.getConnection);

            mydb.openConnection();
            DataTable table = new DataTable();

            table.Load(command.ExecuteReader());
            if (table.Rows.Count > 0)
            {
                try
                {
                    BindingSource bsource = new BindingSource();   //dong nay xuat hien khi dua datasource vao
                    bsource.DataSource       = table;
                    DataGridView1.DataSource = bsource;
                    DataGridViewImageColumn piccol = new DataGridViewImageColumn();
                    piccol             = (DataGridViewImageColumn)DataGridView1.Columns[10];
                    piccol.ImageLayout = DataGridViewImageCellLayout.Stretch;
                    ExcelNguoiLaoDong ex = new ExcelNguoiLaoDong();
                    ex.ExportExcel(table, "Người Lao Động", "Danh sách Người Lao Động");

                    mydb.closeConnection();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Not Found");
            }
        }