public void ddlLanguage_SelectedIndexChanged(object sender, EventArgs e) { MappingFill(); MetaDataPlus.Import.Rule _mapping = this.ClassRule; BindDataType(); if (_mapping != null) { RestoreValues(_mapping); } }
public void SaveMapping_Click(object sender, EventArgs e) { if (this.tbMappingFileName.Text != "") { if (tbMappingFileName.Text.IndexOfAny(System.IO.Path.GetInvalidFileNameChars()) != -1) { DisplayErrorMessage("The mapping filename is invalid."); return; } string path = RulesPath; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string _FilePath = Path.Combine(path, tbMappingFileName.Text + ".xml"); MappingFill(); MetaDataPlus.Import.Rule mapping = this.ClassRule; this.LastPostFile = this.ddlDataFiles.SelectedValue; if (!mapping.Attribute.Contains("DataFile")) { mapping.Attribute.Add("DataFile", this.LastPostFile); } if (!mapping.Attribute.Contains("Encoding")) { mapping.Attribute.Add("Encoding", this.ddlEncoding.SelectedValue); } Mediachase.MetaDataPlus.Import.Rule.XmlSerialize(mapping, _FilePath); this.LastMapFile = _FilePath; Response.Redirect(Request.RawUrl); } }
public void btnLoadMapFile_Click(object sender, EventArgs e) { if (this.ddlMappingFiles.SelectedIndex > 0) { if (!File.Exists(this.ddlMappingFiles.SelectedValue)) { //DisplayErrorMessage(String.Format("The file \"{0}\" does not exist.", this.ddlExMappingFiles.SelectedValue)); return; } MetaDataPlus.Import.Rule mapping = MetaDataPlus.Import.Rule.XmlDeserialize(CatalogContext.MetaDataContext, ddlMappingFiles.SelectedValue); this.ClassRule = mapping; string sTypeName = mapping.Attribute["TypeName"]; if (sTypeName != null) { for (int i = 0; i < this.ddlTypeData.Items.Count; i++) { if (this.ddlTypeData.Items[i].Value == sTypeName) { this.ddlTypeData.SelectedIndex = i; break; } } } if (ddlTypeData.SelectedValue.Equals("Category")) { BindMetaclass("CatalogNode"); this.ddlMetaClass.Enabled = true; } else if (ddlTypeData.SelectedValue.Equals("Entry")) { BindMetaclass("CatalogEntry"); this.ddlMetaClass.Enabled = true; } else if (ddlTypeData.SelectedValue.Equals("EntryRelation") || ddlTypeData.SelectedValue.Equals("EntryAssociation") || ddlTypeData.SelectedValue.Equals("Variation") || ddlTypeData.SelectedValue.Equals("SalePrice")) { this.ddlMetaClass.SelectedIndex = 0; this.ddlMetaClass.Enabled = false; } for (int i = 0; i < this.ddlMetaClass.Items.Count; i++) { if (mapping.ClassName.Equals(this.ddlMetaClass.Items[i].Value, StringComparison.OrdinalIgnoreCase)) { this.ddlMetaClass.SelectedIndex = i; break; } } if (this.ddlMetaClass.SelectedIndex == 0) { MetaClass _metaClass = MetaClass.Load(CatalogContext.MetaDataContext, mapping.ClassName); if (_metaClass == null) { DisplayErrorMessage(String.Format("The metaclass '{0}' does not exists.", mapping.ClassName)); } } if (mapping.Attribute["Language"] != null) { string language = mapping.Attribute["Language"]; if (!String.IsNullOrEmpty(language)) { for (int i = 0; i < this.ddlLanguage.Items.Count; i++) { if (this.ddlLanguage.Items[i].Value.Equals(language, StringComparison.OrdinalIgnoreCase)) { this.ddlLanguage.SelectedIndex = i; break; } } } } this.ddlDataFiles.SelectedIndex = 0; string sDataFile = Path.Combine(SourcePath, Path.GetFileName(mapping.Attribute["DataFile"])); if (sDataFile != null) { for (int i = 0; i < this.ddlDataFiles.Items.Count; i++) { if (Path.Equals(this.ddlDataFiles.Items[i].Value, sDataFile)) { this.ddlDataFiles.SelectedIndex = i; break; } } if (this.ddlDataFiles.SelectedIndex == 0) { DisplayErrorMessage(String.Format("The file \"{0}\" does not exist in a folder \"{1}\".", Path.GetFileName(sDataFile), SourcePath)); return; } } else { DisplayErrorMessage("The wrong version of a mapping file. Required attribute is missed."); } string sDelimiter = mapping.Attribute["Delimiter"]; if (sDelimiter != null) { for (int i = 0; i < this.ddlDelimiter.Items.Count; i++) { if (this.ddlDelimiter.Items[i].Value == sDelimiter) { this.ddlDelimiter.SelectedIndex = i; break; } } } string sTextQualifier = mapping.Attribute["TextQualifier"]; if (sTextQualifier != null) { for (int i = 0; i < this.ddlTextQualifier.Items.Count; i++) { if (this.ddlTextQualifier.Items[i].Value == sTextQualifier) { this.ddlTextQualifier.SelectedIndex = i; break; } } } string sEncoding = "Default"; try { sEncoding = mapping.Attribute["Encoding"]; } catch { } if (sEncoding != null) { for (int i = 0; i < this.ddlEncoding.Items.Count; i++) { if (this.ddlDelimiter.Items[i].Value == sEncoding) { this.ddlEncoding.SelectedIndex = i; break; } } } if (this.ddlDataFiles.SelectedIndex > 0) { this.tbMappingFileName.Text = Path.GetFileNameWithoutExtension(this.ddlMappingFiles.SelectedValue); this.ddlMappingFiles.SelectedIndex = 0; } BindDataType(); RestoreValues(mapping); MappingFill(); } }
private void MappingFill() { MetaDataPlus.Import.Rule mapping = this.ClassRule; foreach (DataGridItem item in grdFields.Items) { DropDownList ddl = (DropDownList)item.FindControl("ddlFields"); TextBox tbCustomValue = (TextBox)item.FindControl("tbCustomValue"); DropDownList ddlValues = (DropDownList)item.FindControl("ddlValues"); string sKey = item.Cells[3].Text; bool IsConstant = bool.Parse(item.Cells[7].Text); bool useDictionaryControl = GetUseDictionaryFlag(item); MetaDataPlus.Import.RuleItem ruleItem = (MetaDataPlus.Import.RuleItem)mapping[sKey]; if (IsConstant) { if (mapping.Attribute[sKey] != null) { mapping.Attribute[sKey] = ddl.SelectedValue; } else { mapping.Attribute.Add(sKey, ddl.SelectedValue); } } else { switch (ddl.SelectedValue) { case "CustomValue": mapping[sKey].FillType = MetaDataPlus.Import.FillType.Custom; if (useDictionaryControl) { ruleItem.CustomValue = ddlValues.SelectedValue; } else { ruleItem.CustomValue = tbCustomValue.Text; } ruleItem.SrcColumnName = ""; break; case "NotSet": ruleItem.FillType = MetaDataPlus.Import.FillType.NotUse; ruleItem.SrcColumnName = ""; ruleItem.CustomValue = ""; break; case "": ruleItem.FillType = MetaDataPlus.Import.FillType.Default; ruleItem.SrcColumnName = ""; ruleItem.CustomValue = ""; break; default: ruleItem.FillType = MetaDataPlus.Import.FillType.CopyValue; ruleItem.SrcColumnName = ddl.SelectedValue; ruleItem.SrcColumnType = typeof(string); ruleItem.CustomValue = ""; break; } } } this.ClassRule = mapping; }
private void RestoreValues(MetaDataPlus.Import.Rule mapping) { foreach (DataGridItem item in grdFields.Items) { DropDownList ddl = (DropDownList)item.FindControl("ddlFields"); TextBox tbCustomValue = (TextBox)item.FindControl("tbCustomValue"); DropDownList ddlValues = (DropDownList)item.FindControl("ddlValues"); string sKey = item.Cells[3].Text; //string sType = item.Cells[4].Text; //bool sIsSystemDictionary = bool.Parse(item.Cells[5].Text); bool IsConstant = bool.Parse(item.Cells[7].Text); bool useDictionaryControl = GetUseDictionaryFlag(item); if (IsConstant) { if (mapping.Attribute[sKey] != null) { string val = mapping.Attribute[sKey]; for (int i = 0; i < ddl.Items.Count; i++) { if (ddl.Items[i].Value == val) { ddl.SelectedIndex = i; break; } } } continue; } if (mapping[sKey] != null) { MetaDataPlus.Import.RuleItem ruleItem = (MetaDataPlus.Import.RuleItem)mapping[sKey]; if (ruleItem.SrcColumnName != "") { for (int i = 0; i < ddl.Items.Count; i++) { if (ddl.Items[i].Value == ruleItem.SrcColumnName) { ddl.SelectedIndex = i; break; } } } else { if (ruleItem.CustomValue != "") { if (useDictionaryControl) { for (int i = 0; i < ddl.Items.Count; i++) { if (ddl.Items[i].Value == "CustomValue") { ddl.SelectedIndex = i; break; } } if (ddl.SelectedIndex > 0) { ddlValues.Style.Add("display", "block"); for (int i = 0; i < ddlValues.Items.Count; i++) { if (ddlValues.Items[i].Value == ruleItem.CustomValue) { ddlValues.SelectedIndex = i; break; } } } } else { for (int i = 0; i < ddl.Items.Count; i++) { if (ddl.Items[i].Value == "CustomValue") { ddl.SelectedIndex = i; tbCustomValue.Style.Add("display", "block"); tbCustomValue.Text = ruleItem.CustomValue; break; } } } } } } } }
private void BindDataType() { DataRow dr; DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("key", typeof(string))); dt.Columns.Add(new DataColumn("name", typeof(string))); dt.Columns.Add(new DataColumn("Type", typeof(string))); dt.Columns.Add(new DataColumn("IsSystemDictionary", typeof(bool))); dt.Columns.Add(new DataColumn("AllowNulls", typeof(bool))); dt.Columns.Add(new DataColumn("IsConstant", typeof(bool))); MappingMetaClass mmc = null; MetaDataPlus.Import.Rule mapping = null; string MetaClassName = ddlMetaClass.SelectedValue; string language = ddlLanguage.SelectedValue; switch (ddlTypeData.SelectedValue) { case "Category": CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogContext.MetaDataContext.Language = language; if (!String.IsNullOrEmpty(MetaClassName)) { mmc = new CategoryMappingMetaClass(CatalogContext.MetaDataContext, MetaClassName, -1); } else { mmc = new CategoryMappingMetaClass(CatalogContext.MetaDataContext, -1); } CatalogContext.MetaDataContext.UseCurrentUICulture = true; mapping = mmc.CreateClassRule(); mapping.Attribute.Add("TypeName", "Category"); if (!String.IsNullOrEmpty(language)) { mapping.Attribute.Add("Language", language); } break; case "Entry": CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogContext.MetaDataContext.Language = language; if (!String.IsNullOrEmpty(MetaClassName)) { mmc = new EntryMappingMetaClass(CatalogContext.MetaDataContext, MetaClassName, -1); } else { mmc = new EntryMappingMetaClass(CatalogContext.MetaDataContext, -1); } CatalogContext.MetaDataContext.UseCurrentUICulture = true; mapping = mmc.CreateClassRule(); mapping.Attribute.Add("TypeName", "Entry"); if (!String.IsNullOrEmpty(language)) { mapping.Attribute.Add("Language", language); } break; case "EntryRelation": mmc = new EntryRelationMappingMetaClass(CatalogContext.MetaDataContext, -1); mapping = mmc.CreateClassRule(); mapping.Attribute.Add("TypeName", "EntryRelation"); break; case "EntryAssociation": mmc = new EntryAssociationMappingMetaClass(CatalogContext.MetaDataContext, -1); mapping = mmc.CreateClassRule(); mapping.Attribute.Add("TypeName", "EntryAssociation"); break; case "Variation": mmc = new VariationMappingMetaClass(CatalogContext.MetaDataContext, -1); mapping = mmc.CreateClassRule(); mapping.Attribute.Add("TypeName", "Variation"); break; case "SalePrice": mmc = new PricingMappingMetaClass(CatalogContext.MetaDataContext, -1); mapping = mmc.CreateClassRule(); mapping.Attribute.Add("TypeName", "SalePrice"); break; default: return; } mapping.Attribute.Add("Delimiter", this.ddlDelimiter.SelectedValue); mapping.Attribute.Add("TextQualifier", this.ddlTextQualifier.SelectedValue); foreach (ColumnInfo ci in mmc.ColumnInfos) { dr = dt.NewRow(); if (ci.Field.IsSystem) { dr["key"] = ci.FieldName; dr["name"] = (ci.FieldFriendlyName != null) ? ci.FieldFriendlyName : ci.FieldName; } else { dr["key"] = ci.FieldName; dr["name"] = ci.FieldFriendlyName; } if (ci.Field.MultiLanguageValue && !String.IsNullOrEmpty(language)) { dr["name"] += String.Format(" ({0})", language); } dr["Type"] = ci.Field.DataType.ToString(); dr["IsSystemDictionary"] = ci.IsSystemDictionary; dr["AllowNulls"] = ci.Field.AllowNulls; dr["IsConstant"] = false; dt.Rows.Add(dr); mapping.Add(new RuleItem(ci.Field, MetaDataPlus.Import.FillType.NotUse)); } grdFields.Columns[0].HeaderText = RM.GetString("IMPORT_MAPPING_TITLE_FIELDS"); grdFields.Columns[1].HeaderText = RM.GetString("IMPORT_MAPPING_TITLE_COLUMN_HEADERS"); grdFields.Columns[2].HeaderText = "Custom values"; grdFields.DataSource = dt; grdFields.DataBind(); this.ClassRule = mapping; if (ddlDataFiles.SelectedIndex > 0) { IIncomingDataParser parser = null; DataSet rawData = null; try { char chTextQualifier = (this.ddlTextQualifier.SelectedValue == "") ? '\0' : char.Parse(this.ddlTextQualifier.SelectedValue); parser = new CsvIncomingDataParser(SourcePath, true, char.Parse(this.ddlDelimiter.SelectedValue), chTextQualifier, true, GetEncoding(this.ddlEncoding.SelectedValue)); rawData = parser.Parse(ddlDataFiles.SelectedItem.Text, null); } catch (Exception ex) { DisplayErrorMessage(ex.Message); return; } DataTable dtSource = rawData.Tables[0]; DataTable dtColumns = new DataTable(); dtColumns.Columns.Add(new DataColumn("Text", typeof(string))); dtColumns.Columns.Add(new DataColumn("Value", typeof(string))); foreach (DataColumn dc in dtSource.Columns) { dr = dtColumns.NewRow(); dr["Text"] = "Column " + (dc.Ordinal + 1) + " - " + dc.ColumnName; dr["Value"] = dc.ColumnName; dtColumns.Rows.Add(dr); } foreach (DataGridItem dgi in grdFields.Items) { DropDownList ddl = (DropDownList)dgi.FindControl("ddlFields"); TextBox tbCustomValue = (TextBox)dgi.FindControl("tbCustomValue"); DropDownList ddlValues = (DropDownList)dgi.FindControl("ddlValues"); string sKey = dgi.Cells[3].Text; string sType = dgi.Cells[4].Text; bool sIsSystemDictionary = bool.Parse(dgi.Cells[5].Text); bool allowNulls = bool.Parse(dgi.Cells[6].Text); bool IsConstant = bool.Parse(dgi.Cells[7].Text); bool useDictionaryControl = GetUseDictionaryFlag(dgi); if (!IsConstant) { if (ddl != null) { ddl.DataSource = dtColumns; ddl.DataTextField = "Text"; ddl.DataValueField = "Value"; ddl.DataBind(); if (sIsSystemDictionary) { ddl.Items.Insert(0, new ListItem("<" + RM.GetString("IMPORT_TYPE_VALUES_DICTIONARY_VALUE") + ">", "CustomValue")); } else { ddl.Items.Insert(0, new ListItem("<" + RM.GetString("IMPORT_TYPE_VALUES_CUSTOM_VALUE") + ">", "CustomValue")); } if (allowNulls) { ddl.Items.Insert(0, new ListItem("", "")); } else { ddl.Items.Insert(0, new ListItem("<" + RM.GetString("IMPORT_TYPE_VALUES_NOT_SET") + ">", "NotSet")); } string customControlID = useDictionaryControl ? ddlValues.ClientID : tbCustomValue.ClientID; string jsDllOnChange = String.Format("ddlOnChange(this, 'CustomValue', '{0}')", customControlID); ddl.Attributes.Add("OnChange", jsDllOnChange); } } //fill custom or dictionary controls ddlValues.Visible = useDictionaryControl; tbCustomValue.Visible = !ddlValues.Visible; if (sType.Equals(MetaDataType.Boolean.ToString()) || sType.Equals(MetaDataType.Bit.ToString())) { ddlValues.Items.Clear(); ddlValues.Items.Add("True"); ddlValues.Items.Add("False"); } if (sKey.Equals("sys_RowAction")) { ddlValues.Items.Clear(); ddlValues.Items.Add(RowAction.Default.ToString()); ddlValues.Items.Add(RowAction.Insert.ToString()); ddlValues.Items.Add(RowAction.Update.ToString()); ddlValues.Items.Add(RowAction.Delete.ToString()); } switch (ddlTypeData.SelectedValue) { case "Category": if (sKey == "TemplateName") { TemplateDto templates = DictionaryManager.GetTemplateDto(); if (templates.main_Templates.Count > 0) { DataView view = templates.main_Templates.DefaultView; view.RowFilter = "TemplateType = 'node'"; ddlValues.DataTextField = "FriendlyName"; ddlValues.DataValueField = "Name"; ddlValues.DataSource = view; ddlValues.DataBind(); } } break; case "Entry": if (sKey == "ClassTypeId") { ddlValues.Items.Clear(); ddlValues.Items.Add(new ListItem("Product", EntryType.Product)); ddlValues.Items.Add(new ListItem("Variation/Sku", EntryType.Variation)); ddlValues.Items.Add(new ListItem("Package", EntryType.Package)); ddlValues.Items.Add(new ListItem("Bundle", EntryType.Bundle)); ddlValues.Items.Add(new ListItem("Dynamic Package", EntryType.DynamicPackage)); } if (sKey == "TemplateName") { TemplateDto templates = DictionaryManager.GetTemplateDto(); if (templates.main_Templates.Count > 0) { DataView view = templates.main_Templates.DefaultView; view.RowFilter = "TemplateType = 'entry'"; ddlValues.DataTextField = "FriendlyName"; ddlValues.DataValueField = "Name"; ddlValues.DataSource = view; ddlValues.DataBind(); } } break; case "EntryAssociation": if (sKey == "AssociationType") { ddlValues.Items.Clear(); CatalogAssociationDto dto = CatalogContext.Current.GetCatalogAssociationDto(0); if (dto.AssociationType.Count > 0) { ddlValues.DataTextField = "Description"; ddlValues.DataValueField = "AssociationTypeId"; ddlValues.DataSource = dto.AssociationType; ddlValues.DataBind(); } } break; case "Variation": if (sKey == "TaxCategoryId") { CatalogTaxDto taxes = CatalogTaxManager.GetTaxCategories(); if (taxes.TaxCategory != null) { ddlValues.DataTextField = "Name"; ddlValues.DataValueField = "TaxCategoryId"; ddlValues.DataSource = taxes.TaxCategory.Rows; ddlValues.DataBind(); } } if (sKey == "MerchantId") { CatalogEntryDto merchants = CatalogContext.Current.GetMerchantsDto(); if (merchants.Merchant != null) { ddlValues.DataTextField = "Name"; ddlValues.DataValueField = "MerchantId"; ddlValues.DataSource = merchants.Merchant.Rows; ddlValues.DataBind(); } } if (sKey == "WarehouseId") { WarehouseDto warehouses = WarehouseManager.GetWarehouseDto(); if (warehouses.Warehouse != null) { ddlValues.DataTextField = "Name"; ddlValues.DataValueField = "WarehouseId"; ddlValues.DataSource = warehouses.Warehouse.Rows; ddlValues.DataBind(); } } if (sKey == "PackageId") { ShippingMethodDto shippingDto = ShippingManager.GetShippingPackages(); if (shippingDto.Package != null) { ddlValues.DataTextField = "Name"; ddlValues.DataValueField = "PackageId"; ddlValues.DataSource = shippingDto.Package.Rows; ddlValues.DataBind(); } } break; case "SalePrice": if (sKey == "SaleType") { ddlValues.Items.Clear(); foreach (SalePriceTypeDefinition element in CatalogConfiguration.Instance.SalePriceTypes) { ListItem li = new ListItem(UtilHelper.GetResFileString(element.Description), element.Value.ToString()); ddlValues.Items.Add(li); } } if (sKey == "Currency") { CurrencyDto dto = CatalogContext.Current.GetCurrencyDto(); ddlValues.DataTextField = "Name"; ddlValues.DataValueField = "CurrencyCode"; ddlValues.DataSource = dto.Currency; ddlValues.DataBind(); } break; default: break; } } } }
private void ShowStep(int step) { for (int i = 0; i <= _stepCount + 1; i++) { ((Panel)steps[i]).Visible = false; } ((Panel)steps[step - 1]).Visible = true; //if(step==1) //{ // pastStep.Value="1"; //} #region step2 if (step == 2) { if (pastStep.Value == "1" && fSourceFile.PostedFile != null && fSourceFile.PostedFile.ContentLength > 0) { ProcessFileCache(Server.MapPath(CommonHelper.ChartPath)); String dir = CommonHelper.ChartPath; string wwwpath = dir + Guid.NewGuid().ToString(); switch (rbSourceType.SelectedValue) { case "0": //wwwpath += ".xls"; // OZ: Added XLS and XLSX extensions wwwpath += Path.GetExtension(fSourceFile.PostedFile.FileName); break; case "1": wwwpath += ".xml"; break; default: break; } wwwPath.Value = wwwpath; using (Stream sw = File.Create(Server.MapPath(wwwpath))) { fSourceFile.PostedFile.InputStream.Seek(0, SeekOrigin.Begin); System.IO.BinaryReader br = new System.IO.BinaryReader(fSourceFile.PostedFile.InputStream); int iBufferSize = 655360; // 640 KB byte[] outbyte = br.ReadBytes(iBufferSize); while (outbyte.Length > 0) { sw.Write(outbyte, 0, outbyte.Length); outbyte = br.ReadBytes(iBufferSize); } br.Close(); } IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwPath.Value)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } try { //rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); DataTable dtSource = rawData.Tables[0]; DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("SourceField", typeof(string))); dt.Columns.Add(new DataColumn("IBNField", typeof(string))); dt.Columns.Add(new DataColumn("realIBNFieldName", typeof(string))); dt.Columns.Add(new DataColumn("IsIn", typeof(bool))); DataRow dr; MappingMetaClass mc = null; mc = new IncidentMappingMetaClass(); foreach (ColumnInfo ci in mc.ColumnInfos) { dr = dt.NewRow(); dr["SourceField"] = LocRM.GetString("imNotSet"); if (ci.Field.IsSystem) { dr["IBNField"] = LocRM.GetString("tw" + ci.FieldName); dr["realIBNFieldName"] = ci.FieldName; } else { dr["IBNField"] = ci.FieldFriendlyName; dr["realIBNFieldName"] = ci.FieldName; } dr["IsIn"] = true; dt.Rows.Add(dr); } DataTable dtColumns = new DataTable(); dtColumns.Columns.Add(new DataColumn("SourceField", typeof(string))); dtColumns.Columns.Add(new DataColumn("IsIn", typeof(bool))); foreach (DataColumn dc in dtSource.Columns) { dr = dtColumns.NewRow(); dr["SourceField"] = dc.ColumnName; dr["IsIn"] = true; dtColumns.Rows.Add(dr); } ViewState["Fields"] = dt; ViewState["SourceFields"] = dtColumns; BindDG(); } catch { step2.Visible = false; step4.Visible = false; step5.Visible = false; step6.Visible = true; ((WizardTemplate)Page.Controls[0]).btnNext.Visible = false; ((WizardTemplate)Page.Controls[0]).btnBack.Visible = false; lblFinalResult.Text = String.Format(LocRM.GetString("imErrorListText"), String.Format("<a href='mailto:{0}'>{0}</a>", GlobalResourceManager.Strings["SupportEmail"])); return; } } ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = false; if (ViewState["Fields"] != null) { BindDG(); } else { ((WizardTemplate)Page.Controls[0]).btnNext.Disabled = true; grdFields.DataSource = null; grdFields.DataBind(); } pastStep.Value = "2"; } #endregion #region step3 - not Lists if (step == 3) { DataTable dtFields = (DataTable)ViewState["Fields"]; IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwPath.Value)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } //DataSet rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); DataTable dtSource = rawData.Tables[0]; MappingMetaClass mc = null; mc = new IncidentMappingMetaClass(); MetaDataPlus.Import.Rule mapping = mc.CreateClassRule(); DataTable dtColumns = (DataTable)ViewState["SourceFields"]; foreach (DataRow dr in dtColumns.Rows) { string srcColumnName = dr["SourceField"].ToString(); DataColumn dc = dtSource.Columns[srcColumnName]; DataRow[] drF = dtFields.Select("SourceField = '" + srcColumnName + "'"); if (drF.Length > 0) { string realIBNField = drF[0]["realIBNFieldName"].ToString(); MetaField mf = mc.GetColumnInfo(realIBNField).Field; if (mf != null) { mapping.Add(new RuleItem(srcColumnName, dc.DataType, mf, FillTypes.CopyValue)); } } else { mapping.Add(new RuleItem(srcColumnName, dc.DataType)); } } try { FillResult fr = null; fr = ((IncidentMappingMetaClass)mc).FillData(FillDataMode.New, dtSource, mapping, 0); if (fr.ErrorRows > 0) { string sText = String.Format(LocRM.GetString("imSomeErrors"), fr.SuccessfulRows.ToString(), fr.ErrorRows.ToString()); int index = 0; foreach (string sError in fr.Errors) { if ((++index) > 5) { break; } else { sText += "<br> <li>" + sError + "</li>"; } } lblFirstResult.Text = sText; } else { lblFirstResult.Text = String.Format(LocRM.GetString("imWasDone"), fr.SuccessfulRows.ToString()); lblFinalResult.Text = String.Format(LocRM.GetString("imWasDone"), fr.SuccessfulRows.ToString()); ((WizardTemplate)Page.Controls[0]).btnNext.Visible = false; ((WizardTemplate)Page.Controls[0]).btnBack.Visible = false; //Page.RegisterStartupScript("onfourthload","<script language='javascript'>"+ //"NextStep();"+ //"function NextStep(){var obj = document.getElementById('"+((WizardTemplate)Page.Controls[0]).btnNext.ClientID+"'); obj.click();}</script>"); } } catch (Exception ex) { lblFirstResult.Text = LocRM.GetString("imSimpleError") + " " + ex.Message; } pastStep.Value = "3"; } #endregion #region step4 - not Lists if (step == 4) { DataTable dtFields = (DataTable)ViewState["Fields"]; IIncomingDataParser parser = null; DataSet rawData = null; switch (rbSourceType.SelectedIndex) { case 0: IMCOleDBHelper helper = (IMCOleDBHelper)Activator.GetObject(typeof(IMCOleDBHelper), ConfigurationManager.AppSettings["McOleDbServiceString"]); rawData = helper.ConvertExcelToDataSet(Server.MapPath(wwwPath.Value)); break; case 1: parser = new XmlIncomingDataParser(); rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); break; } //DataSet rawData = parser.Parse(Server.MapPath(wwwPath.Value), null); DataTable dtSource = rawData.Tables[0]; MappingMetaClass mc = null; mc = new IncidentMappingMetaClass(); MetaDataPlus.Import.Rule mapping = mc.CreateClassRule(); foreach (DataRow dr in dtFields.Rows) { string srcColumnName = dr["SourceField"].ToString(); DataColumn dc = dtSource.Columns[srcColumnName]; string realIBNField = dr["realIBNFieldName"].ToString(); if (realIBNField.Length > 0) { MetaField mf = mc.GetColumnInfo(realIBNField).Field; if (mf != null) { mapping.Add(new RuleItem(srcColumnName, dc.DataType, mf, FillTypes.CopyValue)); } } else { mapping.Add(new RuleItem(srcColumnName, dc.DataType)); } } try { FillResult fr = null; fr = ((IncidentMappingMetaClass)mc).FillData(FillDataMode.New, dtSource, mapping, -1); lblFinalResult.Text = String.Format(LocRM.GetString("imWasDone"), fr.SuccessfulRows.ToString()); } catch (Exception ex) { lblFinalResult.Text = LocRM.GetString("imSimpleError") + " " + ex.Message; } pastStep.Value = "5"; } #endregion }
/// <summary> /// Processes the import button event. /// </summary> protected void DoImport(Guid appId) { AppContext.Current.ApplicationId = appId; try { string filePath = SelectedFilePath; string mappingFilePath = SelectedMappingFilePath; if (String.IsNullOrEmpty(filePath)) { throw new Exception("No selected file."); } if (!String.IsNullOrEmpty(mappingFilePath)) { MetaDataPlus.Import.Rule mapping = MetaDataPlus.Import.Rule.XmlDeserialize(CatalogContext.MetaDataContext, mappingFilePath); char chTextQualifier = '\0'; if (mapping.Attribute["TextQualifier"].ToString() != "") { chTextQualifier = char.Parse(mapping.Attribute["TextQualifier"]); } string sEncoding = "Default"; try { sEncoding = mapping.Attribute["Encoding"]; } catch { } IIncomingDataParser parser = null; DataSet rawData = null; try { parser = new CsvIncomingDataParser(SourcePath, true, char.Parse(mapping.Attribute["Delimiter"].ToString()), chTextQualifier, true, GetEncoding(sEncoding)); rawData = parser.Parse(Path.GetFileName(filePath), null); } catch (Exception ex) { throw ex; } DataTable dtSource = rawData.Tables[0]; MappingMetaClass mc = null; try { int CatalogId = 0; FillResult fr = null; switch (mapping.Attribute["TypeName"]) { case "Category": if (!String.IsNullOrEmpty(ListCatalogs.SelectedValue)) { CatalogId = Int32.Parse(ListCatalogs.SelectedValue); } CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogContext.MetaDataContext.Language = mapping.Attribute["Language"]; mc = new CategoryMappingMetaClass(CatalogContext.MetaDataContext, mapping.ClassName, CatalogId); fr = ((CategoryMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); CatalogContext.MetaDataContext.UseCurrentUICulture = true; break; case "Entry": if (!String.IsNullOrEmpty(ListCatalogs.SelectedValue)) { CatalogId = Int32.Parse(ListCatalogs.SelectedValue); } CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogContext.MetaDataContext.Language = mapping.Attribute["Language"]; mc = new EntryMappingMetaClass(CatalogContext.MetaDataContext, mapping.ClassName, CatalogId); fr = ((EntryMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); CatalogContext.MetaDataContext.UseCurrentUICulture = true; break; case "EntryRelation": mc = new EntryRelationMappingMetaClass(CatalogContext.MetaDataContext, CatalogId); fr = ((EntryRelationMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); break; case "EntryAssociation": mc = new EntryAssociationMappingMetaClass(CatalogContext.MetaDataContext, CatalogId); fr = ((EntryAssociationMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); break; case "Variation": mc = new VariationMappingMetaClass(CatalogContext.MetaDataContext, CatalogId); fr = ((VariationMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); break; case "SalePrice": mc = new PricingMappingMetaClass(CatalogContext.MetaDataContext, CatalogId); fr = ((PricingMappingMetaClass)mc).FillData(FillDataMode.All, dtSource, mapping, -1, DateTime.UtcNow); break; } if (fr != null) { if (fr.ErrorRows > 0) { foreach (Exception expt in fr.Exceptions) { string exMessage = expt.Message; if (expt is MDPImportException) { MDPImportException mdpEx = (MDPImportException)expt; if (mdpEx.RowIndex > -1) { exMessage = String.Format("Import error. Line {0}: {1}", mdpEx.RowIndex + 1, exMessage); } } ProgressControl1.AddProgressMessageText(exMessage, true, 0); } } if (fr.Warnings.Length > 0) { foreach (MDPImportWarning MDPWarn in fr.Warnings) { ProgressControl1.AddProgressMessageText(String.Format("Line {0}: {1}", MDPWarn.RowIndex + 1, MDPWarn.Message), false, 0); } } string msgSuccessful = RM.GetString("IMPORT_MSG_SUCCESSFUL") + ". " + string.Format(RM.GetString("IMPORT_MSG_RESULT"), fr.SuccessfulRows.ToString(), fr.TotalRows.ToString()); ProgressControl1.AddProgressMessageText(msgSuccessful, false, 100); } } catch (Exception ex) { throw ex; } } } catch (Exception ex) { ProgressControl1.AddProgressMessageText(ex.Message, true, 100); } finally { } }