public void loadDataForEditProductType(int productTypeId)
        {
            this.Text = "Chỉnh sửa loại sản phẩm này";
            this.btnAdd.Text = "Cập nhật";

            ProductTypeService productTypeService = new ProductTypeService();
           
            productType = productTypeService.GetProductType(productTypeId);
            if (productType != null)
            {
                txtDescription.Text = productType.Description;
                txtCode.Text = productType.TypeCode;
                txtName.Text = productType.TypeName;
            }
        }
        public void AddProductType()
        {
            //List<ProductType> list = (List<ProductType>)BaoHienRepository.SelectAll<ProductType>().Where<ProductType>(item => item.st == false).ToList<ProductType>();
            //int count = list.Count;
            ProductType productType = new ProductType
            {
                Description = "P Type 1",
                ProductName = "Product 1",
                TypeCode = "Type code 1"
            };
            ProductTypeService productTypeService = new ProductTypeService();
            bool result = productTypeService.AddProductType(productType);

            Assert.AreEqual<bool>(true, result); ;
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (validator1.Validate())
            {
                if (productType != null && productType.Id > 0)//edit
                {
                    productType.Description = txtDescription.Text;
                    productType.TypeName = txtName.Text;
                    productType.TypeCode = txtCode.Text;

                    ProductTypeService productTypeService = new ProductTypeService();
                    bool result = productTypeService.UpdateProductType(productType);
                    if (result)
                    {
                        MessageBox.Show("Loại sản phẩm đã được cập nhật vào hệ thống");
                        ((ucProductType)this.CallFromUserControll).loadProductTypeList();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else//add new
                {
                    productType = new ProductType
                    {

                        Description = txtDescription.Text,
                        TypeName = txtName.Text,
                        TypeCode = txtCode.Text
                    };
                    ProductTypeService productTypeService = new ProductTypeService();
                    bool result = productTypeService.AddProductType(productType);
                    if (result)
                    {
                        MessageBox.Show("Loại sản phẩm đã được thêm mới vào hệ thống");
                        ((ucProductType)this.CallFromUserControll).loadProductTypeList();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Hiện tại hệ thống đang có lỗi. Vui lòng thử lại sau!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
 void LoadDataCombobox()
 {
     ProductTypeService productTypeService = new ProductTypeService();
     ProductType pt = new ProductType
     {
         Id = 0,
         TypeName = "Tất cả"
     };
     productTypes = productTypeService.GetProductTypes();
     productTypes.Add(pt);
     productTypes = productTypes.OrderBy(pts => pts.Id).ToList();
     if (productTypes != null)
     {
         cbmProductTypes.DataSource = productTypes;
         cbmProductTypes.DisplayMember = "TypeName";
         cbmProductTypes.ValueMember = "Id";
     }
     LoadProducts(0);
 }
 partial void DeleteProductType(ProductType instance);
 partial void UpdateProductType(ProductType instance);
 partial void InsertProductType(ProductType instance);
Exemplo n.º 8
0
        public override void InitializeDatabase(AppDbContext context)
        {
            base.InitializeDatabase(context);

            var wood = new ResourceType {
                Name = "Wood"
            };
            var stone = new ResourceType {
                Name = "Stone"
            };
            var iron = new ResourceType {
                Name = "Iron"
            };
            var wheat = new ResourceType {
                Name = "Wheat"
            };
            var leather = new ResourceType {
                Name = "Leather"
            };

            context.ResourceTypes.Add(wood);
            context.ResourceTypes.Add(stone);
            context.ResourceTypes.Add(iron);
            context.ResourceTypes.Add(wheat);
            context.ResourceTypes.Add(leather);

            var timberCamp = new BuildingType {
                Name = "TimberCamp", ResourceType = wood, Cost = "Wood 45 Stone 25 ", ProdPerWorker = 1
            };
            var quarry = new BuildingType {
                Name = "Quarry", ResourceType = stone, Cost = "Wood 45 Stone 25 ", ProdPerWorker = 1
            };
            var ironMine = new BuildingType {
                Name = "IronMine", ResourceType = iron, Cost = "Wood 450 Stone 450 ", ProdPerWorker = 1
            };
            var farm = new BuildingType {
                Name = "Farm", ResourceType = wheat, Cost = "Wood 450 Stone 450 ", ProdPerWorker = 2
            };
            var hunterCabin = new BuildingType {
                Name = "HunterCabin", ResourceType = leather, Cost = "Wood 200 Stone 150 ", ProdPerWorker = 1
            };

            context.SaveChanges();  //najskor sa vzdy ulozili do databazy entity, ktore mali nullable propertu, v tomto pripade ResourceType null

            var smithery = new BuildingType {
                Name = "Smithery", Cost = "Wood 1500 Stone 1500 Iron 1200"
            };
            var trainingCamp = new BuildingType {
                Name = "TrainingCamp", Cost = "Wood 1500 Stone 1050 Iron 1050"
            };
            var bakery = new BuildingType {
                Name = "Bakery", Cost = "Wood 1500 Stone 1500 Iron 750"
            };
            var tavern = new BuildingType {
                Name = "Tavern", Cost = "Wood 3000 Stone 3000 Iron 1500"
            };


            context.BuildingTypes.Add(timberCamp);
            context.BuildingTypes.Add(quarry);
            context.BuildingTypes.Add(ironMine);
            context.BuildingTypes.Add(farm);
            context.BuildingTypes.Add(bakery);

            context.BuildingTypes.Add(hunterCabin);

            context.BuildingTypes.Add(smithery);
            context.BuildingTypes.Add(trainingCamp);
            context.BuildingTypes.Add(tavern);

            var bow = new ProductType {
                Name = "Bow", Cost = "Wood 50 Leather 10", BuildingType = smithery
            };
            var ironSword = new ProductType {
                Name = "IronSword", Cost = "Wood 20 Iron 50", BuildingType = smithery
            };
            var polearm = new ProductType {
                Name = "Polearm", Cost = "Wood 40 Iron 30", BuildingType = smithery
            };
            var leatherArmor = new ProductType {
                Name = "LeatherArmor", Cost = "Leather 150", BuildingType = smithery
            };
            var mailArmor = new ProductType {
                Name = "MailArmor", Cost = "Iron 150", BuildingType = smithery
            };
            var horse = new ProductType {
                Name = "Horse", Cost = "Wheat 100 Leather 20", BuildingType = smithery
            };
            var bread = new ProductType {
                Name = "Bread", Cost = "Wheat 50", BuildingType = bakery
            };
            var waggon = new ProductType {
                Name = "Waggon", Cost = "Wood 10000 Stone 10000 Iron 5000 Leather 5000 Wheat 3000", BuildingType = smithery
            };

            context.ProductTypes.Add(bow);
            context.ProductTypes.Add(ironSword);
            context.ProductTypes.Add(polearm);
            context.ProductTypes.Add(leatherArmor);
            context.ProductTypes.Add(mailArmor);
            context.ProductTypes.Add(horse);
            context.ProductTypes.Add(bread);
            context.ProductTypes.Add(waggon);

            var archer = new UnitType {
                Name = "Archer", Cost = "Bow 1 LeatherArmor 1", Role = UnitRole.Friendly, Damage = 5, HP = 5
            };
            var swordsman = new UnitType {
                Name = "Swordsman", Cost = "IronSword 1 MailArmor 1", Role = UnitRole.Friendly, Damage = 5, HP = 10
            };
            var knight = new UnitType {
                Name = "Knight", Cost = "Polearm 1 MailArmor 1 Horse 1", Role = UnitRole.Friendly, Damage = 7, HP = 15
            };
            var settler = new UnitType {
                Name = "Settler", Cost = "Waggon 1 LeatherArmor 1 IronSword 1", Role = UnitRole.Friendly, Damage = 5, HP = 5
            };


            var goblin = new UnitType {
                Name = "Goblin", Role = UnitRole.Hostile, Damage = 4, HP = 5
            };                                                                                             //mozno by som ho chcel byt potom schopny aj najat
            //var ogre = new UnitType { Name = "Ogre", Role = UnitRole.Hostile };
            var wyvern = new UnitType {
                Name = "Wyvern", Role = UnitRole.Hostile, Damage = 14, HP = 250
            };
            //var giantTroll = new UnitType { Name = "GiantTroll", Role = UnitRole.Hostile };
            var dragon = new UnitType {
                Name = "Dragon", Role = UnitRole.Hostile, Damage = 50, HP = 1000
            };



            context.UnitTypes.Add(archer);
            context.UnitTypes.Add(swordsman);
            context.UnitTypes.Add(knight);
            context.UnitTypes.Add(settler);

            context.SaveChanges();  //najskor sa vzdy ulozili do databazy entity, ktore mali nullable propertu, v tomto pripade Cost null
                                    //co az tak tu by ani nevadilo, stacilo by pri pracis nimi iterovat od 3


            context.UnitTypes.Add(goblin);
            //context.UnitTypes.Add(ogre);
            context.UnitTypes.Add(wyvern);
            //context.UnitTypes.Add(giantTroll);
            context.UnitTypes.Add(dragon);

            var goblinsLair = new AdventureType {
                Name = "GoblinsLair", Enemy = goblin, NumberOfEnemies = 3, BreadPerUnit = 1, ProductsReward = "Bow 10 LeatherArmor 10", ResourcesReward = "Wood 1000 Stone 1000 Iron 1000"
            };
            var wyvernsNest = new AdventureType {
                Name = "WyvernsNest", Enemy = wyvern, NumberOfEnemies = 2, BreadPerUnit = 6, ProductsReward = "Bow 20 LeatherArmor 20 Ironsword 10 ", ResourcesReward = "Iron 1000 Leather 1000"
            };
            var dragonsLair = new AdventureType {
                Name = "DragonsLair", Enemy = dragon, NumberOfEnemies = 1, BreadPerUnit = 12, ProductsReward = "IronSword 100 MailArmor 100", ResourcesReward = "Iron 10000 Leather 10000"
            };


            context.AdventureTypes.Add(goblinsLair);
            context.AdventureTypes.Add(wyvernsNest);
            context.AdventureTypes.Add(dragonsLair);

            context.SaveChanges();
        }
Exemplo n.º 9
0
        public async Task SeedAsync()
        {
            await _context.Database.MigrateAsync().ConfigureAwait(false);

            if (!await _context.Users.AnyAsync())
            {
                const string adminRoleName = "administrator";
                const string userRoleName  = "user";

                await ensureRoleAsync(adminRoleName, "Default administrator", ApplicationPermissions.GetAllPermissionValues());
                await ensureRoleAsync(userRoleName, "Default user", new string[] { });

                await createUserAsync("admin", "tempP@ss123", "Inbuilt Administrator", "*****@*****.**", "+1 (123) 000-0000", new string[] { adminRoleName });
                await createUserAsync("user", "tempP@ss123", "Inbuilt Standard User", "*****@*****.**", "+1 (123) 000-0001", new string[] { userRoleName });
            }



            if (!await _context.Customers.AnyAsync() && !await _context.ProductType.AnyAsync())
            {
                Customer cust_1 = new Customer
                {
                    Name         = "Ebenezer Monney",
                    Email        = "*****@*****.**",
                    Gender       = Gender.Male,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };

                Customer cust_2 = new Customer
                {
                    Name         = "Itachi Uchiha",
                    Email        = "*****@*****.**",
                    PhoneNumber  = "+81123456789",
                    Address      = "Some fictional Address, Street 123, Konoha",
                    City         = "Konoha",
                    Gender       = Gender.Male,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };

                Customer cust_3 = new Customer
                {
                    Name         = "John Doe",
                    Email        = "*****@*****.**",
                    PhoneNumber  = "+18585858",
                    Address      = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio.
                    Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet",
                    City         = "Lorem Ipsum",
                    Gender       = Gender.Male,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };

                Customer cust_4 = new Customer
                {
                    Name         = "Jane Doe",
                    Email        = "*****@*****.**",
                    PhoneNumber  = "+18585858",
                    Address      = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio.
                    Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet",
                    City         = "Lorem Ipsum",
                    Gender       = Gender.Male,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };



                ProductType prodCat_1 = new ProductType
                {
                    Name         = "None",
                    Description  = "Default category. Products that have not been assigned a category",
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };



                Product prod_1 = new Product
                {
                    Name         = "BMW M6",
                    Description  = "Yet another masterpiece from the world's best car manufacturer",
                    BuyingPrice  = 109775,
                    SellingPrice = 114234,
                    UnitsInStock = 12,
                    IsActive     = true,
                    ProductType  = prodCat_1,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };

                Product prod_2 = new Product
                {
                    Name         = "Nissan Patrol",
                    Description  = "A true man's choice",
                    BuyingPrice  = 78990,
                    SellingPrice = 86990,
                    UnitsInStock = 4,
                    IsActive     = true,
                    ProductType  = prodCat_1,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow
                };



                Order ordr_1 = new Order
                {
                    Discount     = 500,
                    Cashier      = await _context.Users.FirstAsync(),
                    Customer     = cust_1,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow,
                    OrderDetails = new List <OrderDetail>()
                    {
                        new OrderDetail()
                        {
                            UnitPrice = prod_1.SellingPrice, Quantity = 1, Product = prod_1
                        },
                        new OrderDetail()
                        {
                            UnitPrice = prod_2.SellingPrice, Quantity = 1, Product = prod_2
                        },
                    }
                };

                Order ordr_2 = new Order
                {
                    Cashier      = await _context.Users.FirstAsync(),
                    Customer     = cust_2,
                    DateCreated  = DateTime.UtcNow,
                    DateModified = DateTime.UtcNow,
                    OrderDetails = new List <OrderDetail>()
                    {
                        new OrderDetail()
                        {
                            UnitPrice = prod_2.SellingPrice, Quantity = 1, Product = prod_2
                        },
                    }
                };


                _context.Customers.Add(cust_1);
                _context.Customers.Add(cust_2);
                _context.Customers.Add(cust_3);
                _context.Customers.Add(cust_4);

                _context.Products.Add(prod_1);
                _context.Products.Add(prod_2);

                _context.Orders.Add(ordr_1);
                _context.Orders.Add(ordr_2);

                await _context.SaveChangesAsync();
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the ProductTypes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProductTypes(ProductType productType)
 {
     base.AddObject("ProductTypes", productType);
 }
 /// <summary>
 /// Create a new ProductType object.
 /// </summary>
 /// <param name="productTypeId">Initial value of the ProductTypeId property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="typeCode">Initial value of the TypeCode property.</param>
 public static ProductType CreateProductType(global::System.Int32 productTypeId, global::System.String name, global::System.String typeCode)
 {
     ProductType productType = new ProductType();
     productType.ProductTypeId = productTypeId;
     productType.Name = name;
     productType.TypeCode = typeCode;
     return productType;
 }