Example #1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            int nambaocao = 0;

            if (int.TryParse(txtNam.Text, out nambaocao) && nambaocao != nam)
            {
                MessageBox.Show("Vui lòng chọn Lập báo cáo trước khi lưu báo cáo");
                return;
            }
            if (dgvChiTietBaoCao.Rows.Count > 0)
            {
                DataTable baoCaoTable = new DataTable();
                //MessageBox.Show(DateTime.Now.Date.ToString());;
                if (dgvChiTietBaoCao.Columns.Count > 0)
                {
                    foreach (DataGridViewColumn col in dgvChiTietBaoCao.Columns)
                    {
                        baoCaoTable.Columns.Add(col.Name);
                    }
                }
                object[] cellValues = new object[dgvChiTietBaoCao.Columns.Count];
                foreach (DataGridViewRow row in dgvChiTietBaoCao.Rows)
                {
                    for (int i = 0; i < row.Cells.Count; i++)
                    {
                        cellValues[i] = row.Cells[i].Value;
                    }
                    baoCaoTable.Rows.Add(cellValues);
                }
                baocaoController.InsertBaoCaoTon(cbbThang.SelectedIndex + 1, nam, baoCaoTable);
            }
        }