// Here we load all the nodes on the left from xml file.
        private void InitializetionDataCategories()
        {
            var xDoc     = XDocument.Load(MapSuiteSampleHelper.GetValueFromConfiguration("CategoryFilePath"));
            var elements = from category in xDoc.Element("DemographicMap").Elements("Category")
                           select category;

            foreach (var element in elements)
            {
                DataCategoryViewModel category = null;
                string title = element.Attribute("name").Value;
                category               = title != "Custom Data" ? new DataCategoryViewModel() : new CustomDataCategoryViewModel();
                category.Title         = title;
                category.CategoryImage = new BitmapImage(new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}", "pack://application:,,,/MapSuiteUSDemographicMap;component/", element.Attribute("icon").Value), UriKind.RelativeOrAbsolute));

                foreach (var item in element.Elements("item"))
                {
                    ColumnViewModel categoryItem = new ColumnViewModel();
                    categoryItem.Parent      = category;
                    categoryItem.ColumnName  = item.Element("columnName").Value;
                    categoryItem.Alias       = item.Element("alias").Value;
                    categoryItem.LegendTitle = item.Element("legendTitle").Value;
                    category.Columns.Add(categoryItem);
                }
                category.CanUsePieView = category.Columns.Count >= 2;
                CategoryList.Add(category);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method to Get the Product Structures(Hierachie) to fill the Category and Subcategory Combobox
        /// </summary>
        public void GetProductStructure()
        {
            if (CategoryList.Count() > 0)
            {
                CategoryList.Clear();
            }

            if (SubCategoryList.Count() > 0)
            {
                SubCategoryList.Clear();
            }

            using (var db = new DataSmartDBContext())
            {
                var structure = db.ProductStructure.ToList();

                if (structure != null)
                {
                    foreach (var d in structure)
                    {
                        CategoryList.Add(d.Category_1);
                        SubCategoryList.Add(d.Category_2);
                    }
                    CategoryList    = CategoryList.Distinct().ToList();
                    SubCategoryList = SubCategoryList.Distinct().ToList();
                }
            }
        }
Exemplo n.º 3
0
        public async Task ExecuteLoadCategoriesAsync()
        {
            try
            {
                IsBusy = true;

                CategoryList.Clear();

                List <Category> listCat = _userSettings.GetCategoriesLocal();

                if (listCat == null)
                {
                    listCat = await _expenseTrackerService.GetCategoryListAsync();
                }

                foreach (Category cat in listCat)
                {
                    CategoryList.Add(cat.Name);
                }
            }
            catch (Exception ex)
            {
                await base.ShowErrorMessageAsync("Error getting category list : " + ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
 /// <summary>
 /// Database loaded message handler, load the database content
 /// </summary>
 /// <param name="obj"></param>
 void DatabaseLoadedHandler(DatabaseLoadedMessage obj)
 {
     CategoryList.Clear();
     foreach (var cat in obj.DatabaseModel.Categories.Select(x => x.Name))
     {
         CategoryList.Add(cat);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Загрузить категории
        /// </summary>
        /// <returns></returns>
        public CategoryList LoadCategories()
        {
            if (ds != null)
            {
                ds.Dispose();
            }
            ds = new DataSet();
            CategoryList list = null;

            using (SQLiteCommand mycommand = new SQLiteCommand(conn))
            {
                mycommand.CommandText = "select * from categories";
                da = new SQLiteDataAdapter();
                da.SelectCommand = mycommand;
                System.Data.SQLite.SQLiteCommandBuilder cb = new System.Data.SQLite.SQLiteCommandBuilder(da);
                da.Fill(ds, "categories");
                foreach (DataRow row in ds.Tables["categories"].Rows)
                {
                    string categories_xml = row["categories_xml"].ToString();
                    if (!string.IsNullOrEmpty(categories_xml))
                    {
                        try
                        {
                            var reader = new StringReader(categories_xml);
                            var sr     = new XmlSerializer(typeof(CategoryList));
                            list = (CategoryList)sr.Deserialize(reader);
                            foreach (Category category in list)
                            {
                                category.SetOwner(list);
                            }
                            list.Reorder();
                            return(list);//(CategoryList)sr.Deserialize(reader);
                        }
                        catch
                        { }
                        break;
                    }
                }
            }
            if (list == null)
            {
                list = new CategoryList();
                list.Add(new Category()
                {
                    Name = "Default"
                });
            }
            foreach (Category category in list)
            {
                category.SetOwner(list);
            }
            list.Reorder();

            return(list);
        }
Exemplo n.º 6
0
        private void GetAllCategories()
        {
            var allCategories = GetCategoryRepo().GetAllCategories();

            foreach (var category in allCategories)
            {
                CategoryList.Add(new Category {
                    Id = category.Id, Name = category.Name
                });
            }
        }
Exemplo n.º 7
0
        private IEnumerable <PageData> FindPages(PageListBlock currentBlock, Category category)
        {
            var pageCriteriaQueryService = ServiceLocator.Current.GetInstance <IPageCriteriaQueryService>();
            var contentProviderManager   = ServiceLocator.Current.GetInstance <IContentProviderManager>();
            var contentLoader            = ServiceLocator.Current.GetInstance <IContentLoader>();

            var      pageRouteHelper = ServiceLocator.Current.GetInstance <IPageRouteHelper>();
            PageData currentPage     = pageRouteHelper.Page ?? contentLoader.Get <PageData>(ContentReference.StartPage);

            var listRoot = currentBlock.Root ?? currentPage.ContentLink.ToPageReference();

            IEnumerable <PageData> pages;


            if (currentBlock.Recursive)
            {
                if (currentBlock.PageTypeFilter != null)
                {
                    pages = FindPagesByPageType(listRoot, true, currentBlock.PageTypeFilter.ID);
                }
                else
                {
                    pages = GetAll <PageData>(listRoot);
                }
            }
            else
            {
                if (currentBlock.PageTypeFilter != null)
                {
                    pages = contentLoader.GetChildren <PageData>(listRoot)
                            .Where(p => p.PageTypeID == currentBlock.PageTypeFilter.ID);
                }
                else
                {
                    pages = contentLoader.GetChildren <PageData>(listRoot);
                }
            }

            if (currentBlock.CategoryFilter != null && currentBlock.CategoryFilter.Any())
            {
                pages = pages.Where(x => x.Category.Intersect(currentBlock.CategoryFilter).Any());
            }
            else if (category != null)
            {
                var catlist = new CategoryList();
                catlist.Add(category.ID);

                pages = pages.Where(x => x.Category.Intersect(catlist).Any());
            }


            pages = pages.Where(p => p.PageTypeName == typeof(BookPage).GetPageType().Name).ToList();
            return(pages);
        }
Exemplo n.º 8
0
 public void SetCategoryItems(IEnumerable <Category> categories)
 {
     foreach (var category in categories)
     {
         CategoryList.Add(new SelectListItem()
         {
             Value = category.CategoryID.ToString(),
             Text  = category.CategoryName
         });
     }
 }
Exemplo n.º 9
0
 // The available filter categories
 void AddCategoriesToList()
 {
     string[] categories = { "Food / Drink", "Health", "Stationary", "Sports", "Misc" };
     foreach (string category in categories)
     {
         CategoryList.Add(new CustomPin()
         {
             Category = category,
             Address  = new ImageService().CategoryToImage(category)
         });
     }
 }
Exemplo n.º 10
0
 //populates combo box full of categories
 private void addEquationCategories()
 {
     CategoryList.Add("Cylindrical Coordinates");
     CategoryList.Add("Spherical Coordinates");
     CategoryList.Add("Trigonometric Identities");
     CategoryList.Add("Linear Algebra");
     CategoryList.Add("Calculus Laws");
     CategoryList.Add("Mathematical Tools");
     CategoryList.Add("Series Expansions");
     CategoryList.Add("Quantum Basics");
     SelectedCategory = 0;
 }
Exemplo n.º 11
0
        internal void SslBlackList(FileInfo mfile)
        {
            string path = Common.GetPath();

            //FileUrl = Common.GetURL();// Creates a dictionary of Filename and URL from which it got downloaded
            using (var rd = new StreamReader(path + mfile.ToString()))
            {
                List <KeyValuePair <string, List <string> > > InfoList = new List <KeyValuePair <string, List <string> > >();
                string fieldC        = "category";
                string fieldD        = "description";
                string fieldU        = "url";
                string fieldT        = "date";
                string IP            = "";
                string IpDescription = "";
                string category      = "";
                string IpDate        = "";
                string URL           = "";
                string line1         = rd.ReadLine();
                string line2         = rd.ReadLine();
                string line3         = rd.ReadLine();
                while (!rd.EndOfStream)
                {
                    string   line = rd.ReadLine();
                    string[] info = line.Split(',');
                    IpDate = line3.Split(':')[1];
                    if (info.Count() == 3)
                    {
                        IP            = info[0];
                        IpDescription = info[2];
                        category      = "C & C";
                        URL           = "https://sslbl.abuse.ch";
                        DescriptionList.Add(IpDescription);
                        CategoryList.Add(category);
                        UrlList.Add(URL);
                        IpDateList.Add(IpDate);
                        InfoList.Add(new KeyValuePair <string, List <string> >(fieldC, CategoryList));
                        InfoList.Add(new KeyValuePair <string, List <string> >(fieldD, DescriptionList));
                        InfoList.Add(new KeyValuePair <string, List <string> >(fieldU, UrlList));
                        InfoList.Add(new KeyValuePair <string, List <string> >(fieldT, IpDateList));
                        if (!BlackListDB.ContainsKey(IP))
                        {
                            BlackListDB.Add(IP, InfoList);
                            totalip.Add(IP);
                        }
                        CategoryList    = new List <string>();
                        DescriptionList = new List <string>();
                        UrlList         = new List <string>();
                        InfoList        = new List <KeyValuePair <string, List <string> > >();
                        IpDateList      = new List <string>();
                    }
                }
            }
        }
        public void Add()
        {
            var newEntity = new CategoryEntity()
            {
                Deleted     = false,
                Description = "",
                CategoryId  = -1
            };

            CategoryList.Add(newEntity);
            CategoryList = new List <CategoryEntity>(_categoryList);
        }
        public void EditCategory(object item)
        {
            if (CanEditCategory(null))
            {
                if (SelectedCategory != null)
                {
                    CategoryData categoryItem = new CategoryData()
                    {
                        ProductCategoryID = SelectedCategory.ProductCategoryID,
                        Name     = CategoryName,
                        IsActive = CategoryIsActive
                    };
                    ProductCategory updatedProductCategory = CategoriesClient.UpdateCategory(categoryItem);

                    CategoryData categoryInList = CategoryList.FirstOrDefault(cat => cat.ProductCategoryID == updatedProductCategory.ProductCategoryID);
                    categoryInList.Name     = updatedProductCategory.Name;
                    categoryInList.IsActive = updatedProductCategory.IsActive;
                }
                else
                {
                    try
                    {
                        CategoryData categoryItem = new CategoryData()
                        {
                            ProductCategoryID = 0,
                            Name     = CategoryName,
                            IsActive = CategoryIsActive
                        };
                        ProductCategory updatedProductCategory = CategoriesClient.UpdateCategory(categoryItem);

                        if (updatedProductCategory != null)
                        {
                            CategoryList.Add(new CategoryData()
                            {
                                ProductCategoryID = updatedProductCategory.ProductCategoryID,
                                Name         = updatedProductCategory.Name,
                                IsActive     = updatedProductCategory.IsActive,
                                ProductCount = updatedProductCategory.ProductCount
                            });
                        }
                        else
                        {
                            MessageBox.Show("Save failed.");
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }
        }
Exemplo n.º 14
0
 public static void CreateCategories()
 {
     if (File.Exists("categories.txt"))
     {
         XDocument.Load("categories.txt").Descendants("Category").Select(p => new
         {
             categoryName = p.Element("CategoryName").Value,
         }).ToList().ForEach(p =>
         {
             CategoryList.Add(new Category(p.categoryName));
         });
     }
 }
Exemplo n.º 15
0
        public Dictionary <string, List <KeyValuePair <string, List <string> > > > BadIpMain()
        {
            List <string> AllIP = new List <string>();
            List <KeyValuePair <string, List <string> > > InfoList = new List <KeyValuePair <string, List <string> > >();
            string fieldC        = "category";
            string fieldD        = "description";
            string fieldU        = "url";
            string fieldT        = "date";
            string IP            = "";
            string IpDescription = "";
            string category      = "";
            string IpDate        = "";
            string URL           = "";
            Dictionary <string, string> CatDesc = new Dictionary <string, string>();

            CatDesc = GetCatDesc();
            foreach (string cat in CatDesc.Keys)
            {
                AllIP = Get("https://www.badips.com/get/list/" + cat + "/0");
                foreach (string ip in AllIP)
                {
                    IP            = ip;
                    category      = cat;
                    IpDescription = CatDesc[cat];
                    URL           = "https://www.badips.com/get/list/" + cat + "/0";
                    IpDate        = "No Date Provided";
                    DescriptionList.Add(IpDescription);
                    CategoryList.Add(category);
                    UrlList.Add(URL);
                    IpDateList.Add(IpDate);
                    InfoList.Add(new KeyValuePair <string, List <string> >(fieldC, CategoryList));
                    InfoList.Add(new KeyValuePair <string, List <string> >(fieldD, DescriptionList));
                    InfoList.Add(new KeyValuePair <string, List <string> >(fieldU, UrlList));
                    InfoList.Add(new KeyValuePair <string, List <string> >(fieldT, IpDateList));
                    if (IP != "")
                    {
                        if (!BlackListDB.ContainsKey(IP))
                        {
                            totalip.Add(IP);
                            BlackListDB.Add(IP, InfoList);
                        }
                    }
                    CategoryList    = new List <string>();
                    DescriptionList = new List <string>();
                    UrlList         = new List <string>();
                    InfoList        = new List <KeyValuePair <string, List <string> > >();
                    IpDateList      = new List <string>();
                }
            }
            return(BlackListDB);
        }
Exemplo n.º 16
0
 public ExpenseManager()
 {
     Categories.Add(new Category()
     {
         Name = "Étel", IsLuxury = false
     });
     Categories.Add(new Category()
     {
         Name = "Utazás", IsLuxury = false
     });
     Categories.Add(new Category()
     {
         Name = "Rezsi", IsLuxury = false
     });
     Categories.Add(new Category()
     {
         Name = "Extrák", IsLuxury = true
     });
     Categories.Add(new Category()
     {
         Name = "Bevétel", IsLuxury = false
     });
 }
Exemplo n.º 17
0
        public CategoryList GetSectionsByNames(List <string> categoryNames)
        {
            var sectionCategories = _categoryRepository.GetRoot();
            var list = new CategoryList();

            foreach (var cat in categoryNames)
            {
                var foundCategory = sectionCategories.FindChild(cat);
                if (foundCategory != null)
                {
                    list.Add(foundCategory.ID);
                }
            }
            return(list);
        }
Exemplo n.º 18
0
        private void GenerateComboBoxes()
        {
            CategoryList.Add("Engine");
            CategoryList.Add("Tyres");
            CategoryList.Add("Paint");
            CategoryList.Add("Doors");

            TypeList.Add("Car");
            TypeList.Add("Truck");
            TypeList.Add("Bus");

            PriorityList.Add("1");
            PriorityList.Add("2");
            PriorityList.Add("3");
        }
Exemplo n.º 19
0
        public async void RefreshAsync()
        {
            while (true)
            {
                try
                {
                    using (var httpClient = new HttpClient())
                    {
                        FoodClient foodClient = new FoodClient(httpClient);
                        Task <ICollection <Food> > allFoodTask = foodClient.GetAllFoodAsync();
                        FoodList.Clear();
                        foreach (var item in await allFoodTask)
                        {
                            FoodList.Add(item);
                        }

                        CategoryClient categoryClient = new CategoryClient(httpClient);
                        Task <ICollection <Category> > allCategoryTask = categoryClient.GetAllCategoryAsync();
                        CategoryList.Clear();
                        foreach (var item in await allCategoryTask)
                        {
                            CategoryList.Add(item);
                        }

                        StorageClient storageClient = new StorageClient(httpClient);
                        Task <ICollection <Storage> > allStorageTask = storageClient.GetAllStorageAsync();
                        StorageList.Clear();
                        foreach (var item in await allStorageTask)
                        {
                            StorageList.Add(item);
                        }

                        SlotClient slotClient = new SlotClient(httpClient);
                        Task <ICollection <Slot> > allSlotTask = slotClient.GetAllSlotAsync();
                        SlotList.Clear();
                        foreach (var item in await allSlotTask)
                        {
                            SlotList.Add(item);
                        }
                    }
                    return;
                }
                catch
                {
                    Thread.Sleep(500);
                }
            }
        }
Exemplo n.º 20
0
        public async void InitCategory()
        {
            try
            {
                string jsonResult = await LinqHelper.GetAllQueryData("BlockQueryCategory");

                var result = JsonConvert.DeserializeObject <JsonResultTemplate <BlockQueryCategory> >(jsonResult);
                if (result.ResultCode == (int)ResultCodeType.操作成功)
                {
                    result.Data.ToList().ForEach(item => { CategoryList.Add(item); });
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Exemplo n.º 21
0
        protected override async Task OnInitializedAsync()
        {
            ProjectViewModels = await ProjectDataService.GetProjectsAsync();


            //Not a fan of this nested logic
            //What I'm trying to do is collect every distinct category of a given type of CategoryTypeFilter
            foreach (ProjectViewModel projectVM in ProjectViewModels)
            {
                foreach (Category category in projectVM.Categories)
                {
                    if (!CategoryList.Contains <Category>(category) && category.Type == CategoryTypeFilter)
                    {
                        CategoryList.Add(category);
                    }
                }
            }
        }
        /// <summary>
        /// Add a new category
        /// </summary>
        private void AddCategory()
        {
            if (string.IsNullOrWhiteSpace(NewCategoryName))
            {
                FormError = "EmptyCategoryName";
                return;
            }
            if (CategoryList.FirstOrDefault(x => x == NewCategoryName) != null)
            {
                FormError = "CategoryExists";
                return;
            }

            databaseRepository.AddCategory(NewCategoryName);
            Messenger.Default.Send(new CategoryAddedMessage(this, NewCategoryName));
            CategoryList.Add(NewCategoryName);
            StopAddCategory();
        }
Exemplo n.º 23
0
        private async Task LoadCategoriesFromDataBase()
        {
            CategoryList.Clear();
            var CategoryModels = await _categoryService.GetCategoriesAsync(App.CurrentUserId);

            CategoryList.Add(new CategoryViewModel(
                                 -1,
                                 App.CurrentUserId,
                                 "No Category",
                                 CategoryTappedCommand
                                 ));

            if (CategoryModels != null)
            {
                foreach (var model in CategoryModels)
                {
                    CategoryList.Add(model.ToViewModel(CategoryTappedCommand));
                }
            }
        }
Exemplo n.º 24
0
        // public methods
        public void AddCategory(Category category, CategoryList list)
        {
            // add new record to database
            string tableName = GetDBTableName(list);
            bool   ok        = DBHelper.Insert(category, tableName);

            if (!ok)
            {
                throw new InvalidOperationException();
            }

            // add to catagory list
            list.Add(category);

            // update item count of new category
            if (list == IngredientCategories)
            {
                IngredientCategories.CountItemsFrom(GroupedIngredients);
            }
        }
Exemplo n.º 25
0
        private void btnNewCategory_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBoxCategory.Text))
            {
                MessageBox.Show("You must fill in the category textfield!");
                return;
            }

            if (Validation.ValidateCategories(textBoxCategory.Text))
            {
                MessageBox.Show("You are trying to add a category that already exists!");
                return;
            }

            Category kategori = new Category(textBoxCategory.Text);

            CategoryList.Add(kategori);
            UpdatecomboBoxCategory();
            UpdatelistBoxCategory();
        }
Exemplo n.º 26
0
        /// <summary>
        /// Sets the CategoryList for XMLHandler
        /// </summary>
        private void SetCategoryList()
        {
            Predicate <Category> catFinder;
            Category             oldCat, newCat;

            // Iterate through the list of Business to get each Category
            foreach (var b in BusinessList)
            {
                // A Business will have n Categories (a given Category may have a unique list of Subcategories)
                foreach (var c in b.CategoryList)
                {
                    catFinder = (Category catToFind) => { return(catToFind.Name == c.Name); };
                    oldCat    = CategoryList.Find(catFinder);

                    // Insert new Category or update the SubcategoryList of a Category already represented in CategoryList
                    if (oldCat == null)
                    {
                        CategoryList.Add(c);
                    }
                    else
                    {
                        newCat      = new Category();
                        newCat.Name = oldCat.Name;

                        foreach (var oldCatSC in oldCat.SubcategoryList)
                        {
                            newCat.SubcategoryList.Add(oldCatSC);
                        }

                        foreach (var sc in c.SubcategoryList)
                        {
                            newCat.SubcategoryList.Add(sc);
                        }

                        CategoryList.Insert(CategoryList.FindIndex(catFinder), newCat);
                        oldCat = null;
                    }
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Fetch CategoryList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public CategoryList Fetch(CategoryCriteria criteria)
        {
            CategoryList item = (CategoryList)Activator.CreateInstance(typeof(CategoryList), true);

            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(item);
            }

            // Fetch Child objects.
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Category_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                    command.Parameters.AddWithValue("@p_DescnHasValue", criteria.DescriptionHasValue);
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                item.Add(new CategoryFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            OnFetched();
            return(item);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Fetch CategoryList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public CategoryList Fetch(CategoryCriteria criteria)
        {
            CategoryList item = (CategoryList)Activator.CreateInstance(typeof(CategoryList), true);

            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(item);
            }

            // Fetch Child objects.
            string commandText = String.Format("SELECT [CategoryId], [Name], [Descn] FROM [dbo].[Category] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                item.Add(new CategoryFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            OnFetched();
            return(item);
        }
Exemplo n.º 29
0
        public async void ExecuteLoadCategories()
        {
            try
            {
                IsBusy = true;

                CategoryList.Clear();

                List <Category> listCat = await _expenseTrackerWebApiService.GetCategoryList();

                foreach (Category cat in listCat)
                {
                    CategoryList.Add(cat.Name);
                }
            }
            catch (Exception ex)
            {
                await base.ShowErrorMessage("Cannot connect to server. " + ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemplo n.º 30
0
 public void AddCategory(Category cat)
 {
     CategoryList.Add(cat);
 }
Exemplo n.º 31
0
        /// <summary>
        /// Загрузить категории
        /// </summary>
        /// <returns></returns>
        public CategoryList LoadCategories()
        {
            var list = new CategoryList();
            if (server == null) return null;
            try
            {
                using (var documentStore = server.OpenClient())
                {
                    var categories = documentStore.Query<Category>();

                    //foreach (Category category in categories)
                    //    documentStore.Delete(category);
                    //documentStore.Commit();

                    if (categories.Count() > 0)
                    {
                        foreach (var category in categories)
                            if (category!=null)
                                list.Add(category);
                    }
                    else
                    {
                        var c = new Category { Name = "Default" };
                        list.Add(c);
                        documentStore.Store(c);
                        documentStore.Commit();
                    }
                    foreach (var category in list)
                        category.SetOwner(list);
                    list.Reorder();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибка выборки категорий из БД." + ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            return list;
        }
Exemplo n.º 32
0
        /// <summary>
        /// Загрузить категории
        /// </summary>
        /// <returns></returns>
        public CategoryList LoadCategories()
        {
            if (ds != null) ds.Dispose();
            ds = new DataSet();
            CategoryList list = null;
            using (SQLiteCommand mycommand = new SQLiteCommand(conn))
            {
                mycommand.CommandText = "select * from categories";
                da = new SQLiteDataAdapter();
                da.SelectCommand = mycommand;
                System.Data.SQLite.SQLiteCommandBuilder cb = new System.Data.SQLite.SQLiteCommandBuilder(da);
                da.Fill(ds, "categories");
                foreach (DataRow row in ds.Tables["categories"].Rows)
                {
                    string categories_xml = row["categories_xml"].ToString();
                    if (!string.IsNullOrEmpty(categories_xml))
                    {
                        try
                        {
                            var reader = new StringReader(categories_xml);
                            var sr = new XmlSerializer(typeof(CategoryList));
                            list = (CategoryList)sr.Deserialize(reader);
                            foreach (Category category in list)
                                category.SetOwner(list);
                            list.Reorder();
                            return list;//(CategoryList)sr.Deserialize(reader);
                        }
                        catch
                        { }
                        break;
                    }
                }
            }
            if (list == null)
            {
                list = new CategoryList();
                list.Add(new Category() { Name = "Default" });
            }
            foreach (Category category in list)
                category.SetOwner(list);
            list.Reorder();

            return list;
        }
        private static void InsertTypeInterval(ServiceReference1.MainClient a,ServiceReference2.StaticClient b, User usr)
        {
            var cat = b.GetAllCategories(usr.UserId);
            var typeTransReason = b.GetAllTypeTransactionReasons(usr.UserId);
            var typeIntervals = b.GetAllTypeIntervals(usr.UserId);
            var recurrenceRules = b.GetAllRecurrenceRules();
            var typeTransactions = b.GetAllTypeTransactions(usr.UserId);

            var catList = new CategoryList();
            cat.ForEach(x => catList.Add(x));

            var typeTransReasonList = new TypeTransactionReasonList();
            typeTransReason.ForEach(x => typeTransReasonList.Add(x));

            var typeTransactionsList = new TypeTransactionList();
            typeTransactions.ForEach(x => typeTransactionsList.Add(x));


            // INSERT //
            var intervals = new TypeIntervalList { new TypeInterval(catList, typeTransReasonList, typeTransactionsList, usr) };
            //intervals[0].RecurrenceRule = staticData.RecurrenceRules.FirstOrDefault(x => x.Name == "RuleDailyEveryDays");


            var found = recurrenceRules.FirstOrDefault(x => x.Name == "RuleDailyEveryDays");
            intervals[0].RecurrenceRuleValue.RecurrenceRule = found;
            intervals[0].RecurrenceRuleValue.RulePartValueList[0].Value = "aaa";
            intervals[0].RecurrenceRuleValue.RulePartValueList[1].Value = "bbb";

            intervals[0].RecurrenceRangeRuleValue.RecurrenceRule = recurrenceRules.FirstOrDefault(x => x.Name == Const.Rule.RuleRangeTotalOcurrences.ToString());
            intervals[0].RecurrenceRangeRuleValue.RulePartValueList[0].Value = "20111111";
            intervals[0].RecurrenceRangeRuleValue.RulePartValueList[1].Value = "234";


            var result = b.SaveTypeIntervals(intervals.ToList());

        }
        private static List<Category> SaveCategories(ServiceReference2.StaticClient b, User usr)
        {
            var allCat = b.GetAllCategories(usr.UserId);
            var allReasons = b.GetAllTypeTransactionReasons(usr.UserId);

            var catList = new CategoryList();
            var reasonList = new TypeTransactionReasonList();

            allReasons.ForEach(x=>reasonList.Add(x));
            var newCat = new Category(usr, reasonList);
            newCat = allCat[2];
            newCat.TypeTransactionReasons[1].IsDeleted = true;
            newCat.TypeTransactionReasons[1].ModifiedDate = DateTime.Now;

            newCat.HasChanges = true;
            newCat.ModifiedDate = DateTime.Now;

            //newCat.Name = "CarTest";

            //if (newCat.TypeTransactionReasons == null)
            //    newCat.TypeTransactionReasons = new List<TypeTransactionReason>();

            //newCat.TypeTransactionReasons.Add(allReasons[0]);
            //newCat.TypeTransactionReasons.Add(allReasons[1]);

            //var transReasonList = new List<TypeTransactionReason>();
            //var transReason = new TypeTransactionReason(usr);
            //transReason.Name = "CarTest";


            catList.Add(newCat);

            catList.OptimizeOnTopLevel();

            var result = b.SaveCategories(catList.ToList());
            //var arrC = st.ToList();

            //var c = b.SaveCategories(st.Categories);

            return result;
        }