protected void ddlFileType_SelectedIndexChanged(object sender, EventArgs e) { try { txtFilePath.Text = Convert.ToString(ddlFileType.SelectedValue); BLImport im = new BLImport(Convert.ToString(Session["ConStr"])); string sFilePath = ""; string sFullPath = ""; sFullPath = txtFilePath.Text + ddlFileType.SelectedItem.Text + ".txt"; txtFileCreationDate.Text = im.FileCreationTime(sFullPath).ToString("dd-MMM-yyyy h:mm:ss tt"); try { if (DateTime.Parse(txtFileCreationDate.Text) < DateTime.Parse("01-Jan-1900")) { throw new Exception("Invalid file"); } } catch (Exception ex) { lblMessage.Text = "File not found"; return; } this.ResetStatus(); if (im.IsFileExist((enmFileID)ddlFileType.SelectedIndex, Convert.ToDateTime(txtFileCreationDate.Text))) { throw new Exception(ddlFileType.SelectedItem.Text + " already imported. Please check. . "); } } catch (Exception ex) { lblMessage.Text = ex.Message; } }
protected void grdFileProcessHistory_RowCommand(object sender, GridViewCommandEventArgs e) { try { int iFileID; DateTime dForDate; if (grdFileProcessHistory.Rows[Convert.ToInt32(e.CommandArgument)].Cells[7].Text == " ") { throw new Exception("Invalid Delete Operation. Please Check. . ."); } iFileID = Convert.ToInt32(grdFileProcessHistory.Rows[Convert.ToInt32(e.CommandArgument)].Cells[7].Text); dForDate = Convert.ToDateTime(grdFileProcessHistory.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].Text); BLImport im = new BLImport(Convert.ToString(Session["ConStr"])); im.DeleteProcessHistory((enmFileID)iFileID, dForDate); this.PrepareImportHistory(); } catch (Exception ex) { lblMessage.ForeColor = System.Drawing.Color.Red; lblMessage.Text = ex.Message; } }
private bool IsValidate(enmFileID vFileID) { BLImport im = new BLImport(Convert.ToString(Session["ConStr"])); //im.CheckConsistency((enmFileID)ddlFileType.SelectedIndex); if (im.IsFileExist((enmFileID)ddlFileType.SelectedIndex, Convert.ToDateTime(txtFileCreationDate.Text))) { throw new Exception(ddlFileType.SelectedItem.Text + " already imported. Please check. . "); } if (im.IsImportExist(vFileID, Convert.ToDateTime(this.txtImportDate.Text))) { throw new Exception(ddlFileType.SelectedItem.Text + " already imported. Please check. . "); } if (vFileID != enmFileID.SOBB04 && vFileID != enmFileID.InfoCD) { if (im.IsProcessExist(vFileID)) { throw new Exception(ddlFileType.SelectedItem.Text + " already imported and Not yet processed. Please check. . "); } } //if (!im.DoArchived(vFileID)) //{ // throw new Exception("Imported data still not archived. Please Check."); //} return(true); }
private void PrepareImportHistory() { try { BLImport im = new BLImport(Convert.ToString(Session["ConStr"])); grdFileProcessHistory.DataSource = im.GetFileProcessingHistory(); grdFileProcessHistory.DataBind(); } catch (Exception ex) { lblMessage.Text = ex.Message; } }
protected void gvImport_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteImp") { int importId; if (Int32.TryParse(e.CommandArgument.ToString(), out importId)) { BLImport.CleanTablesForSpecificImportID(importId, false); //refresh the data grid gvImport.DataBind(); } } }
protected void cmdImport_Click(object sender, EventArgs e) { string userName = ""; string uploadDirectory = ""; bool hasErr = false; bool forceCompanySubsid = chkForceCompSubsid.Checked; bool updateGroupes = chkGroupes.Checked; bool updateExperience = chkExp.Checked; bool updateCad = chkCad.Checked; try { #region INITIAL CONFIGURATION //initial configuration userName = User.Identity.Name; uploadDirectory = Path.Combine(Request.PhysicalApplicationPath, C.uploadFolder); string prefix = userName + "_"; string uploadPathPrest = Path.Combine(uploadDirectory, prefix + txtPrestPath.Text); string uploadPathCot = Path.Combine(uploadDirectory, prefix + txtCotPath.Text); string uploadPathDemo = Path.Combine(uploadDirectory, prefix + txtDemoPath.Text); string uploadPathCotPrev = Path.Combine(uploadDirectory, prefix + txtCotPrevPath.Text); string uploadPathSinistrPrev = Path.Combine(uploadDirectory, prefix + txtSinistrePrevPath.Text); string uploadPathDecompPrev = Path.Combine(uploadDirectory, prefix + txtDecompPrevPath.Text); string uploadPathExp = Path.Combine(uploadDirectory, prefix + txtExpPath.Text); string newPrestCSV = Path.Combine(uploadDirectory, prefix + C.eMOGImportFile.PrestationsMOG.ToString() + ".csv"); string newCotCSV = Path.Combine(uploadDirectory, prefix + C.eMOGImportFile.CotisationsMOG.ToString() + ".csv"); string newDemoCSV = Path.Combine(uploadDirectory, prefix + C.eMOGImportFile.DemographyMOG.ToString() + ".csv"); string newOtherFieldsCSV = Path.Combine(uploadDirectory, prefix + C.eMOGImportFile.OtherFieldsMOG.ToString() + ".csv"); string newCotPrevCSV = Path.Combine(uploadDirectory, prefix + C.eMOGImportFile.CotPrevMOG.ToString() + ".csv"); string newSinistrePrevCSV = Path.Combine(uploadDirectory, prefix + C.eMOGImportFile.SinistrePrevMOG.ToString() + ".csv"); string newDecompPrevCSV = Path.Combine(uploadDirectory, prefix + C.eMOGImportFile.DecompPrevMOG.ToString() + ".csv"); string newExpCSV = Path.Combine(uploadDirectory, prefix + C.eMOGImportFile.ExpMOG.ToString() + ".csv"); string tableForOtherFields = WebConfigurationManager.AppSettings["TableForOtherFields"]; string configStringPrest = WebConfigurationManager.AppSettings[C.eConfigStrings.PrestSante.ToString()]; string configStringCot = WebConfigurationManager.AppSettings[C.eConfigStrings.CotisatSante.ToString()]; string configStringDemo = WebConfigurationManager.AppSettings[C.eConfigStrings.Demography.ToString()]; string configStringOtherFields = WebConfigurationManager.AppSettings[C.eConfigStrings.OtherFields.ToString()]; string configStringCotPrev = WebConfigurationManager.AppSettings[C.eConfigStrings.CotisatPrev.ToString()]; string configStringSinistrPrev = WebConfigurationManager.AppSettings[C.eConfigStrings.SinistrePrev.ToString()]; string configStringDecompPrev = WebConfigurationManager.AppSettings[C.eConfigStrings.DecomptePrev.ToString()]; string configStringExp = WebConfigurationManager.AppSettings[C.eConfigStrings.Experience.ToString()]; uploadPrestFile = (HttpPostedFile)Session[C.eUploadSessionVar.UploadPrestFile.ToString()]; uploadCotFile = (HttpPostedFile)Session[C.eUploadSessionVar.UploadCotFile.ToString()]; uploadDemoFile = (HttpPostedFile)Session[C.eUploadSessionVar.UploadDemoFile.ToString()]; uploadCotPrevFile = (HttpPostedFile)Session[C.eUploadSessionVar.UploadCotPrevFile.ToString()]; uploadDecompPrevFile = (HttpPostedFile)Session[C.eUploadSessionVar.UploadDecompPrevFile.ToString()]; uploadSinistrePrevFile = (HttpPostedFile)Session[C.eUploadSessionVar.UploadSinistrePrevFile.ToString()]; uploadExpFile = (HttpPostedFile)Session[C.eUploadSessionVar.UploadExpFile.ToString()]; string csvSep = WebConfigurationManager.AppSettings["CSVSEP"]; #endregion //most basic validation if (txtNomImport.Text == "") { throw new Exception("Il faudra renseigner un nom pour l’import dans le champ 'Nom Import' !"); } //we need to provide at least 1 import file if (txtPrestPath.Text == "" && txtDemoPath.Text == "" && txtCotPath.Text == "" && txtExpPath.Text == "" && txtSinistrePrevPath.Text == "" && txtDecompPrevPath.Text == "" && txtCotPrevPath.Text == "") { throw new Exception("Il faudra spécifier au moins un fichier d'import !"); } //### the following is no longer required //make sure a file is provided for the other fields table //### add PREV fields //if (tableForOtherFields == C.eImportFile.PrestaSante.ToString()) // if (txtPrestPath.Text == "") // throw new Exception("Il faudra spécifier un fichier du type .csv ou .xlsx dans le champ 'Fichier CSV Prestations' !"); //if (tableForOtherFields == C.eImportFile.CotisatSante.ToString()) // if (txtCotPath.Text == "") // throw new Exception("Il faudra spécifier un fichier du type .csv ou .xlsx dans le champ 'Fichier CSV Cotisations' !"); //if (tableForOtherFields == C.eImportFile.Demography.ToString()) // if (txtDemoPath.Text == "") // throw new Exception("Il faudra spécifier un fichier du type .csv ou .xlsx dans le champ 'Fichier CSV Démographie' !"); #region SAVE IMPORTED FILES TO SPECIFIC LOCATION //upload provided import files if (uploadPrestFile != null && uploadPrestFile.FileName.Length > 0 && txtPrestPath.Text != "") { uploadPrestFile.SaveAs(uploadPathPrest); } if (uploadCotFile != null && uploadCotFile.FileName.Length > 0 && txtCotPath.Text != "") { uploadCotFile.SaveAs(uploadPathCot); } if (uploadDemoFile != null && uploadDemoFile.FileName.Length > 0 && txtDemoPath.Text != "") { uploadDemoFile.SaveAs(uploadPathDemo); } if (uploadSinistrePrevFile != null && uploadSinistrePrevFile.FileName.Length > 0 && txtSinistrePrevPath.Text != "") { uploadSinistrePrevFile.SaveAs(uploadPathSinistrPrev); } if (uploadDecompPrevFile != null && uploadDecompPrevFile.FileName.Length > 0 && txtDecompPrevPath.Text != "") { uploadDecompPrevFile.SaveAs(uploadPathDecompPrev); } if (uploadCotPrevFile != null && uploadCotPrevFile.FileName.Length > 0 && txtCotPrevPath.Text != "") { uploadCotPrevFile.SaveAs(uploadPathCotPrev); } if (uploadExpFile != null && uploadExpFile.FileName.Length > 0 && txtExpPath.Text != "") { uploadExpFile.SaveAs(uploadPathExp); } #endregion #region VALIDATE IMPORT FILES - VERIFY IF ALL REQUIRED FIELDS ARE PRESENT //Validate imported files List <string> missingColumns; //verify PrestaSante Data if (File.Exists(uploadPathPrest)) { missingColumns = BLImport.ImportFileVerification(C.eImportFile.PrestaSante, ref uploadPathPrest, configStringPrest); if (missingColumns.Count > 0) { string errMess = string.Format("Le fichier d'import : {0} manque les colonnes suivantes : {1} ", txtPrestPath.Text, string.Join(", ", missingColumns)); throw new Exception(errMess); } } //verify CotisatSante Data if (File.Exists(uploadPathCot)) { missingColumns = BLImport.ImportFileVerification(C.eImportFile.CotisatSante, ref uploadPathCot, configStringCot); if (missingColumns.Count > 0) { string errMess = string.Format("Le fichier d'import : {0} manque les colonnes suivantes : {1} ", txtCotPath.Text, string.Join(", ", missingColumns)); throw new Exception(errMess); } } //verify Demo Data if (File.Exists(uploadPathDemo)) { missingColumns = BLImport.ImportFileVerification(C.eImportFile.Demography, ref uploadPathDemo, configStringDemo); if (missingColumns.Count > 0) { string errMess = string.Format("Le fichier d'import : {0} manque les colonnes suivantes : {1} ", txtDemoPath.Text, string.Join(", ", missingColumns)); throw new Exception(errMess); } } //verify CotisatPrev Data if (File.Exists(uploadPathCotPrev)) { missingColumns = BLImport.ImportFileVerification(C.eImportFile.CotisatPrev, ref uploadPathCotPrev, configStringCotPrev); if (missingColumns.Count > 0) { string errMess = string.Format("Le fichier d'import : {0} manque les colonnes suivantes : {1} ", txtCotPrevPath.Text, string.Join(", ", missingColumns)); throw new Exception(errMess); } } //verify SinistrePrev Data if (File.Exists(uploadPathSinistrPrev)) { missingColumns = BLImport.ImportFileVerification(C.eImportFile.SinistrePrev, ref uploadPathSinistrPrev, configStringSinistrPrev); if (missingColumns.Count > 0) { string errMess = string.Format("Le fichier d'import : {0} manque les colonnes suivantes : {1} ", txtSinistrePrevPath.Text, string.Join(", ", missingColumns)); throw new Exception(errMess); } } //verify DecomptePrev Data if (File.Exists(uploadPathDecompPrev)) { missingColumns = BLImport.ImportFileVerification(C.eImportFile.DecompPrev, ref uploadPathDecompPrev, configStringDecompPrev); if (missingColumns.Count > 0) { string errMess = string.Format("Le fichier d'import : {0} manque les colonnes suivantes : {1} ", txtDecompPrevPath.Text, string.Join(", ", missingColumns)); throw new Exception(errMess); } } //verify Experience Data if (File.Exists(uploadPathExp)) { missingColumns = BLImport.ImportFileVerification(C.eImportFile.Exp, ref uploadPathExp, configStringExp); if (missingColumns.Count > 0) { string errMess = string.Format("Le fichier d'import : {0} manque les colonnes suivantes : {1} ", txtExpPath.Text, string.Join(", ", missingColumns)); throw new Exception(errMess); } } #endregion //### Other Validations ? configStrings not empty, files & directories exist //Perform data import BLImport imp = new BLImport(userName, newPrestCSV, newCotCSV, newDemoCSV, newOtherFieldsCSV, newCotPrevCSV, newSinistrePrevCSV, newDecompPrevCSV, configStringPrest, configStringDemo, configStringCot, configStringOtherFields, configStringCotPrev, configStringSinistrPrev, configStringDecompPrev, tableForOtherFields, importName, csvSep, uploadDirectory, uploadPathPrest, uploadPathCot, uploadPathDemo, uploadPathCotPrev, uploadPathSinistrPrev, uploadPathDecompPrev, newExpCSV, configStringExp, uploadPathExp, forceCompanySubsid, updateGroupes, updateExperience, updateCad); imp.DoImport(); //refresh the data grid gvImport.DataBind(); } //catch (Exception ex) //{ // hasErr = true; // BLImport.CleanupImportFiles(uploadDirectory, userName); // var myCustomValidator = new CustomValidator(); // myCustomValidator.IsValid = false; // myCustomValidator.ErrorMessage = ex.Message; // Page.Validators.Add(myCustomValidator); //} catch (Exception ex) { UICommon.HandlePageError(ex, this.Page, "cmdImport_Click"); } finally { if (!hasErr) { //clean all text fields txtCotPath.Text = ""; txtCotPrevPath.Text = ""; txtDecompPrevPath.Text = ""; txtDemoPath.Text = ""; txtNomImport.Text = ""; txtPrestPath.Text = ""; txtSinistrePrevPath.Text = ""; txtExpPath.Text = ""; uploadPrestFile = null; uploadCotFile = null; uploadDemoFile = null; uploadCotPrevFile = null; uploadDecompPrevFile = null; uploadSinistrePrevFile = null; uploadExpFile = null; } } }
private int SaveHistory(enmFileID vFileID) { BLImport im = new BLImport(Convert.ToString(Session["ConStr"])); return(im.SaveHistory(vFileID, Convert.ToDateTime(this.txtImportDate.Text), Convert.ToDateTime(txtFileCreationDate.Text), Convert.ToString(Session["gUserName"]))); }
protected void btnStart_Click(object sender, EventArgs e) { try { this.IsValidate((enmFileID)ddlFileType.SelectedIndex); this.ResetStatus(); BLImport im = new BLImport(Convert.ToString(Session["ConStr"])); if (this.ddlFileType.SelectedItem.Text == "BDDB1") { //if (im.DoArchived(enmFileID.BDDB1) == false) //{ // throw new Exception("Import data archive operation fail. Please check. . ."); //} this.ProcessBDDB1(); } else if (this.ddlFileType.SelectedItem.Text == "BDDB2") { //if (im.DoArchived(enmFileID.BDDB2) == false) //{ // throw new Exception("Import data archive operation fail. Please check. . ."); //} this.ProcessBDDB2(); } //else if (this.ddlFileType.SelectedItem.Text == "TXN") //{ // if (im.DoArchived(enmFileID.TXN) == false) // { // throw new Exception("Import data archive operation fail. Please check. . ."); // } // this.ProcessTXN(); //} //else if (this.ddlFileType.SelectedItem.Text == "SOBB4") //{ // if (im.DoArchived(enmFileID.SOBB04) == false) // { // throw new Exception("Import data archive operation fail. Please check. . ."); // } // this.ProcessSOBB4(); //} //else if (this.ddlFileType.SelectedItem.Text == "InfoCD") //{ // if (im.DoArchived(enmFileID.InfoCD) == false) // { // throw new Exception("Import data archive operation fail. Please check. . ."); // } // this.ProcessInfoCD(); //} //else if (this.ddlFileType.SelectedItem.Text == "XLSheet") //{ // if (im.DoArchived(enmFileID.XLSheet) == false) // { // throw new Exception("Import data archive operation fail. Please check. . ."); // } // this.ProcessXLSheet(); //} else { throw new Exception("Invalid file selection. Please check"); } this.txtProcess.Text = Convert.ToString(iProcessed); this.txtImported.Text = Convert.ToString(iImported); this.txtUncompleted.Text = Convert.ToString(iUncompleted); this.PreparedErrorGrid(); this.SaveHistory((enmFileID)ddlFileType.SelectedIndex); if (_dtError.Rows.Count > 0) { string sFileName, sFilePath; sFileName = ddlFileType.SelectedItem.Text + "-" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xml"; if (this.txtFilePath.Text.Substring(this.txtFilePath.Text.Length - 4, 4) == ".xls") { sFilePath = this.txtFilePath.Text.Substring(0, this.txtFilePath.Text.LastIndexOf("\\")) + "\\"; } else { sFilePath = this.txtFilePath.Text + "\\"; } _dtError.TableName = "Error"; _dtError.WriteXml(sFilePath + sFileName); } this.PrepareImportHistory(); } catch (Exception ex) { this.lblMessage.Text = ex.Message; } }