コード例 #1
0
        public List <StoreItemCategoryObject> GetStoreItemCategoryObjects(int?itemsPerPage, int?pageNumber)
        {
            try
            {
                List <StoreItemCategory> storeItemCategoryEntityList;
                if ((itemsPerPage != null && itemsPerPage > 0) && (pageNumber != null && pageNumber >= 0))
                {
                    var tpageNumber = (int)pageNumber;
                    var tsize       = (int)itemsPerPage;
                    storeItemCategoryEntityList = _repository.GetWithPaging(m => m.StoreItemCategoryId, tpageNumber, tsize).ToList();
                }

                else
                {
                    storeItemCategoryEntityList = _repository.GetAll().ToList();
                }

                if (!storeItemCategoryEntityList.Any())
                {
                    return(new List <StoreItemCategoryObject>());
                }
                var storeItemCategoryObjList = new List <StoreItemCategoryObject>();
                storeItemCategoryEntityList.ForEach(m =>
                {
                    var storeItemCategoryObject = ModelCrossMapper.Map <StoreItemCategory, StoreItemCategoryObject>(m);
                    if (storeItemCategoryObject != null && storeItemCategoryObject.StoreItemCategoryId > 0)
                    {
                        if (storeItemCategoryObject.ParentCategoryId > 0)
                        {
                            var parentCategory = new StoreItemCategory();
                            parentCategory     = storeItemCategoryEntityList.Find(x => x.StoreItemCategoryId == storeItemCategoryObject.ParentCategoryId);
                            if (parentCategory != null && parentCategory.StoreItemCategoryId > 0)
                            {
                                storeItemCategoryObject.ParentName = parentCategory.Name;
                            }
                            else
                            {
                                parentCategory = _repository.GetById(storeItemCategoryObject.ParentCategoryId);
                                if (parentCategory != null && parentCategory.StoreItemCategoryId > 0)
                                {
                                    storeItemCategoryObject.ParentName = parentCategory.Name;
                                }
                            }
                        }
                        else
                        {
                            storeItemCategoryObject.ParentName = " ";
                        }
                        storeItemCategoryObjList.Add(storeItemCategoryObject);
                    }
                });

                return(storeItemCategoryObjList);
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(new List <StoreItemCategoryObject>());
            }
        }
コード例 #2
0
        private void CboItemCategories_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //When the item category is changed, update the tax labels and calculated values accordingly.
            var selectedCategoryName = cboItemCategories.SelectedItem.ToString();

            //Use a Linq query to retrieve the Category that matches the name.
            StoreItemCategory selectedCategory = storeItemCategoryHelper.GetStoreItemCategoryByName(selectedCategoryName, storeItemCategories);
        }
コード例 #3
0
        private IList <StoreItem> RetrieveAvailableStoreItems(StoreItemCategory category)
        {
            switch (category)
            {
            case StoreItemCategory.Aircrafts: return(GlobalModel.Store.Aircrafts);

            case StoreItemCategory.Gold: return(GlobalModel.Store.Gold);

            case StoreItemCategory.Corn: return(GlobalModel.Store.Corn);

            default:
                Log.Error("Failed to retrieve store items for category {0}.", EnumUtility.GetName(category));
                return(new List <StoreItem>());
            }
        }
コード例 #4
0
        private void BtnAddItem_Click(object sender, RoutedEventArgs e)
        {
            int     enteredQuantity;
            decimal enteredPrice;

            //Check all StoreItem fields to ensure there are valid values in each.
            if (cboItemCategories.SelectedItem == null) //ItemCategory
            {
                MessageBox.Show("Please select an Item Category.");
            }
            else if (txtItemDescription.Text == null) //ItemDescription
            {
                MessageBox.Show("Please enter an item description.");
            }
            else if (!int.TryParse(txtQuantity.Text, out enteredQuantity)) //Quantity
            {
                MessageBox.Show("Please enter a valid whole number Quantity. Entered value: " + txtQuantity.Text);
            }
            else if (!decimal.TryParse(txtPrice.Text, out enteredPrice)) //Price
            {
                MessageBox.Show("Please enter a valid Price. Entered value: " + txtPrice.Text);
            }
            else //If all fields check out, add the item to the StoreItems list, view, and update the receipt.
            {
                StoreItemCategory selectedCategory = storeItemCategoryHelper.GetStoreItemCategoryByName(cboItemCategories.SelectedItem.ToString(), storeItemCategories);

                StoreItem newItem = new StoreItem()
                {
                    Category    = selectedCategory,
                    Description = txtItemDescription.Text.Trim(),
                    Quantity    = enteredQuantity,
                    Price       = enteredPrice,
                    AddedOn     = DateTime.Now
                };

                storeItems.Add(newItem);
                BindCartData();

                CalculateTotals();
            }
        }
コード例 #5
0
        public StoreItemCategory ProcessCategory(StoreItemCategory category)
        {
            try
            {
                using (var db = new ShopKeeperStoreEntities(_connectionString))
                {
                    StoreItemCategory categoryInfo;
                    var categories = db.StoreItemCategories.Where(b => b.Name.Trim().ToLower().Replace(" ", "") == category.Name.Trim().ToLower().Replace(" ", "")).ToList();
                    if (!categories.Any())
                    {
                        var processedCategory = db.StoreItemCategories.Add(category);
                        db.SaveChanges();
                        categoryInfo = processedCategory;
                    }
                    else
                    {
                        categoryInfo = categories[0];
                    }

                    return(categoryInfo);
                }
            }
            catch (DbEntityValidationException e)
            {
                var str = "";
                foreach (var eve in e.EntityValidationErrors)
                {
                    str += string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                         eve.Entry.Entity.GetType().Name, eve.Entry.State) + "\n";
                    foreach (var ve in eve.ValidationErrors)
                    {
                        str += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                             ve.PropertyName, ve.ErrorMessage) + " \n";
                    }
                }

                ErrorLogger.LogError(e.StackTrace, e.Source, str);
                return(new StoreItemCategory());
            }
        }
コード例 #6
0
        public List <StoreItemCategory> InitializeStoreItemCategories()
        {
            //Function is used to loop through a statically defined list of strings, and build StoreItemCategory objects for use throughout the app.
            string[] storeCategoryNames = new string[] { "Books", "Food", "Medical", "Other", "Imported Books", "Imported Food", "Imported Medical", "Imported Other" };
            List <StoreItemCategory> storeItemCategories = new List <StoreItemCategory>();

            //Loop through the names array and instantiate objects.
            for (int i = 0; i < storeCategoryNames.Length; i++)
            {
                StoreItemCategory newCategory = new StoreItemCategory()
                {
                    Name = storeCategoryNames[i],
                    BasicSalesTaxRate  = 10.0M,
                    ImportSalesTaxRate = 5.0M
                };

                //If the CategoryName doesn't contain the string "Other", set BasicSalesTaxExempt = true.
                //*The default value for the bool data type in C# is false, so we'll handle that condition when we instantiate the object beforehand.
                if (!newCategory.Name.Contains("Other"))
                {
                    newCategory.BasicSalesTaxExempt = true;
                }

                //Furthermore, the ImportTaxExempt value will always be false on object instantiation,
                //but in the event certain categories become exempt in the future, we'll have a field to handle this case.
                if (!newCategory.Name.Contains("Imported"))
                {
                    newCategory.ImportTaxExempt = true;
                }

                //Add the Category to the list.
                storeItemCategories.Add(newCategory);
            }

            return(storeItemCategories);
        }
コード例 #7
0
        private long ProcessRecord(DataRowView dv, ref string msg)
        {
            if (dv == null)
            {
                return(0);
            }
            try
            {
                using (var db = _dbStoreEntities)
                {
                    var mInfo = new StoreItem
                    {
                        Name = dv.Row["Name"].ToString().Trim()
                    };
                    var duplicates = db.StoreItems.Count(m => m.Name.ToLower().Trim() == mInfo.Name.ToLower().Trim());
                    if (duplicates > 0)
                    {
                        return(0);
                    }
                    var parentProductStr = dv.Row["Parent_Product_Name"].ToString().Trim();
                    if (!string.IsNullOrEmpty(parentProductStr))
                    {
                        var parentItems = db.StoreItems.Where(m => m.Name.ToLower().Trim() == parentProductStr.ToLower().Trim()).ToList();
                        if (parentItems.Any())
                        {
                            var parentItemId = parentItems[0].StoreItemId;
                            if (parentItemId > 0)
                            {
                                mInfo.ParentItemId = parentItemId;
                            }
                        }
                    }

                    var productTypeStr = dv.Row["Product_Type"].ToString().Trim();

                    if (!string.IsNullOrEmpty(productTypeStr))
                    {
                        var productTypes = db.StoreItemTypes.Where(m => m.Name.ToLower().Trim() == productTypeStr.ToLower().Trim()).ToList();
                        if (productTypes.Any())
                        {
                            var productType = productTypes[0];
                            if (productType != null && productType.StoreItemTypeId > 0)
                            {
                                mInfo.StoreItemTypeId = productType.StoreItemTypeId;
                            }
                        }
                        else
                        {
                            var productType = new StoreItemType {
                                Name = productTypeStr.Trim()
                            };
                            var processedProductType = db.StoreItemTypes.Add(productType);
                            db.SaveChanges();
                            if (processedProductType.StoreItemTypeId > 0)
                            {
                                mInfo.StoreItemTypeId = processedProductType.StoreItemTypeId;
                            }
                            else
                            {
                                msg = "Product Type Information could not be added.";
                                return(0);
                            }
                        }
                    }
                    else
                    {
                        msg = "Product Type is empty.";
                        return(0);
                    }

                    var productBrandStr = dv.Row["Product_Brand"].ToString().Trim();

                    if (!string.IsNullOrEmpty(productBrandStr))
                    {
                        var productTypes = db.StoreItemTypes.Where(m => m.Name.ToLower().Trim() == productBrandStr.ToLower().Trim()).ToList();
                        if (productTypes.Any())
                        {
                            var productType = productTypes[0];
                            if (productType != null && productType.StoreItemTypeId > 0)
                            {
                                mInfo.StoreItemTypeId = productType.StoreItemTypeId;
                            }
                        }
                        else
                        {
                            var productBrand = new StoreItemBrand {
                                Name = productBrandStr.Trim()
                            };
                            var processedProductBrand = db.StoreItemBrands.Add(productBrand);
                            db.SaveChanges();
                            if (processedProductBrand.StoreItemBrandId > 0)
                            {
                                mInfo.StoreItemBrandId = processedProductBrand.StoreItemBrandId;
                            }
                            else
                            {
                                msg = "Product Brand Information could not be added.";
                                return(0);
                            }
                        }
                    }
                    else
                    {
                        msg = "Product Brand is empty.";
                        return(0);
                    }

                    var productCategoryStr = dv.Row["Product_Category"].ToString().Trim();

                    if (!string.IsNullOrEmpty(productCategoryStr))
                    {
                        var productCategories = db.StoreItemCategories.Where(m => m.Name.ToLower().Trim() == productCategoryStr.ToLower().Trim()).ToList();
                        if (productCategories.Any())
                        {
                            var productCategory = productCategories[0];
                            if (productCategory != null && productCategory.StoreItemCategoryId > 0)
                            {
                                mInfo.StoreItemTypeId = productCategory.StoreItemCategoryId;
                            }
                        }
                        else
                        {
                            var productCategory = new StoreItemCategory {
                                Name = productCategoryStr.Trim()
                            };
                            var processedProductCategory = db.StoreItemCategories.Add(productCategory);
                            db.SaveChanges();
                            if (processedProductCategory.StoreItemCategoryId > 0)
                            {
                                mInfo.StoreItemCategoryId = processedProductCategory.StoreItemCategoryId;
                            }
                            else
                            {
                                msg = "Product Category is empty.";
                                return(0);
                            }
                        }
                    }
                    else
                    {
                        msg = "Product Category is empty.";
                        return(0);
                    }

                    var processedProduct = db.StoreItems.Add(mInfo);
                    db.SaveChanges();
                    return(processedProduct.StoreItemId);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }