예제 #1
0
        private void Thread_Load_Categories()
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("ItemCategories.xml");
            foreach (XmlNode xmlNode1 in xmlDoc.GetElementsByTagName("Items"))
            {
                foreach (XmlNode xmlNode2 in xmlNode1.ChildNodes)
                {

                    int catID = Convert.ToInt32(xmlNode2.Attributes["id"].Value);
                    string catName = xmlNode2.Attributes["name"].Value.ToString().Trim();

                    statusStrip1.Invoke(new UpdateUI(UpdateUIStatusText), "Loading Categories in " + catName);
                    ItemCategory ic = db.ItemCategories.SingleOrDefault(p => p.ItemCategoryID == catID);
                    if (ic == null)
                    {
                        ic = new ItemCategory();
                        ic.ItemCategoryID = catID;
                        ic.CategoryName = catName;
                        db.ItemCategories.InsertOnSubmit(ic);
                    }
                    else if (!ic.CategoryName.Equals(catName))
                    {
                        ic.CategoryName = catName;
                    }
                    foreach (XmlNode xmlNode3 in xmlNode2.ChildNodes)
                    {
                        int subId = Convert.ToInt32(xmlNode3.Attributes["id"].Value);
                        string subName = xmlNode3.InnerText.Trim();
                        ItemSubCategory isc = db.ItemSubCategories.SingleOrDefault(p => p.ItemSubCat_ID == subId);
                        if (isc == null)
                        {
                            isc = new ItemSubCategory();
                            isc.ItemSubCat_ID = subId;
                            isc.Name = subName;
                            isc.ItemCategory = ic;
                            db.ItemSubCategories.InsertOnSubmit(isc);
                        }
                        else if (!isc.Name.Equals(subName))
                        {
                            isc.Name = subName;
                        }
                    }
                }
            }
            db.SubmitChanges();
            statusStrip1.Invoke(new UpdateUI(UpdateUIStatusText), "Categories Loaded");
            statusStrip1.Invoke(new UpdateUIFinish(UpdateUIFinished));
        }
 partial void DeleteItemSubCategory(ItemSubCategory instance);
 partial void InsertItemSubCategory(ItemSubCategory instance);
 partial void UpdateItemSubCategory(ItemSubCategory instance);
		private void detach_ItemSubCategories(ItemSubCategory entity)
		{
			this.SendPropertyChanging();
			entity.ItemCategory = null;
		}