예제 #1
0
        private string GetCategoryNameFromDBInternal(Int64 categoryId)
        {
            string usedDB = "chosenstuff.sqlite";

            CatShort[] NewCategory;
            using (var checkingCatExist = new SQLite.SQLiteConnection(Path.Combine(WorkingInetAndSQL.destinationPath, usedDB), true))
            {
                var query = checkingCatExist.Table <CatShort>().Where(v => v.ServerID == categoryId);
                if (query.FirstOrDefault() != null)
                {
                    NewCategory = query.ToArray <CatShort>();
                }
                else
                {
                    NewCategory = new CatShort[1];
                    string qu = res.GetString(Resource.String.Unknown_category);
                    NewCategory[0]      = new CatShort();
                    NewCategory[0].Name = res.GetString(Resource.String.Unknown_category);
                    ;
                }
                //List<EventsShort> queryList = query.ToList<EventsShort>();
            }

            return(NewCategory[0].Name);
        }
예제 #2
0
        public static bool SavingCategory(CategoryShort[] categoryForSaving)
        {
            bool   categorySaved       = false;
            bool   categoryAlreadyInDB = false;
            string usedDB = "chosenstuff.sqlite";

            for (int i = 0; i < categoryForSaving.Length; i++)
            {
                if (categoryForSaving[i] != null && categoryForSaving[i].Name != null)
                {
                    //Проверка, нет ли уже такой записи
                    using (var checkingEventExist = new SQLite.SQLiteConnection(Path.Combine(WorkingInetAndSQL.destinationPath, usedDB), true))
                    {
                        var idOfCategory = categoryForSaving[i].Id;
                        var query        = checkingEventExist.Table <CatShort>().Where(v => v.CatID == idOfCategory);
                        if (query.FirstOrDefault() != null)
                        {
                            categoryAlreadyInDB = true; return(categoryAlreadyInDB);
                        }
                    }

                    //Если данное событие отсутствует в базе данных, то:
                    if (!categoryAlreadyInDB)
                    {
                        CatShort curCat;
                        curCat = new CatShort {
                            ServerID = categoryForSaving[i].Id, Name = categoryForSaving[i].Name
                        };

                        //SYNCHRONOUS is Simpler
                        using (var db = new SQLite.SQLiteConnection(Path.Combine(WorkingInetAndSQL.destinationPath, usedDB), true))
                        {
                            //db.CreateTable<CatShort>();
                            db.Insert(curCat);
                            categorySaved = true;
                        }
                    }
                }
            }
            return(categorySaved);
        }