/// <summary> /// Imports the specified input. /// </summary> /// <param name="input">The input.</param> /// <param name="applicationId">The application id.</param> /// <param name="baseFilePath">The base file path.</param> public void Import(string pathToCsvFile, Guid applicationId, Guid?siteId, char delimiter) { CultureInfo currentCultureInfo = GetImportExportCulture(); int totalImportSteps = GetTotalImportSteps(); OnEvent("Starting import...", 0); string fileName = Path.GetFileName(pathToCsvFile); // 1. Parse csv file OnEvent("Start parsing csv file", GetProgressPercent((int)ImportSteps.StartParseFile, totalImportSteps)); CsvIncomingDataParser parser = new CsvIncomingDataParser(Path.GetDirectoryName(pathToCsvFile), true, delimiter); DataSet taxDataSet = parser.Parse(fileName, null); OnEvent("Finished parsing csv file", GetProgressPercent((int)ImportSteps.EndParseFile, totalImportSteps)); // 2. Create Dtos from parsed DataSet if (taxDataSet.Tables[fileName] == null) { throw new OrdersImportExportException(String.Format("Unknown problem with parsing file {0}.", fileName)); } OnEvent("Start processing parsed rows", GetProgressPercent((int)ImportSteps.StartImport, totalImportSteps)); int totalRowCount = taxDataSet.Tables[fileName].Rows.Count; JurisdictionDto currentJurisdictionDto = JurisdictionManager.GetJurisdictions(Mediachase.Commerce.Orders.Managers.JurisdictionManager.JurisdictionType.Tax); TaxDto currentTaxDto = TaxManager.GetTaxDto(TaxType.SalesTax); JurisdictionDto jurisdictionDto = new JurisdictionDto(); TaxDto taxDto = new TaxDto(); for (int i = 0; i <= totalRowCount - 1; i++) { DataRow currentRow = taxDataSet.Tables[fileName].Rows[i]; #region Import Jurisdictions #region JurisdictionDto string jurisdictionCode = currentRow.ItemArray.GetValue(9).ToString(); JurisdictionDto.JurisdictionRow jRow = null; JurisdictionDto.JurisdictionRow[] jRows = (JurisdictionDto.JurisdictionRow[])currentJurisdictionDto.Jurisdiction.Select(String.Format("Code='{0}'", jurisdictionCode)); // check if row has already been imported // (to support multiple values for the same jurisdiction need to check if jurisdiction with the given name already exists in jurisdictionDto) JurisdictionDto.JurisdictionRow[] jRows2 = (JurisdictionDto.JurisdictionRow[])jurisdictionDto.Jurisdiction.Select(String.Format("Code='{0}'", jurisdictionCode)); bool jurisdictionExists = jRows2 != null && jRows2.Length > 0; if (jurisdictionExists) { jRow = jRows2[0]; } else { if (jRows != null && jRows.Length > 0) { jurisdictionDto.Jurisdiction.ImportRow(jRows[0]); jRow = jurisdictionDto.Jurisdiction[jurisdictionDto.Jurisdiction.Count - 1]; } else { jRow = jurisdictionDto.Jurisdiction.NewJurisdictionRow(); jRow.ApplicationId = applicationId; jRow.JurisdictionType = Mediachase.Commerce.Orders.Managers.JurisdictionManager.JurisdictionType.Tax.GetHashCode(); } } jRow.DisplayName = currentRow.ItemArray.GetValue(0).ToString(); jRow.StateProvinceCode = GetStringValue(currentRow.ItemArray.GetValue(1)); jRow.CountryCode = currentRow.ItemArray.GetValue(2).ToString(); jRow.ZipPostalCodeStart = GetStringValue(currentRow.ItemArray.GetValue(3)); jRow.ZipPostalCodeEnd = GetStringValue(currentRow.ItemArray.GetValue(4)); jRow.City = GetStringValue(currentRow.ItemArray.GetValue(5)); jRow.District = GetStringValue(currentRow.ItemArray.GetValue(6)); jRow.County = GetStringValue(currentRow.ItemArray.GetValue(7)); jRow.GeoCode = GetStringValue(currentRow.ItemArray.GetValue(8)); jRow.Code = jurisdictionCode; if (jRow.RowState == DataRowState.Detached) { jurisdictionDto.Jurisdiction.Rows.Add(jRow); } #endregion #region JurisdictionGroupDto string jurisdictionGroupCode = currentRow.ItemArray.GetValue(11).ToString(); JurisdictionDto.JurisdictionGroupRow jGroupRow = null; JurisdictionDto.JurisdictionGroupRow[] jGroupRows = (JurisdictionDto.JurisdictionGroupRow[])currentJurisdictionDto.JurisdictionGroup.Select(String.Format("Code='{0}'", jurisdictionGroupCode)); // check if row has already been imported // (to support multiple values for the same jurisdiction need to check if jurisdiction with the given name already exists in jurisdictionDto) JurisdictionDto.JurisdictionGroupRow[] jGroupRows2 = (JurisdictionDto.JurisdictionGroupRow[])jurisdictionDto.JurisdictionGroup.Select(String.Format("Code='{0}'", jurisdictionGroupCode)); bool jurisdictionGroupExists = jGroupRows2 != null && jGroupRows2.Length > 0; if (jurisdictionGroupExists) { jGroupRow = jGroupRows2[0]; } else { if (jGroupRows != null && jGroupRows.Length > 0) { jurisdictionDto.JurisdictionGroup.ImportRow(jGroupRows[0]); jGroupRow = jurisdictionDto.JurisdictionGroup[jurisdictionDto.JurisdictionGroup.Count - 1]; } else { jGroupRow = jurisdictionDto.JurisdictionGroup.NewJurisdictionGroupRow(); jGroupRow.ApplicationId = applicationId; jGroupRow.JurisdictionType = Mediachase.Commerce.Orders.Managers.JurisdictionManager.JurisdictionType.Tax.GetHashCode(); } } jGroupRow.DisplayName = currentRow.ItemArray.GetValue(10).ToString(); jGroupRow.Code = jurisdictionGroupCode; if (jGroupRow.RowState == DataRowState.Detached) { jurisdictionDto.JurisdictionGroup.Rows.Add(jGroupRow); } #endregion #region JurisdictionRelationDto JurisdictionDto.JurisdictionRelationRow jRelationRow = null; if (jRow.JurisdictionId > 0 && jGroupRow.JurisdictionGroupId > 0) { // check if relation already exists JurisdictionDto.JurisdictionRelationRow[] jRelationRows = (JurisdictionDto.JurisdictionRelationRow[])currentJurisdictionDto.JurisdictionRelation.Select(String.Format("JurisdictionId={0} AND JurisdictionGroupId={1}", jRow.JurisdictionId, jGroupRow.JurisdictionGroupId)); if (jRelationRows != null && jRelationRows.Length > 0) { jurisdictionDto.JurisdictionRelation.ImportRow(jRelationRows[0]); jRelationRow = jurisdictionDto.JurisdictionRelation[jurisdictionDto.JurisdictionRelation.Count - 1]; } } if (jRelationRow == null) { // create new relation jRelationRow = jurisdictionDto.JurisdictionRelation.NewJurisdictionRelationRow(); jRelationRow.JurisdictionId = jRow.JurisdictionId; jRelationRow.JurisdictionGroupId = jGroupRow.JurisdictionGroupId; jurisdictionDto.JurisdictionRelation.Rows.Add(jRelationRow); } #endregion // save jurisdictionDto if (jurisdictionDto.HasChanges()) { JurisdictionManager.SaveJurisdiction(jurisdictionDto); } #endregion #region Import Taxes #region TaxDto TaxDto.TaxRow taxRow = null; string taxName = currentRow.ItemArray.GetValue(13).ToString(); // check if row already exists TaxDto.TaxRow[] taxRows = (TaxDto.TaxRow[])currentTaxDto.Tax.Select(String.Format("Name='{0}'", taxName)); // check if row has already been imported TaxDto.TaxRow[] taxRows2 = (TaxDto.TaxRow[])taxDto.Tax.Select(String.Format("Name='{0}'", taxName)); bool taxExists = taxRows2 != null && taxRows2.Length > 0; if (taxExists) { taxRow = taxRows2[0]; } else { #region if tax is not in the destination dto if (taxRows != null && taxRows.Length > 0) { taxDto.Tax.ImportRow(taxRows[0]); taxRow = taxDto.Tax[taxDto.Tax.Count - 1]; } else { taxRow = taxDto.Tax.NewTaxRow(); taxRow.ApplicationId = applicationId; taxRow.TaxType = TaxType.SalesTax.GetHashCode(); taxRow.Name = taxName; } #endregion } taxRow.SortOrder = Int32.Parse(currentRow.ItemArray.GetValue(14).ToString()); if (taxRow.RowState == DataRowState.Detached) { taxDto.Tax.Rows.Add(taxRow); } #endregion #region TaxLanguageDto TaxDto.TaxLanguageRow taxLanguageRow = null; string langCode = currentRow.ItemArray.GetValue(15).ToString(); // check if row already exists TaxDto.TaxLanguageRow[] taxLanguageRows = (TaxDto.TaxLanguageRow[])currentTaxDto.TaxLanguage.Select(String.Format("LanguageCode='{0}' and TaxId={1}", langCode, taxRow.TaxId)); // check if row has already been imported TaxDto.TaxLanguageRow[] taxLanguageRows2 = (TaxDto.TaxLanguageRow[])taxDto.TaxLanguage.Select(String.Format("LanguageCode='{0}' and TaxId={1}", langCode, taxRow.TaxId)); bool taxLanguageExists = taxLanguageRows2 != null && taxLanguageRows2.Length > 0; string displayName = currentRow.ItemArray.GetValue(12).ToString(); if (taxLanguageExists) { taxLanguageRow = taxLanguageRows2[0]; } else { #region if tax is not in the destination dto if (taxLanguageRows != null && taxLanguageRows.Length > 0) { taxDto.TaxLanguage.ImportRow(taxLanguageRows[0]); taxLanguageRow = taxDto.TaxLanguage[taxDto.TaxLanguage.Count - 1]; } else { taxLanguageRow = taxDto.TaxLanguage.NewTaxLanguageRow(); taxLanguageRow.LanguageCode = langCode; taxLanguageRow.TaxId = taxRow.TaxId; } #endregion } taxLanguageRow.DisplayName = displayName; if (taxLanguageRow.RowState == DataRowState.Detached) { taxDto.TaxLanguage.Rows.Add(taxLanguageRow); } #endregion #region TaxValueDto TaxDto.TaxValueRow taxValueRow = null; // check if row already exists TaxDto.TaxValueRow[] taxValueRows = null; if (siteId.HasValue) { taxValueRows = (TaxDto.TaxValueRow[])currentTaxDto.TaxValue.Select(String.Format("TaxId={0} and SiteId={1} and JurisdictionGroupId={2}", taxRow.TaxId, siteId.Value, jRelationRow.JurisdictionGroupId)); } else { taxValueRows = (TaxDto.TaxValueRow[])currentTaxDto.TaxValue.Select(String.Format("TaxId={0} and JurisdictionGroupId={1}", taxRow.TaxId, jRelationRow.JurisdictionGroupId)); } // check if row has already been imported TaxDto.TaxValueRow[] taxValueRows2 = null; if (siteId.HasValue) { taxValueRows2 = (TaxDto.TaxValueRow[])taxDto.TaxValue.Select(String.Format("TaxId={0} and SiteId={1} and JurisdictionGroupId={2}", taxRow.TaxId, siteId.Value, jRelationRow.JurisdictionGroupId)); } else { taxValueRows2 = (TaxDto.TaxValueRow[])taxDto.TaxValue.Select(String.Format("TaxId={0} and JurisdictionGroupId={1}", taxRow.TaxId, jRelationRow.JurisdictionGroupId)); } bool taxValueExists = taxValueRows2 != null && taxValueRows2.Length > 0; if (taxValueExists) { taxValueRow = taxValueRows2[0]; } else { if (taxValueRows != null && taxValueRows.Length > 0) { taxDto.TaxValue.ImportRow(taxValueRows[0]); taxValueRow = taxDto.TaxValue[taxDto.TaxValue.Count - 1]; } else { taxValueRow = taxDto.TaxValue.NewTaxValueRow(); taxValueRow.TaxId = taxRow.TaxId; } } // assign tax values taxValueRow.JurisdictionGroupId = jGroupRow.JurisdictionGroupId; taxValueRow.TaxCategory = currentRow.ItemArray.GetValue(16).ToString(); taxValueRow.Percentage = float.Parse(currentRow.ItemArray.GetValue(17).ToString(), currentCultureInfo); taxValueRow.AffectiveDate = DateTime.Parse(currentRow.ItemArray.GetValue(18).ToString(), currentCultureInfo); if (siteId.HasValue) { taxValueRow.SiteId = siteId.Value; } // add row to dto, if needed if (taxValueRow.RowState == DataRowState.Detached) { taxDto.TaxValue.Rows.Add(taxValueRow); } // create tax category, if it doesn't exist yet CatalogTaxManager.CreateTaxCategory(taxValueRow.TaxCategory, true); #endregion if (taxDto.HasChanges()) { TaxManager.SaveTax(taxDto); } #endregion if ((i + 1) % 20 == 0) { OnEvent(String.Format("Processed {0} of {1} rows", i + 1, totalRowCount), GetProgressPercent((int)ImportSteps.StartImport, totalImportSteps)); } } OnEvent(String.Format("Finished processing parsed rows. Total processed: {0}", totalRowCount), GetProgressPercent((int)ImportSteps.Finish, totalImportSteps)); OnEvent("CSV file successfully imported.", 100); }
/// <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 { } }
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; } } } }
/// <summary> /// Gets the raw data for CSV. /// Parse CSV file with user defined parameters. /// </summary> /// <returns></returns> private DataSet GetRawDataForCSV() { char delimeter = ','; #region define delimeter switch (ddDelimeter.SelectedValue) { case ",": delimeter = ','; break; case ".": delimeter = '.'; break; case ";": delimeter = ';'; break; case "space": delimeter = ' '; break; case "tab": delimeter = '\t'; break; default: break; } #endregion char textQualifier = '"'; #region define Text Qualifier switch (ddTextQualifier.SelectedValue) { case "\"": textQualifier = '"'; break; case "'": textQualifier = '\''; break; default: break; } #endregion Encoding enc = Encoding.Default; #region define encoding switch (ddEncoding.SelectedValue) { case "ASCII": enc = Encoding.ASCII; break; case "UTF8": enc = Encoding.UTF8; break; case "Unicode": enc = Encoding.Unicode; break; default: break; } #endregion IIncomingDataParser parser = new CsvIncomingDataParser(String.Empty, true, delimeter, textQualifier, true, enc); DataSet rawData = parser.Parse(Server.MapPath(hdnFilePath.Value), null); foreach (DataColumn column in rawData.Tables[0].Columns) { column.ColumnName = column.ColumnName.Trim(textQualifier); } return(rawData); }