public tbl_BangTienDoKeo_H CreateHeader(tbl_BangTienDoKeo_H header) { tbl_BangTienDoKeo_H tienDoKeo_H = new tbl_BangTienDoKeo_H(); SqlParameter[] sqlParameters = new SqlParameter[4]; sqlParameters[0] = new SqlParameter("@NgayCapNhat", SqlDbType.DateTime); sqlParameters[0].Value = header.NgayCapNhat; sqlParameters[1] = new SqlParameter("@Tuan", SqlDbType.Int); sqlParameters[1].Value = header.Tuan; sqlParameters[2] = new SqlParameter("@Nam", SqlDbType.Int); sqlParameters[2].Value = header.Nam; sqlParameters[3] = new SqlParameter("@DonViID", SqlDbType.Int); sqlParameters[3].Value = header.DonViID; DataTable data = _Provider.ExecuteQuery("sp_Insert_BangTienDoKeo_H", sqlParameters); if (data.Rows.Count > 0) { tienDoKeo_H.ID = (int)data.Rows[0]["ID"]; tienDoKeo_H.NgayCapNhat = (DateTime)data.Rows[0]["NgayCapNhat"]; tienDoKeo_H.Tuan = (int)data.Rows[0]["Tuan"]; tienDoKeo_H.Nam = (int)data.Rows[0]["Nam"]; tienDoKeo_H.DonViID = (int)data.Rows[0]["DonViID"]; } return(tienDoKeo_H); }
private void btnImport_Click(object sender, EventArgs e) { DataTable data = GetDataTable(gvTienDoKeo); if (data.Rows.Count <= 0) { XtraMessageBox.Show("Vui lòng view file trước khi import.", "Có lỗi trong quá trình upload excel", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Tạo bảng header //Đối với user admin được quyền chọn thời gian, đơn vị để up tiến độ kéo tbl_BangTienDoKeo_H header = new tbl_BangTienDoKeo_H(); if (glueKhau.EditValue != null && (clsBienHeThong._MaNV == "admin" || Otif_DungChung._DonViID == 34)) { header = _clsTDK.CreateHeader(new tbl_BangTienDoKeo_H() { Tuan = Otif_DungChung.GetWeek((DateTime)dtpTuanNam.EditValue), Nam = ((DateTime)dtpTuanNam.EditValue).Year, DonViID = clsXuLyChung.GetSafeInt(glueKhau.EditValue), NgayCapNhat = DateTime.Now }); } else { header = _clsTDK.CreateHeader(new tbl_BangTienDoKeo_H() { Tuan = Otif_DungChung.GetWeek(DateTime.Now), Nam = DateTime.Now.Year, DonViID = Otif_DungChung._DonViID, NgayCapNhat = DateTime.Now }); } //Xử lý data thành List<tbl_BangTienDoKeo_L> List <tbl_BangTienDoKeo_L> tienDoKeos = new List <tbl_BangTienDoKeo_L>(); foreach (DataRow row in data.Rows) { tbl_BangTienDoKeo_L tienDoKeo_L = new tbl_BangTienDoKeo_L(); tienDoKeo_L.ID_Header = header.ID; tienDoKeo_L.NGH = (DateTime)row[0]; tienDoKeo_L.KHACHHANG = row[1].ToString(); tienDoKeo_L.SOLSX = row[2].ToString(); tienDoKeo_L.MASP = row[3].ToString(); tienDoKeo_L.MAMAU = row[4].ToString(); tienDoKeo_L.COSO = Convert.ToInt32(row[5]); tienDoKeo_L.SLKH = Convert.ToInt32(row[6]); tienDoKeo_L.NSU = Convert.ToInt32(row[7]); tienDoKeo_L.DMHC = Convert.ToDouble(row[8]); tienDoKeo_L.NANGSUAT = Convert.ToDouble(row[9]); tienDoKeo_L.CONGCAN = Convert.ToDouble(row[10]); tienDoKeo_L.LINE = Convert.ToInt32(row[11]); tienDoKeo_L.NGAYBATDAU = (DateTime)row[12]; tienDoKeo_L.NGAYKETTHUC = (DateTime)row[13]; tienDoKeos.Add(tienDoKeo_L); } //MessageBox.Show(tienDoKeos.Count.ToString()); if (_clsTDK.CreateLine(tienDoKeos)) { XtraMessageBox.Show("Import excel thành công.", "", MessageBoxButtons.OK, MessageBoxIcon.None); } else { XtraMessageBox.Show("Import không thành công.", "Có lỗi trong quá trình upload excel", MessageBoxButtons.OK, MessageBoxIcon.Error); } }