public ActionResult CleanseMatchDataMatch() { DataTable dt = new DataTable(); if (TempData["Data"] != null) { dt = (TempData["Data"] as DataTable).Copy(); } bool IsTag = false; //Get Import File Column Name to fill in dropdown List <SelectListItem> lstAllFilter = new List <SelectListItem>(); if (dt.Rows.Count > 0) { lstAllFilter.Add(new SelectListItem { Value = "0", Text = "-Select-" }); int i = 0; foreach (DataColumn c in dt.Columns) { lstAllFilter.Add(new SelectListItem { Value = (i + 1).ToString(), Text = Convert.ToString(c.ColumnName) }); i++; if (c.ColumnName.ToLower() == "tags" || c.ColumnName.ToLower() == "tag") { IsTag = true; } } } // Get InpCompany Data Column Names SettingFacade sfac = new SettingFacade(this.CurrentClient.ApplicationDBConnectionString); DataTable dtSecondaryAutoAcceptanceCriteria = new DataTable(); //Get Secondary Auto-Acceptance Criteria Columns Name dtSecondaryAutoAcceptanceCriteria = sfac.GetSecondaryAutoAcceptanceCriteriaColumnsName(); List <string> columnName = new List <string>(); if (dtSecondaryAutoAcceptanceCriteria.Rows.Count > 0) { for (int k = 0; k < dtSecondaryAutoAcceptanceCriteria.Rows.Count; k++) //loop through the columns. { if (Convert.ToString(dtSecondaryAutoAcceptanceCriteria.Rows[k][0]) != "ImportRowId" && Convert.ToString(dtSecondaryAutoAcceptanceCriteria.Rows[k][0]) != "ImportProcessId" && Convert.ToString(dtSecondaryAutoAcceptanceCriteria.Rows[k][0]) != "CountryGroupId") { columnName.Add(Convert.ToString(dtSecondaryAutoAcceptanceCriteria.Rows[k][0])); } } } ViewBag.ColumnList = columnName; ViewBag.ExternalColumn = lstAllFilter; ViewBag.IsContainsTags = IsTag; TempData["IsTag"] = IsTag; IPagedList <dynamic> pagedProducts = new StaticPagedList <dynamic>(dt.AsDynamicEnumerable(), 1, 100000, 0); TempData.Keep(); return(View(pagedProducts)); }
public JsonResult CleanseMatchDataMatch(string OrgColumnName, string ExcelColumnName, string Tags = null, bool IsOverWrite = false, int?CommentId = null) { bool IsTag = false; if (TempData["IsTag"] != null) { IsTag = Convert.ToBoolean(TempData["IsTag"]); } string[] OrgColumnNameArray = OrgColumnName.Split(','); string[] ExcelColumnNameArray = ExcelColumnName.Split(','); string Message = string.Empty; SettingFacade sfac = new SettingFacade(this.CurrentClient.ApplicationDBConnectionString); DataTable dt = new DataTable(); DataTable dtOrgColumns = new DataTable(); DataTable dtColumns = new DataTable(); if (TempData["Data"] != null) { dt = (TempData["Data"] as DataTable).Copy(); } //Get Secondary Auto-Acceptance Criteria Columns Name dtOrgColumns = sfac.GetSecondaryAutoAcceptanceCriteriaColumnsName(); if (!IsTag) { DataColumn Col = dt.Columns.Add("Tags", typeof(System.String)); foreach (DataRow d in dt.Rows) { if (!string.IsNullOrEmpty(Tags)) { d["Tags"] = Convert.ToString(Tags); } } } if (!Helper.LicenseEnableTags) { // if the tag is disable and file contain tags field in table. We just remove tags field from data table var list = new List <string>(OrgColumnNameArray); string tag = list.Where(x => x.ToUpperInvariant() == "Tags".ToUpperInvariant()).Select(x => x.ToUpperInvariant()).FirstOrDefault(); if (!string.IsNullOrEmpty(tag)) { list.Remove("Tags"); OrgColumnNameArray = list.ToArray(); } } dtColumns.Columns.Add("Tablecolumn"); dtColumns.Columns.Add("Excelcolumn"); DataRow dr = dtColumns.NewRow(); // Merge Original and Excel column in single table and Manage Dynamic Column matching for (int i = 0; i < OrgColumnNameArray.Length; i++) { if (Convert.ToString(OrgColumnNameArray[i]) != "-Select-") { if (i == OrgColumnNameArray.Length - 1) { dr = dtColumns.NewRow(); dr["Tablecolumn"] = "CountryGroupId"; dr["Excelcolumn"] = "CountryGroupId"; dtColumns.Rows.Add(dr); } dr = dtColumns.NewRow(); dr["Tablecolumn"] = Convert.ToString(ExcelColumnNameArray[i]); dr["Excelcolumn"] = Convert.ToString(OrgColumnNameArray[i]); dtColumns.Rows.Add(dr); } } TempData.Keep(); try { //remove the blank rows in data table string strRowFilter = string.Empty; for (int m = 0; m < dtOrgColumns.Rows.Count; m++) { if (Convert.ToString(dtOrgColumns.Rows[m][1]).ToLower() == "no") { for (int tt = 0; tt < dtColumns.Rows.Count; tt++) { if (Convert.ToString(dtColumns.Rows[tt][0]) == Convert.ToString(dtOrgColumns.Rows[m][0])) { if (Convert.ToString(dtOrgColumns.Rows[m][0]) != "CountryGroupId") { strRowFilter += "([" + Convert.ToString(dtColumns.Rows[tt][1]) + "] <> '' OR [" + Convert.ToString(dtColumns.Rows[tt][1]) + "] <> 'NULL') AND"; } } } } } strRowFilter = strRowFilter.Remove(strRowFilter.Length - 3, 3); DataTable dtTempDataNew = new DataTable(); DataColumn Col = dt.Columns.Add("CountryGroupId", typeof(System.Int32)); foreach (DataRow d in dt.Rows) { d["CountryGroupId"] = 0; } dtTempDataNew = dt.Select(strRowFilter).CopyToDataTable(); dt = dtTempDataNew; //bulk insert new records bool IsDataInsert = BulkInsert(dt, dtColumns, IsOverWrite, CommentId); Message = Convert.ToString(TempData["BulkMessage"]); } catch (Exception ex) { Message = MessageCollection.CommanEnableFileImport; } TempData.Keep(); return(new JsonResult { Data = Message }); }