public CategoryListCtrl(CategoryContainer container, List<string> catImpLst = null, bool isEditable = true, bool loadEachNode = false, int limit = 0, bool lockOutParentSelectionNodes = false) { InitializeComponent(); this.gl_isEditable = isEditable; this.gl_loadEachNode = loadEachNode; this.gl_lockCnt = limit; this.gl_lockOutParentNodes = lockOutParentSelectionNodes; this.CategoryDeSelected += new CategoryUnOrSelectedEventHandler(CategoryListCtrl_CategoryDeSelected); this.CategorySelected += new CategoryUnOrSelectedEventHandler(CategoryListCtrl_CategorySelected); if (catImpLst != null) { this.gl_catImpLst = catImpLst; } else { this.gl_catImpLst = new List<string>(); } LoadSettingsFromContainer(container, catImpLst); }
public static List<string> GetCategoryIdList(CategoryContainer catContainer, string path) { List<string> list = new List<string>(); string[] wPath = path.Split(new Char[] { '/' }); if (wPath.Length < 2) return null; CategoryContainer container = catContainer; bool foundAllPaths = false; for (int i = 0; i < container.Items.Count; i++) { if (container.Items[i].CategoryName == wPath[0]) { list.Add(container.Items[i].CategoryId); // enter sub routine to find the child items to see if they match. FindNextNodeC(container.Items[i], wPath, 1, list, ref foundAllPaths); if (foundAllPaths == true) break; list.Clear(); } } if (foundAllPaths == false) return null; return list; }
private void LoadSettingsFromContainer(CategoryContainer container, List<string> catImpLst = null) { this.gl_catDefLst = new Dictionary<string, CategoryDef>(); this.gl_catDevLst = new Dictionary<string, CategoryIdDevice>(); this.gl_xDoc = null; this.gl_catContainer = container; string CategoryId = "{ROOT}"; string CategoryName = "Site Root"; CategoryIdDevice catDev = new CategoryIdDevice(CategoryId, CategoryName); catDev.xIsEnabledChk.IsEnabled = false; catDev.CategorySelected += new CategoryUnOrSelectedEventHandler(catDev_CategorySelected); TreeViewItem tItm = new TreeViewItem(); tItm.Selected += new RoutedEventHandler(tItm_Selected); tItm.Header = catDev; this.xCatTreeLst.Items.Add(tItm); this.gl_catDevLst.Add(CategoryId, catDev); CommandBinding cb = new CommandBinding(gl_AddCmd, gl_addCmdExecuted, gl_addCmdCanExecute); this.CommandBindings.Add(cb); CommandBinding cb2 = new CommandBinding(gl_delCmd, gl_delCmdExecuted, gl_delCmdCanExecute); this.CommandBindings.Add(cb2); CommandBinding cb3 = new CommandBinding(gl_editCmd, gl_editCmd_Executed, gl_editCmd_CanExecute); this.CommandBindings.Add(cb3); this.xAddCatBtn.Command = gl_AddCmd; this.xDeleteCatBtn.Command = gl_delCmd; this.xEditCatBtn.Command = gl_editCmd; this.CategoryAdded += new CategoryAddedEventHandler(CategoryListCtrl_CategoryAdded); this.CategoryRemoved += new CategoryRemovedEventHandler(CategoryListCtrl_CategoryRemoved); this.CategoryEdited += new CategoryEditedEventHandler(CategoryListCtrl_CategoryEdited); LoadInitCategoriesFromSource(); if (catImpLst != null) { foreach (string catDefItm in catImpLst) { var selectQuery = from KeyValuePair<string, CategoryIdDevice> category in this.gl_catDevLst where category.Key == catDefItm select category; foreach (var category in selectQuery) { try { this.gl_catDevLst[category.Key].CategoryIsSelected = true; } catch { } } } } this.xAddCatBtn.Click += new RoutedEventHandler(xAddCatBtn_Click); }
public static List<string> BuildPathIfNotExist(CategoryContainer catContainer, string path, bool appendToFirstFound = true) { try { string[] wPath = path.Split(new Char[] { '/' }); if (wPath.Length < 2) { #if DEBUG System.Diagnostics.Debug.WriteLine("The path does not contain a path long enough to travel down."); #endif return null; } List<string> tmpList = CategoryMgr.GetCategoryIdList(catContainer, path); if (tmpList == null) { if (appendToFirstFound == true) { // The path does not exist. Attempt to build it. CategoryItm lItm = null; string cPath = wPath[0]; //for (int i = 1; i < wPath.Length; i++) //{ cPath += "/" + wPath[1]; List<string> tmpL = CategoryMgr.GetCategoryIdList(catContainer, cPath); List<string> cTmpL = null; int offset = 1; while (tmpL != null) { cTmpL = tmpL; offset++; cPath += "/" + wPath[offset]; tmpL = CategoryMgr.GetCategoryIdList(catContainer, cPath); } if (cTmpL != null) { string Id = (cTmpL[cTmpL.Count - 1]).ToString(); CategoryItm catItm = catContainer.IdLinkList[Id]; // Ok, so we know the most bottom level. CategoryItm catItm2 = null; for (int i2 = offset; i2 < wPath.Length; i2++) { if (catItm2 == null) { CategoryItm catItm3 = new CategoryItm("{" + Guid.NewGuid().ToString() + "}", wPath[i2], catItm); if (!catContainer.IdLinkList.ContainsKey(catItm3.CategoryId)) { catContainer.IdLinkList.Add(catItm3.CategoryId, catItm3); } catItm.Items.Add(catItm3); catItm2 = catItm3; } else { CategoryItm catItm3 = new CategoryItm("{" + Guid.NewGuid().ToString() + "}", wPath[i2], catItm2); if (!catContainer.IdLinkList.ContainsKey(catItm3.CategoryId)) { catContainer.IdLinkList.Add(catItm3.CategoryId, catItm3); } catItm2.Items.Add(catItm3); catItm2 = catItm3; } } tmpList = CategoryMgr.GetCategoryIdList(catContainer, path); } else { // Ok, so we know that we can't find a partial list to go by, // lets start by creating a whole new one. CategoryItm pCatItm = null; bool foundRootCat = false; string rootCatId = ""; // try one last attempt to see if there is a root category available. var rootQuery = from CategoryItm catItm in catContainer.Items where catItm.CategoryName == wPath[0] select catItm; foreach (var category in rootQuery) { foundRootCat = true; rootCatId = category.CategoryId; break; } if (foundRootCat == false) { pCatItm = new CategoryItm("{" + Guid.NewGuid().ToString() + "}", wPath[0]); catContainer.Items.Add(pCatItm); } else { pCatItm = catContainer.IdLinkList[rootCatId]; } catContainer.Items.Add(pCatItm); if (!catContainer.IdLinkList.ContainsKey(pCatItm.CategoryId)) { catContainer.IdLinkList.Add(pCatItm.CategoryId, pCatItm); } for (int i2 = 1; i2 < wPath.Length; i2++) { CategoryItm catItm = new CategoryItm(Guid.NewGuid().ToString(), wPath[i2], pCatItm); pCatItm.Items.Add(catItm); if (!catContainer.IdLinkList.ContainsKey(catItm.CategoryId)) { catContainer.IdLinkList.Add(catItm.CategoryId, catItm); } pCatItm = catItm; } return (tmpList = CategoryMgr.GetCategoryIdList(catContainer, path)); } return tmpList; } else { CategoryItm pCatItm = new CategoryItm("{" + Guid.NewGuid().ToString() + "}", wPath[0]); catContainer.Items.Add(pCatItm); catContainer.IdLinkList.Add(pCatItm.CategoryId, pCatItm); for (int i = 1; i < wPath.Length; i++) { CategoryItm catItm = new CategoryItm("{" + Guid.NewGuid().ToString() + "}", wPath[i], pCatItm); pCatItm.Items.Add(catItm); if (!catContainer.IdLinkList.ContainsKey(catItm.CategoryId)) { catContainer.IdLinkList.Add(catItm.CategoryId, catItm); } pCatItm = catItm; } return (tmpList = CategoryMgr.GetCategoryIdList(catContainer, path)); } //catContainer.Items.Add } else { return tmpList; } } #if DEBUG catch(Exception e) { System.Diagnostics.Debug.WriteLine("Error while trying to build the path. Error: {0}", e.ToString()); } #else catch { } #endif return null; }
public static List<string> BuildZenCartPathIfNotExist(CategoryContainer catContainer, string path, string Host, string Db, string User, string Pwd, bool appendToFirstFound = true) { MySqlConnection mCon1 = null; try { string conStr = string.Format("server={0};database={1};user={2};password={3}", Host, Db, User, Pwd); mCon1 = new MySqlConnection(conStr); mCon1.Open(); string[] wPath = path.Split(new Char[] { '/' }); if (wPath.Length < 2) { #if DEBUG System.Diagnostics.Debug.WriteLine("The path does not contain a path long enough to travel down."); #endif return null; } List<string> tmpList = CategoryMgr.GetCategoryIdList(catContainer, path); if (tmpList == null) { if (appendToFirstFound == true) { // The path does not exist. Attempt to build it. CategoryItm lItm = null; bool c = false; string cPath = wPath[0]; //for (int i = 1; i < wPath.Length; i++) //{ cPath += "/" + wPath[1]; List<string> tmpL = CategoryMgr.GetCategoryIdList(catContainer, cPath); List<string> cTmpL = null; int offset = 1; while (tmpL != null) { cTmpL = tmpL; offset++; cPath += "/" + wPath[offset]; tmpL = CategoryMgr.GetCategoryIdList(catContainer, cPath); } if (cTmpL != null) { string Id = (cTmpL[cTmpL.Count - 1]).ToString(); CategoryItm catItm = catContainer.IdLinkList[Id]; // Ok, so we know the most bottom level. CategoryItm catItm2 = null; for (int i2 = offset; i2 < wPath.Length; i2++) { if (catItm2 == null) { MySqlCommand mCmd1 = new MySqlCommand(string.Format("INSERT INTO categories(parent_id, categories_status) VALUES('{0}', '1');", catItm.CategoryId), mCon1); mCmd1.ExecuteNonQuery(); MySqlCommand mCmd2 = new MySqlCommand(string.Format("INSERT INTO categories_description(categories_id, categories_name) VALUES('{0}', '{1}');", mCmd1.LastInsertedId.ToString(), wPath[i2]), mCon1); mCmd2.ExecuteNonQuery(); CategoryItm catItm3 = new CategoryItm(mCmd1.LastInsertedId.ToString(), wPath[i2], catItm); if (!catContainer.IdLinkList.ContainsKey(catItm3.CategoryId)) { catContainer.IdLinkList.Add(catItm3.CategoryId, catItm3); } catItm.Items.Add(catItm3); catItm2 = catItm3; mCmd1.Dispose(); mCmd1 = null; mCmd2.Dispose(); mCmd2 = null; } else { MySqlCommand mCmd1 = new MySqlCommand(string.Format("INSERT INTO categories(parent_id, categories_status) VALUES('{0}', '1');", catItm2.CategoryId), mCon1); mCmd1.ExecuteNonQuery(); MySqlCommand mCmd2 = new MySqlCommand(string.Format("INSERT INTO categories_description(categories_id, categories_name) VALUES('{0}', '{1}');", mCmd1.LastInsertedId.ToString(), wPath[i2]), mCon1); mCmd2.ExecuteNonQuery(); CategoryItm catItm3 = new CategoryItm(mCmd1.LastInsertedId.ToString(), wPath[i2], catItm2); if (!catContainer.IdLinkList.ContainsKey(catItm3.CategoryId)) { catContainer.IdLinkList.Add(catItm3.CategoryId, catItm3); } catItm2.Items.Add(catItm3); catItm2 = catItm3; } } tmpList = CategoryMgr.GetCategoryIdList(catContainer, path); } else { // Ok, so we know that we can't find a partial list to go by, // lets start by creating a whole new one. bool foundRootCat = false; string rootCatId = ""; // try one last attempt to see if there is a root category available. var rootQuery = from CategoryItm catItm in catContainer.Items where catItm.CategoryName == wPath[0] select catItm; foreach (var category in rootQuery) { foundRootCat = true; rootCatId = category.CategoryId; break; } MySqlCommand mCmd1 = null; if (foundRootCat == false) { mCmd1 = new MySqlCommand("INSERT INTO categories(categories_status) VALUES('1');", mCon1); mCmd1.ExecuteNonQuery(); MySqlCommand mCmd2 = new MySqlCommand(string.Format("INSERT INTO categories_description(categories_id, categories_name) VALUES('{0}', '{1}');", mCmd1.LastInsertedId.ToString(), wPath[0]), mCon1); mCmd2.ExecuteNonQuery(); rootCatId = mCmd1.LastInsertedId.ToString(); mCmd1.Dispose(); mCmd1 = null; mCmd2.Dispose(); mCmd2 = null; } else { // } CategoryItm pCatItm = new CategoryItm(rootCatId, wPath[0]); catContainer.Items.Add(pCatItm); if (!catContainer.IdLinkList.ContainsKey(pCatItm.CategoryId)) { catContainer.IdLinkList.Add(pCatItm.CategoryId, pCatItm); } for (int i2 = 1; i2 < wPath.Length; i2++) { MySqlCommand mCmd3 = new MySqlCommand(string.Format("INSERT INTO categories(parent_id, categories_status) VALUES('{0}', '1');", pCatItm.CategoryId), mCon1); mCmd3.ExecuteNonQuery(); MySqlCommand mCmd4 = new MySqlCommand(string.Format("INSERT INTO categories_description(categories_id, categories_name) VALUES('{0}', '{1}');", mCmd3.LastInsertedId.ToString(), wPath[i2]), mCon1); mCmd4.ExecuteNonQuery(); CategoryItm catItm = new CategoryItm(mCmd3.LastInsertedId.ToString(), wPath[i2], pCatItm); pCatItm.Items.Add(catItm); if (!catContainer.IdLinkList.ContainsKey(catItm.CategoryId)) { catContainer.IdLinkList.Add(catItm.CategoryId, catItm); } mCmd3.Dispose(); mCmd3 = null; mCmd4.Dispose(); mCmd4 = null; pCatItm = catItm; } if (mCon1 != null) { mCon1.Close(); mCon1.Dispose(); mCon1 = null; } return (tmpList = CategoryMgr.GetCategoryIdList(catContainer, path)); } if (mCon1 != null) { mCon1.Close(); mCon1.Dispose(); mCon1 = null; } return tmpList; } else { MySqlCommand mCmd1 = new MySqlCommand("INSERT INTO categories(categories_status) VALUES('1');", mCon1); mCmd1.ExecuteNonQuery(); MySqlCommand mCmd2 = new MySqlCommand(string.Format("INSERT INTO categories_description(categories_id, categories_name) VALUES('{0}', '{1}');", mCmd1.LastInsertedId.ToString(), wPath[0]), mCon1); mCmd2.ExecuteNonQuery(); CategoryItm pCatItm = new CategoryItm(mCmd1.LastInsertedId.ToString(), wPath[0]); catContainer.Items.Add(pCatItm); catContainer.IdLinkList.Add(pCatItm.CategoryId, pCatItm); mCmd1.Dispose(); mCmd1 = null; mCmd2.Dispose(); mCmd2 = null; for (int i = 1; i < wPath.Length; i++) { MySqlCommand mCmd3 = new MySqlCommand(string.Format("INSERT INTO categories(parent_id, categories_status) VALUES('{0}', '1');", pCatItm.CategoryId), mCon1); mCmd3.ExecuteNonQuery(); MySqlCommand mCmd4 = new MySqlCommand(string.Format("INSERT INTO categories_description(categories_id, categories_name) VALUES('{0}', '{1}');", mCmd3.LastInsertedId.ToString(), wPath[i]), mCon1); mCmd4.ExecuteNonQuery(); CategoryItm catItm = new CategoryItm(mCmd3.LastInsertedId.ToString(), wPath[i], pCatItm); pCatItm.Items.Add(catItm); if (!catContainer.IdLinkList.ContainsKey(catItm.CategoryId)) { catContainer.IdLinkList.Add(catItm.CategoryId, catItm); } mCmd3.Dispose(); mCmd3 = null; mCmd4.Dispose(); mCmd4 = null; pCatItm = catItm; } if (mCon1 != null) { mCon1.Close(); mCon1.Dispose(); mCon1 = null; } return (tmpList = CategoryMgr.GetCategoryIdList(catContainer, path)); } //catContainer.Items.Add } else { return tmpList; } } #if DEBUG catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error while trying to build the path. Error: {0}", e.ToString()); } #else catch { } #endif return null; }
//private Dictionary<string, CategoryDef> gl_catDef = new Dictionary<string, CategoryDef>(); public CategoryMgr(string configPath = @".\Categories.xml") { try { this.gl_xDoc = XDocument.Load(this.gl_configPath); //this.xCatTreeLst = new TreeView(); this.gl_container = new CategoryContainer(); this.gl_eBayContainer = new CategoryContainer(); } #if DEBUG catch(FileNotFoundException fnfe) { MessageBox.Show(string.Format("Configuration file was not found for the category manager. Categories will not be loaded. Please locate the categories.xml file. Error: {0}", fnfe.ToString())); OpenFileDialog oFD = new OpenFileDialog(); oFD.Filter = "XML files (*.xml)|*.xml"; oFD.ShowDialog(); if (oFD.FileName != "") { try { this.gl_xDoc = XDocument.Load(this.gl_configPath); //this.xCatTreeLst = new TreeView(); this.gl_container = new CategoryContainer(); this.gl_eBayContainer = new CategoryContainer(); } #if DEBUG catch(Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); #else catch { #endif if (MessageBox.Show("An error was thrown while trying to load the xml file you chose. Unexpected behaviour could arise. You should restart this application once you have located the categories file. Or we could create a new one for you. Would you like us to create a new template for you?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes) { try { // } #if DEBUG catch(Exception ex2) { System.Diagnostics.Debug.WriteLine(ex2.ToString()); #else catch { #endif } } } } } #else catch(FileNotFoundException) { MessageBox.Show("Configuration file was not found for the category manager. Categories will not be loaded."); } #endif LoadInitCategories(); /*foreach (KeyValuePair<string, CategoryDef> catDefItm in catDef) { var selectQuery = from KeyValuePair<string, CategoryIdDevice> category in this.gl_catDevLst where category.Key == catDefItm.Key select category; foreach (var category in selectQuery) { try { this.gl_catDevLst[category.Key].CategoryIsSelected = true; } catch { } } }*/ }
public bool RefresheBayCategories() { try { this.gl_eBayContainer = ContainerBuilders.BuildCategoryFromeBay(); #if DEBUG MessageBox.Show("eBay container built."); #endif return true; } catch { } return false; }
private static void LoadZenNode(int parentId, CategoryItm catItm, DataSet dset_CatM, DataSet dset_CatMDesc, CategoryContainer container) { var categoryQuery = from DataRow category in dset_CatM.Tables["categories"].Rows where category.Field<int>("parent_id") == parentId select category; foreach (var category in categoryQuery) { string catName = ""; var catDesc = from DataRow category2 in dset_CatMDesc.Tables["categories_description"].Rows where category2.Field<int>("categories_id") == category.Field<int>("categories_id") select category2; foreach (var category2 in catDesc) { catName = category2.Field<string>("categories_name").ToString(); break; } string cId = category.Field<int>("categories_id").ToString(); CategoryItm catItm2 = new CategoryItm(cId, catName, catItm); if (!container.IdLinkList.ContainsKey(cId)) { container.IdLinkList.Add(cId, catItm2); } catItm.Items.Add(catItm2); LoadZenNode(int.Parse(catItm2.CategoryId), catItm2, dset_CatM, dset_CatMDesc, container); } }
public CategoryListCtrl GetCategoryLstCtrl(CategoryContainer container, List<string> impCatLst = null, bool isEditable = true, int limit = 0) { try { CategoryListCtrl catLstCtrl = new CategoryListCtrl(container, impCatLst, isEditable, false, limit); catLstCtrl.CategoryAdded += new CategoryAddedEventHandler(catLstCtrl_CategoryAdded); catLstCtrl.CategoryRemoved += new CategoryRemovedEventHandler(catLstCtrl_CategoryRemoved); catLstCtrl.CategoryEdited += new CategoryEditedEventHandler(catLstCtrl_CategoryEdited); return catLstCtrl; } catch { } return null; }
private static void LoadeBayStoreNode(string parentId, CategoryItm catItm, Dictionary<string, CategoryDef> catIdLst, CategoryContainer container) { var categoryQuery = from category in catIdLst where category.Value.ParentId == parentId select category; foreach (var category in categoryQuery) { string catName = category.Value.CategoryName; string cId = category.Value.CategoryId; CategoryItm catItm2 = new CategoryItm(cId, catName, catItm); if (!container.IdLinkList.ContainsKey(cId)) { container.IdLinkList.Add(cId, catItm2); } catItm.Items.Add(catItm2); LoadeBayStoreNode(catItm2.CategoryId, catItm2, catIdLst, container); } }
private static void GeteBayChildCategoriesRoot(StoreCustomCategoryType cat, CategoryItm catItm, int pId, Dictionary<string, CategoryDef> catDefIdLst, CategoryContainer container) { //continue the recursion for each of the child categories foreach (StoreCustomCategoryType childcat in cat.ChildCategory) { //get the category name, ID and whether it is a leaf int parentId = pId; long id = cat.CategoryID; string name = cat.Name; bool leaf = (cat.ChildCategory.Count == 0); Console.WriteLine("id = " + id + " name = " + name + " leaf= " + leaf); CategoryDef catDef = new CategoryDef(childcat.Name, childcat.CategoryID.ToString(), cat.CategoryID.ToString()); try { catDefIdLst.Add(childcat.CategoryID.ToString(), catDef); } catch { } string catName = name; // LoadNode(parent category id, container) -> find all cats call -> LoadNode(parent category id, container) //string pId = parentCategory.Key; CategoryItm catItm2 = new CategoryItm(childcat.CategoryID.ToString(), childcat.Name, catItm); if (!container.IdLinkList.ContainsKey(childcat.CategoryID.ToString())) { container.IdLinkList.Add(childcat.CategoryID.ToString(), catItm2); } catItm.Items.Add(catItm2); GeteBayChildCategoriesRoot(childcat, catItm2, (int)id, catDefIdLst, container); } }
public static CategoryContainer BuildCategoryFromeBay(bool storeCatBuild = false) { if (storeCatBuild == false) { CategoryContainer container = new CategoryContainer(); apiContext = AppSettingHelper.GetApiContext(); apiContext.ApiLogManager = new ApiLogManager(); apiContext.ApiLogManager.ApiLoggerList.Add(new FileLogger("log.txt", true, true, true)); apiContext.ApiLogManager.EnableLogging = true; apiContext.Site = SiteCodeType.US; GetCategoriesCall catCall = new GetCategoriesCall(apiContext) { EnableCompression = true, ViewAllNodes = true }; catCall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); catCall.GetCategories(); Dictionary<string, CategoryDef> catIdCMLst = new Dictionary<string, CategoryDef>(); foreach (CategoryType category in catCall.CategoryList) { int categoryId = Int32.Parse(category.CategoryID); int? parentId = Int32.Parse(category.CategoryParentID[0]); if (parentId == categoryId) { parentId = null; } if (parentId == null) { catIdCMLst.Add(category.CategoryID, new CategoryDef(category.CategoryName, category.CategoryID)); } else { catIdCMLst.Add(category.CategoryID, new CategoryDef(category.CategoryName, category.CategoryID, parentId.ToString())); } } // Lets get all parent categories so we can build down the tree. var parentQuery = from parentCategory in catIdCMLst where parentCategory.Value.ParentId == "" select parentCategory; foreach (var parentCategory in parentQuery) { string catName = parentCategory.Value.CategoryName; // LoadNode(parent category id, container) -> find all cats call -> LoadNode(parent category id, container) string pId = parentCategory.Key; CategoryItm catItm = new CategoryItm(pId, catName); container.IdLinkList.Add(pId, catItm); container.Items.Add(catItm); LoadeBayNode(pId, catItm, catIdCMLst, container); } return container; } else { CategoryContainer container = new CategoryContainer(); apiContext = AppSettingHelper.GetApiContext(); apiContext.ApiLogManager = new ApiLogManager(); apiContext.ApiLogManager.ApiLoggerList.Add(new FileLogger("log.txt", true, true, true)); apiContext.ApiLogManager.EnableLogging = true; apiContext.Site = SiteCodeType.US; GetStoreCall getStoreCall = new GetStoreCall(apiContext) { EnableCompression = true }; getStoreCall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); getStoreCall.CategoryStructureOnly = true; getStoreCall.Execute(); StoreCustomCategoryType cType = new StoreCustomCategoryType(); Dictionary<string, CategoryDef> catIdCMLst = new Dictionary<string, CategoryDef>(); foreach (StoreCustomCategoryType category in getStoreCall.Store.CustomCategories) { CategoryItm catItm = new CategoryItm(category.CategoryID.ToString(), category.Name); container.IdLinkList.Add(category.CategoryID.ToString(), catItm); container.Items.Add(catItm); GeteBayChildCategoriesRoot(category, catItm, (int)category.CategoryID, catIdCMLst, container); //container.Items.Add(catItm); } // Lets get all parent categories so we can build down the tree. /*var parentQuery = from parentCategory in catIdCMLst select parentCategory; foreach (var parentCategory in parentQuery) { string catName = parentCategory.Value.CategoryName; // LoadNode(parent category id, container) -> find all cats call -> LoadNode(parent category id, container) string pId = parentCategory.Key; CategoryItm catItm = new CategoryItm(pId, catName); container.IdLinkList.Add(pId, catItm); container.Items.Add(catItm); LoadeBayNode(pId, catItm, catIdCMLst, container); }*/ return container; } //} //catch //{ // return null; //} }
public static CategoryContainer BuildCategoryFromZenCart(string Host, string Db, string User, string Password) { CategoryContainer container = new CategoryContainer(); string conStr = string.Format("server={0};database={1};user={2};password={3}", Host, Db, User, Password); MySqlConnection mCon = null; //try //{ mCon = new MySqlConnection(conStr); mCon.Open(); MySqlCommand pCmd1 = new MySqlCommand("SELECT * FROM categories;", mCon); MySqlCommand pCmd2 = new MySqlCommand("SELECT * FROM categories_description;", mCon); MySqlDataAdapter mysqlAdapter_cat = null; MySqlDataAdapter mysqlAdapter_catDesc = null; DataSet dsetCatM = new DataSet(); DataSet dsetCatDescM = new DataSet(); mysqlAdapter_cat = new MySqlDataAdapter(pCmd1); MySqlCommandBuilder cmdBuilder1 = new MySqlCommandBuilder(mysqlAdapter_cat); mysqlAdapter_cat.Fill(dsetCatM, "categories"); mysqlAdapter_catDesc = new MySqlDataAdapter(pCmd2); MySqlCommandBuilder cmdBuilder2 = new MySqlCommandBuilder(mysqlAdapter_catDesc); mysqlAdapter_catDesc.Fill(dsetCatDescM, "categories_description"); // Lets get all parent categories so we can build down the tree. var parentQuery = from DataRow parentCategory in dsetCatM.Tables["categories"].Rows where parentCategory.Field<int>("parent_id") == 0 select parentCategory; foreach (var parentCategory in parentQuery) { string catName = ""; // LoadNode(parent category id, container) -> find all cats call -> LoadNode(parent category id, container) var catDesc = from DataRow category in dsetCatDescM.Tables["categories_description"].Rows where category.Field<int>("categories_id") == parentCategory.Field<int>("categories_id") select category; foreach (var category in catDesc) { catName = category.Field<string>("categories_name").ToString(); break; } string pId = parentCategory.Field<int>("categories_id").ToString(); CategoryItm catItm = new CategoryItm(pId, catName); container.IdLinkList.Add(pId, catItm); container.Items.Add(catItm); LoadZenNode(parentCategory.Field<int>("categories_id"), catItm, dsetCatM, dsetCatDescM, container); } pCmd1.Dispose(); pCmd1 = null; pCmd2.Dispose(); pCmd2 = null; mysqlAdapter_cat.Dispose(); mysqlAdapter_cat = null; mysqlAdapter_catDesc.Dispose(); mysqlAdapter_catDesc = null; dsetCatM.Dispose(); dsetCatM = null; dsetCatDescM.Dispose(); dsetCatDescM = null; mCon.Close(); mCon.Dispose(); mCon = null; return container; //} //catch //{ // return null; //} }
public static CategoryContainer BuildCategoryFromeBaySource(string configPath = @".\eBayCategoriesConfig.xml") { try { CategoryContainer container = new CategoryContainer(); XDocument xDoc = XDocument.Load(configPath); return container; } catch { } return null; }