Пример #1
0
        /// <summary>
        /// category context menu add click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CategoryContextMenuAdd_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new EditCategoryName(this);

            if (true != dialog.ShowDialog())
            {
                return;
            }
            using (var table = new CategoriesTable(this._profileDatabase)) {
                var model = new CategoryModel()
                {
                    DisplayName = dialog.DisplayName,
                    RowOrder    = this._categoryList.Count,
                };
                model.DisplayName = dialog.DisplayName;
                model.RowOrder    = this._categoryList.Count;
                model.Id          = table.Insert(model);
                if (model.Id < 0)
                {
                    AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToInsert, "category"));
                    return;
                }
                this._categoryList.Add(model);
            }
        }
Пример #2
0
        public ProductCategory GetProductCategory(string code)
        {
            ProductCategory result = null;
            var             batch  = new BatchSql();

            batch.Append(CategoriesTable.Select().Where(CategoriesTable.ColumnsQualified.Code, code));
            batch.Append(ProductsTable.Select().Add("\r\nWHERE SKU in (SELECT SKU FROM Categories_Products WHERE Categories_Products.CategoryCode=@p0)"));


            var cmd = batch.BuildCommand(connectionStringName);

            using (var rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
            {
                if (rdr.Read())
                {
                    result = LoadProductCategory(rdr);

                    if (result != null)
                    {
                        result.Products = new List <Product>();
                        if (rdr.NextResult())
                        {
                            while (rdr.Read())
                            {
                                result.Products.Add(LoadProduct(rdr));
                            }
                        }
                    }
                }
            }
            return(result);
        }
        public ActionResult Update(CategoriesTable categorytable)
        {
            var seo = Seo.Seo.Translate(categorytable.CategoryName);

            _modelCategory.Update(categorytable.CategoryId, categorytable.CategoryName, seo);
            return(RedirectToAction("index", "allcategory"));
        }
Пример #4
0
 /// <summary>
 /// show category list
 /// </summary>
 private void ShowCategoryList()
 {
     using (var table = new CategoriesTable(this._profileDatabase)) {
         table.SelectAll();
         while (table.Read())
         {
             this._categoryList.Add(new CategoryModel(table));
         }
     }
 }
Пример #5
0
        public ApplicationDbContext(DbContextOptions options) : base(options)
        {
            CategoriesTable.Add(new Category {
                Description = "Sci-fi"
            });
            CategoriesTable.Add(new Category {
                Description = "History"
            });

            AuthorizationLevelsTable.Add(new AuthorizationLevel {
                Name = "Admin"
            });
            AuthorizationLevelsTable.Add(new AuthorizationLevel {
                Name = "Librarian"
            });
            AuthorizationLevelsTable.Add(new AuthorizationLevel {
                Name = "User"
            });
            SaveChanges();
            var librarian = AuthorizationLevelsTable.Where(x => x.Name == "Librarian").FirstOrDefault();
            var user      = AuthorizationLevelsTable.Where(x => x.Name == "User").FirstOrDefault();

            user.WhoHasTheLevel.Add(new Account {
                Name = "Alice"
            });
            user.WhoHasTheLevel.Add(new Account {
                Name = "Bob"
            });
            user.WhoHasTheLevel.Add(new Account {
                Name = "Cecilia"
            });
            SaveChanges();

            var servadac = new Book {
                Title = "Hector Servadac", WhenLent = DateTime.Now
            };
            var alice = AccountsTable.Where(x => x.Name == "Alice").FirstOrDefault();

            alice.BorrowedBooks.Add(servadac);
            SaveChanges();

            var scifi = CategoriesTable.Where(x => x.Description == "Sci-fi").FirstOrDefault();

            var now      = DateTime.Now;
            var catEvent = new CategorizationEvent {
                When = now
            };

            scifi.Events.Add(catEvent);
            servadac.Categorized.Add(catEvent);
            SaveChanges();
        }
Пример #6
0
        public IList <ProductCategory> GetProductCategories()
        {
            var sql = CategoriesTable.Select();
            var cmd = sql.BuildCommand();
            List <ProductCategory> result = new List <ProductCategory>();

            using (var rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
            {
                while (rdr.Read())
                {
                    result.Add(LoadProductCategory(rdr));
                }
            }
            return(result);
        }
Пример #7
0
        private void Create_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog {
                FileName     = "profile.db",
                Filter       = "db ファイル|*.db",
                FilterIndex  = 0,
                AddExtension = true
            };

            if (true != dialog.ShowDialog())
            {
                return;
            }
            var profile = new FileOperator(dialog.FileName);

            if (this.IsRegisterProfile(profile.FilePath))
            {
                return;
            }
            profile.Delete();
            using (var database = new ProfileDatabase(profile.FilePath)) {
                try {
                    database.SetPassWord(ProfileDatabase.Password);
                    database.Open();
                    database.BeginTrans();
                    if (database.ExecuteNonQuery(CategoriesTable.CreateTable()) < 0)
                    {
                        AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToCreate, "categories table"));
                        return;
                    }
                    if (database.ExecuteNonQuery(ItemsTable.CreateTable()) < 0)
                    {
                        AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToCreate, "items table"));
                        return;
                    }
                    database.CommitTrans();
                } catch (Exception ex) {
                    AppCommon.ShowErrorMsg(ex.Message);
                } finally {
                    database.RollbackTrans();
                }
            }
            if (this.InsertProfile(profile))
            {
                this.cProfileList.DataContext = this._model;
            }
        }
Пример #8
0
        /// <summary>
        /// category list key down
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CategoryList_KeyDown(object sender, KeyEventArgs e)
        {
            var  selectedIndex = this.cCategoryList.SelectedIndex;
            bool updateOrder   = false;

            if (Key.U == e.Key && this.IsModifierPressed(ModifierKeys.Shift) && this.IsModifierPressed(ModifierKeys.Control))
            {
                if (selectedIndex <= 0)
                {
                    return;
                }
                var model = this._categoryList[selectedIndex];
                this._categoryList.Remove(model);
                selectedIndex--;
                this._categoryList.Insert(selectedIndex, model);
                updateOrder = true;
                e.Handled   = true;
            }
            else if (Key.D == e.Key && this.IsModifierPressed(ModifierKeys.Shift) && this.IsModifierPressed(ModifierKeys.Control))
            {
                if (-1 == selectedIndex || this._categoryList.Count - 1 <= selectedIndex)
                {
                    return;
                }
                var model = this._categoryList[selectedIndex];
                this._categoryList.Remove(model);
                selectedIndex++;
                this._categoryList.Insert(selectedIndex, model);
                updateOrder = true;
                e.Handled   = true;
            }
            if (updateOrder)
            {
                using (var table = new CategoriesTable(this._profileDatabase)) {
                    if (table.UpdateRowOrdersByIds(this._categoryList) == 0)
                    {
                        AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToUpdate, "category"));
                    }
                    else
                    {
                        this.cCategoryList.SelectedIndex = selectedIndex;
                    }
                }
            }
        }
Пример #9
0
        /// <summary>
        /// category context menu edit click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CategoryContextMenuEdit_Click(object sender, RoutedEventArgs e)
        {
            if (!((this._categoryMenu.Tag as ListViewItem)?.DataContext is CategoryModel model))
            {
                return;
            }
            var dialog = new EditCategoryName(this, model);

            if (true != dialog.ShowDialog())
            {
                return;
            }
            using (var table = new CategoriesTable(this._profileDatabase)) {
                model.DisplayName = dialog.DisplayName;
                if (0 == table.UpdateById(model))
                {
                    AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToUpdate, "category"));
                    return;
                }
            }
        }
Пример #10
0
        /// <summary>
        /// category context menu delete click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CategoryContextMenuDelete_Click(object sender, RoutedEventArgs e)
        {
            if (!((this._categoryMenu.Tag as ListViewItem)?.DataContext is CategoryModel model))
            {
                return;
            }
            var dialog = new CategoryDeleteConfirm(this, model, this._categoryList);

            if (true != dialog.ShowDialog())
            {
                return;
            }

            try {
                this._profileDatabase.Open();
                this._profileDatabase.BeginTrans();

                using (var categoriesTable = new CategoriesTable(this._profileDatabase))
                    using (var itemsTable = new ItemsTable(this._profileDatabase)) {
                        if (0 == categoriesTable.DeleteById(model))
                        {
                            AppCommon.ShowErrorMsg(string.Format(ErrorMsg.FailToDelete, "Category"));
                        }
                        if (-1 == dialog.MoveCategory)
                        {
                            itemsTable.DeleteByCateogyId(model.Id);
                        }
                        else
                        {
                            itemsTable.UpdateCategoryIdByCategoryId(model.Id, dialog.MoveCategory);
                        }
                        this._profileDatabase.CommitTrans();
                    }
                this._categoryList.Remove(model);
            } finally {
                this._profileDatabase.RollbackTrans();
                this._profileDatabase.Close();
            }
        }
Пример #11
0
 public ModelCategory()
 {
     _categoryContext = new FashionSiteContext();
     _categoryTable   = new CategoriesTable();
 }
Пример #12
0
 internal ProductCategory LoadProductCategory(DbDataReader rdr)
 {
     return(new ProductCategory(CategoriesTable.ReadCode(rdr), CategoriesTable.ReadTitle(rdr)));
 }
Пример #13
0
 internal CategoryModel(CategoriesTable table)
 {
     this.Id          = table.Id;
     this.DisplayName = table.DisplayName;
     this.RowOrder    = table.RowOrder;
 }
Пример #14
0
        private async void generateGraph_onTapped(object sender, TappedRoutedEventArgs e)
        {
            // check whether DB file already there or not..
            var check = await App.DoesFileExistAsync("chartdb.db");

            if (!check)
            {
                CreateDatabase();
            }

            if (await isValidData())
            {
                #region activity time => integer converter

                var a = cb_activityTime.SelectedIndex;
                switch (a)
                {
                case 0:
                    activityTime = 0;
                    break;

                case 1:
                    activityTime = 15;
                    break;

                case 2:
                    activityTime = 30;
                    break;

                case 3:
                    activityTime = 45;
                    break;

                case 4:
                    activityTime = 60;
                    break;

                case 5:
                    activityTime = 75;
                    break;

                case 6:
                    activityTime = 90;
                    break;

                case 7:
                    activityTime = 105;
                    break;

                case 8:
                    activityTime = 120;
                    break;

                case 9:
                    activityTime = 135;
                    break;

                case 10:
                    activityTime = 150;
                    break;

                case 11:
                    activityTime = 165;
                    break;

                case 12:
                    activityTime = 180;
                    break;
                }

                #endregion

                // connect to DB and insert current values in DB

                SQLiteAsyncConnection con  = new SQLiteAsyncConnection("chartdb.db");
                CategoriesTable       data = new CategoriesTable
                {
                    username       = App.userName,
                    weight         = converted_weight,
                    blood_pressure = tb_boodPressure.Text,
                    oxygen_level   = converted_oxyzenLevel,
                    glucose_level  = converted_glucoze,
                    bmi            = double.Parse(converted_BMI.ToString()),
                    pedometer      = activityTime,
                    //pedometer = int.Parse(cb_activityTime.SelectedItem.ToString()),
                    date = dateToInsert
                };
                await con.InsertAsync(data);

                generateTable();
                await CreateChartAsync();

                SQLiteConnectionPool.Shared.Reset();

                tb_weight.Text       = string.Empty;
                tb_boodPressure.Text = string.Empty;
                tb_oxyzenLevel.Text  = string.Empty;
                tb_glucozeLevel.Text = string.Empty;
                tb_BMI.Text          = string.Empty;
            }
            //else
            //{
            //    MessageDialog ms = new MessageDialog("Data you entered is not in it's range.", "Drive2Wellness");
            //    await ms.ShowAsync();
            //}
        }