private void kiem_tra_du_lieu(DS_EXCEL_IMPORT_HOC_VIEN ip_ds) { m_flag_du_lieu_is_ok = true; CellStyle v_style_not_ok = m_fg.Styles.Add("LoiDuLieu"); v_style_not_ok.BackColor = Color.Pink; CellStyle v_style_ok_ma_hv = m_fg.Styles.Add("Ma_HV"); v_style_ok_ma_hv.BackColor = Color.DeepSkyBlue; CellStyle v_style_ok = m_fg.Styles.Add("OK"); v_style_ok.BackColor = Color.White; //Buoc 1: Check null for(int i = m_fg.Rows.Fixed; i < m_fg.Rows.Count; i++) { for(int j = m_fg.Cols.Fixed; j < m_fg.Cols.Count; j++) { if(m_fg.Rows[i][j] == null || m_fg.Rows[i][j].ToString() == "") { m_fg.SetCellStyle(i, j, v_style_not_ok); m_flag_du_lieu_is_ok = false; } else { m_fg.SetCellStyle(i, (int)e_col_Number.MA_HOC_VIEN, v_style_ok); } } } //Buoc 2: Check Ma hoc vien da ton tai chua DS_DM_HOC_SINH v_ds_hs = new DS_DM_HOC_SINH(); v_ds_hs.Clear(); v_ds_hs.EnforceConstraints = false; US_DM_HOC_SINH v_us_hs = new US_DM_HOC_SINH(); v_us_hs.FillDataset(v_ds_hs); DataView v_dv_db = v_ds_hs.DM_HOC_SINH.DefaultView; v_dv_db.Sort = "MA_DOI_TUONG"; for(int i = m_fg.Rows.Fixed; i < m_fg.Rows.Count; i++) { int v_row = v_dv_db.Find(m_fg.Rows[i][(int)e_col_Number.MA_HOC_VIEN].ToString()); if(v_row > 0) { m_flag_du_lieu_is_ok = false; m_fg.SetCellStyle(i, (int)e_col_Number.MA_HOC_VIEN, v_style_ok_ma_hv); } else { m_fg.SetCellStyle(i, (int)e_col_Number.MA_HOC_VIEN, v_style_ok); } } }
void m_cmd_save_data_Click(object sender, EventArgs e) { try { if(m_flag_du_lieu_is_ok == false) { BaseMessages.MsgBox_Error("Bạn kiểm tra dữ liệu trước nhé!"); return; } m_us.BeginTransaction(); US_DM_HOC_SINH v_us_hv = new US_DM_HOC_SINH(); for(int i_grid_row = 1; i_grid_row < m_fg.Rows.Count; i_grid_row++) { grid2us_object(m_us, i_grid_row); excel_2_us_dm_hoc_vien(m_us, v_us_hv); v_us_hv.Insert(); v_us_hv.ClearAllFields(); } m_us.CommitTransaction(); BaseMessages.MsgBox_Infor("Lưu dữ liệu học viên thành công"); } catch(Exception v_e) { if(m_us.is_having_transaction()) { m_us.Rollback(); } CSystemLog_301.ExceptionHandle(v_e); } }
private void excel_2_us_dm_hoc_vien(US_EXCEL_IMPORT_HOC_VIEN ip_us_excel, US_DM_HOC_SINH ip_us_hv) { ip_us_hv.dcID_LOAI_DOI_TUONG = CONST_ID_LOAI_DOI_TUONG.ID_HOC_SINH; ip_us_hv.strMA_DOI_TUONG = ip_us_excel.strMA_HOC_VIEN; ip_us_hv.strHO = ip_us_excel.strHO_DEM; ip_us_hv.strTEN = ip_us_excel.strTEN; ip_us_hv.strTRUONG_DANG_HOC = ip_us_excel.strTRUONG_DANG_HOC; ip_us_hv.strEMAIL_HS = ip_us_excel.strEMAIL; ip_us_hv.strDIA_CHI = ip_us_excel.strDIA_CHI; ip_us_hv.strSDT_HS = ip_us_excel.strSĐT; }