public override bool IsValid(object value)
        {
            string login = (string)value;

            using (StoreDB db = new StoreDB())
                return !db.IsContainUser(login);
        }
Beispiel #2
0
        private void byDateButton_Click(object sender, EventArgs e)
        {
            using (StoreDB db = new StoreDB())
            {
                List <Order> userOrders = db.Orders
                                          .Where(x => x.userId == GlobalVars.CurrentUser.userID)
                                          .OrderByDescending(x => x.timeCreatedOrder)
                                          .ToList();

                dgOrders(userOrders);
            }
        }
Beispiel #3
0
 private void SeedCategories(StoreDB context)
 {
     for (int i = 1; i <= 5; i++)
     {
         var category = new Category()
         {
             Name = "Kategoria " + i.ToString()
         };
         context.Set <Category>().AddOrUpdate(category);
     }
     context.SaveChanges();
 }
Beispiel #4
0
 public void checkProductsButton_Click(object sender, EventArgs e)
 {
     using (StoreDB db = new StoreDB())
     {
         var products = db.Products
                        .Include(p => p.Orders)
                        .Where(p => p.Orders.Any(c => c.orderId == ((Order)dataGridView.CurrentRow.DataBoundItem).orderId))
                        .ToList();
         GlobalVars.CurrentProductsList = products;
         GlobalVars.checkingOrderForm.ShowDialog();
     }
 }
Beispiel #5
0
        public List <ProductCategory> GetTaxMaster()
        {
            List <ProductCategory> categories = new List <ProductCategory>();

            using (var db = new StoreDB())
            {
                var query = (from a in db.PRODUCT_CATEGORY_MASTER_NEW
                             select a);
                categories = Mapper.Map <List <ProductCategory> >(query.ToList());
            }
            return(categories);
        }
Beispiel #6
0
 public void TestDBMethod()
 {
     using (var db = new StoreDB())
     {
         //db.PRODUCT_CATEGORY_MASTER.Add(new PRODUCT_CATEGORY_MASTER() { CategoryName="John Honai",CategoryDescription="This is my sample category"});
         //db.SaveChanges();
         var query = (from b in db.PRODUCT_CATEGORY_MASTER_NEW
                      orderby b.CategoryName
                      select b).FirstOrDefault();
         string y = query.CategoryName;
     }
 }
Beispiel #7
0
        public List <UomCategory> GetUomCategories()
        {
            List <UomCategory> categories = new List <UomCategory>();

            using (var db = new StoreDB())
            {
                var query = (from a in db.UOM_CATEGORY_MASTER
                             select a);
                categories = Mapper.Map <List <UomCategory> >(query.ToList());
            }
            return(categories);
        }
        public MainWindow()
        {
            StoreDB storeDb = new StoreDB();

            InitializeComponent();
            products = storeDb.GetProducts();

            this.DataContext     = products;
            view                 = (ListCollectionView)CollectionViewSource.GetDefaultView(this.DataContext);
            view.CurrentChanged += new EventHandler(view_CurrentChanged);

            lstProducts.ItemsSource = products;
        }
Beispiel #9
0
        public async Task <Contact> Create([FromBody] Contact value)
        {
            try
            {
                var ret = await StoreDB.AddContactAsync(value);

                return(ret);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #10
0
        public void AddProduct(Product product)
        {
            using (var db = new StoreDB())
            {
                PRODUCT prod = Mapper.Map <PRODUCT>(product);
                prod.ProductCategoryId = 1;
                prod.ProductType       = 1;
                //prod.ProductUoM = 1;

                db.PRODUCTS.Add(prod);
                db.SaveChanges();
            }
        }
        public TreeViewWindow()
        {
            InitializeComponent();
            TreeCategories.ItemsSource = StoreDB.GetCategoriesAndProducts();

            foreach (var drive in DriveInfo.GetDrives())
            {
                TreeViewItem item = new TreeViewItem();
                item.Tag    = drive;
                item.Header = drive.ToString();
                item.Items.Add("*");
                TreeFileSystem.Items.Add(item);
            }
        }
Beispiel #12
0
 private void SeedProducers(StoreDB context)
 {
     for (int i = 1; i <= 3; i++)
     {
         var producer = new Producer()
         {
             ProducerId = i,
             Name       = "Producent " + i.ToString(),
             FirstName  = "Tom",
             LastName   = "Drugi"
         };
         context.Set <Producer>().AddOrUpdate(producer);
     }
     context.SaveChanges();
 }
Beispiel #13
0
        //заполнение быза данных
        private void uploadToDB()
        {
            using (StoreDB db = new StoreDB())
            {
                if (db.Products.Count() != 0)
                {
                    return;
                }
                Category mac    = new Category("Mac");
                Category ipad   = new Category("iPad");
                Category iphone = new Category("iPhone");
                Category watch  = new Category("Watch");
                Category tv     = new Category("TV");
                Category music  = new Category("Music");
                db.Categories.Add(mac);
                db.Categories.Add(ipad);
                db.Categories.Add(iphone);
                db.Categories.Add(watch);
                db.Categories.Add(tv);
                db.Categories.Add(music);
                db.SaveChanges();

                db.Products.AddRange(new List <Product> {
                    new Product("MacBook Air", 1299, mac),
                    new Product("MacBook Pro 13\"", 2399, mac),
                    new Product("MacBook Pro 16\"", 2799, mac),
                    new Product("iMac", 2299, mac),
                    new Product("iMac Pro", 4999, mac),
                    new Product("iPad Pro", 999, ipad),
                    new Product("iPad Air", 499, ipad),
                    new Product("iPad", 329, ipad),
                    new Product("iPad Mini", 399, ipad),
                    new Product("iPhone 11 Pro", 999, iphone),
                    new Product("iPhone 11", 699, iphone),
                    new Product("iPhone xR", 599, iphone),
                    new Product("iPhone 8", 449, iphone),
                    new Product("Watch Series 5", 399, watch),
                    new Product("Watch Nike", 399, watch),
                    new Product("Watch Series 3", 399, watch),
                    new Product("TV 4K", 199, tv),
                    new Product("TV HD", 149, tv),
                    new Product("Airpods Pro", 249, music),
                    new Product("Airpods", 199, music),
                    new Product("Home Pod", 299, music)
                });
                db.SaveChanges();
            }
        }
Beispiel #14
0
 private void SeedPictures(StoreDB context)
 {
     for (int i = 0; i < 20; i++)
     {
         context.Set <Picture>().AddOrUpdate(new Picture {
             Name = "pict1.jpg", ProductId = 1 + 3 * i
         });
         context.Set <Picture>().AddOrUpdate(new Picture {
             Name = "pict2.jpg", ProductId = 2 + 3 * i
         });
         context.Set <Picture>().AddOrUpdate(new Picture {
             Name = "pict3.jpg", ProductId = 3 + 3 * i
         });
     }
     context.SaveChanges();
 }
Beispiel #15
0
 public ActionResult Create([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album)
 {
     if (ModelState.IsValid)
     {
         if (album.Title != null && album.Title.Trim() != "" && album.Price >= 0)
         {
             StoreDB.Albums.Add(album);
             StoreDB.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(RedirectToAction("InvalidRequest", "Error"));
     }
     ViewBag.ArtistId = new SelectList(StoreDB.Artists, "ArtistId", "Name", album.ArtistId);
     ViewBag.GenreId  = new SelectList(StoreDB.Genres, "GenreId", "Name", album.GenreId);
     return(View(album));
 }
Beispiel #16
0
        private void allOrdersButton_Click(object sender, EventArgs e)
        {
            using (StoreDB db = new StoreDB())
            {
                var allOrders = from order in db.Orders
                                select order;

                dgOrdersAdmin(allOrders.ToList());
                menusVisible(false, false, false, false, true);
                menuAdministrator.Items[0].Visible = true;
                menuAdministrator.Items[1].Visible = true;
                menuAdministrator.Items[2].Visible = true;
                menuAdministrator.Items[3].Visible = false;
                menuAdministrator.Items[4].Visible = false;
            }
        }
Beispiel #17
0
        public ActionResult Index()
        {
            log.Info("testtestsetest");

            try
            {
                using (StoreDB db = new StoreDB())
                {
                    var result = db.Products.Select(s => s.productId == 1);
                }
            }
            catch (Exception e)
            {
                throw;
            }
            return(View());
        }
Beispiel #18
0
        private async void makeInvoiceButton_Click(object sender, EventArgs e)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo("D:\\");

            directoryInfo.CreateSubdirectory("Temp");
            string         path  = @"D:\temp\file.txt";
            Order          order = (Order)dataGridView.CurrentRow.DataBoundItem;
            List <Product> productsInOrder;

            using (StoreDB db = new StoreDB())
            {
                productsInOrder = db.Products
                                  .Include(p => p.Orders)
                                  .Where(p => p.Orders.Any(c => c.orderId == ((Order)dataGridView.CurrentRow.DataBoundItem).orderId))
                                  .ToList();
            }

            try
            {
                using (FileStream fs = File.Create(path))
                {
                    byte[] orderInfo = new UTF8Encoding(true)
                                       .GetBytes($"Buyer: {order.userName}\n" +
                                                 $"Order number: {order.orderId}\n" +
                                                 $"Date: {order.timeCreatedOrder}\n\n" +
                                                 $"| Price\t| Product\n");
                    fs.Write(orderInfo, 0, orderInfo.Length);

                    foreach (var product in productsInOrder)
                    {
                        byte[] productInfo = new UTF8Encoding(true).GetBytes($"| {product.Price}\t| {product.Name}\n");
                        await fs.WriteAsync(productInfo, 0, productInfo.Length);
                    }

                    byte[] orderSum = new UTF8Encoding(true)
                                      .GetBytes($"\nTotal price: {order.sum}");
                    fs.Write(orderSum, 0, orderSum.Length);
                }
                Process.Start(path);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #19
0
 private void CurrentProductsList_Load()
 {
     using (StoreDB db = new StoreDB())
     {
         GlobalVars.CurrentProductsList = null;
         var tmp = from product in db.Products
                   select product;
         try
         {
             foreach (var item in tmp)
             {
                 GlobalVars.CurrentProductsList.Add(item);
             }
         }
         catch (NullReferenceException)
         {
         }
     }
 }
Beispiel #20
0
        protected void Application_Start()
        {
            log4net.Config.XmlConfigurator.Configure();

            if (HttpContext.Current.IsDebuggingEnabled)
            {
                System.Data.Entity.Database.SetInitializer <StoreDB>(new DemoInitialize1());
                StoreDB db = new StoreDB();
                db.Database.Initialize(true);
            }



            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Beispiel #21
0
        private void btnGetProduct_Click(object sender, RoutedEventArgs e)
        {
            int id;

            if (Int32.TryParse(productID.Text, out id))
            {
                try
                {
                    gridProductDetails.DataContext = StoreDB.GetProduct(id);
                }
                catch
                {
                    MessageBox.Show("Error contacting database.");
                }
            }
            else
            {
                MessageBox.Show("Invalid ID");
            }
        }
Beispiel #22
0
 private void isNotManagerButton_Click(object sender, EventArgs e)
 {
     if (((User)dataGridView.CurrentRow.DataBoundItem).userID == GlobalVars.CurrentUser.userID)
     {
         MessageBox.Show("You can not change your status manager.");
         return;
     }
     using (StoreDB db = new StoreDB())
     {
         db.Users.First(o => o.userID == ((User)dataGridView.CurrentRow.DataBoundItem).userID).IsManager = false;
         db.SaveChanges();
         List <User> users = db.Users
                             .OrderBy(y => y.userID)
                             .OrderBy(x => x.IsManager)
                             .ToList();
         dataGridView.DataSource = users;
         dataGridView.Columns["password"].Visible = false;
         dataGridView.Columns["Orders"].Visible   = false;
     }
 }
Beispiel #23
0
        /*---------------------------------------------------------------    end_ShoppingHistory    ----------------------------------------------------------------*/
        /*---------------------------------------------------------------    AdministratorMenu    ----------------------------------------------------------------*/
        private void allUsersButton_Click(object sender, EventArgs e)
        {
            menusVisible(false, false, false, false, true);
            menuAdministrator.Items[0].Visible = false;
            menuAdministrator.Items[1].Visible = false;
            menuAdministrator.Items[2].Visible = false;
            menuAdministrator.Items[3].Visible = true;
            menuAdministrator.Items[4].Visible = true;
            using (StoreDB db = new StoreDB())
            {
                List <User> users = db.Users
                                    .OrderBy(y => y.userID)
                                    .OrderBy(x => x.IsManager)
                                    .ToList();

                dataGridView.DataSource = users;
                dataGridView.Columns["password"].Visible = false;
                dataGridView.Columns["Orders"].Visible   = false;
            }
        }
Beispiel #24
0
 private void LoadStudent()
 {
     try
     {
         if (db == null)
         {
             db = new StoreDB();
         }
         //Instead of binding StudentAttendanceGrid here, we bind it in xaml
         //<igDP:XamDataPresenter DataSource="{Binding Path=Members}"
         CommunityVM = new CommunityViewModel(db.GetStudentsByClassA(ClassId)); //db.GetStudentsByClassA(4);
         _view.StudentAttendanceGrid.DataContext = CommunityVM;
         loadStudentClicked = true;
         MainWindowViewModel.Instance.StatusBar = $"Load Students for class {ClassId}";
     }
     catch (Exception e)
     {
         log.Error("In ScheduleViewModel.cs..LoadStudent: " + e.Message);
         Environment.Exit(-1);
     }
 }
Beispiel #25
0
        private void SeedProducts(StoreDB context)
        {
            int sizes  = Repository.Services.ProductService.AvailableSizes.Length;
            int colors = Repository.Services.ProductService.AvailableColors.Length;

            for (int i = 1; i <= 60; i++)
            {
                var product = new Product()
                {
                    Category   = context.Categories.Find(i % 5 + 1),
                    ProducerId = (i - 1) / 20 + 1,
                    Colors     = i % ((1 << colors) - 1) + 1,
                    Sizes      = i % ((1 << sizes) - 1) + 1,
                    Name       = "Produkt " + i.ToString(),
                    Price      = i / 10M,
                    Amount     = (i < 5 ? 0 : i)
                };
                context.Set <Product>().AddOrUpdate(product);
            }
            context.SaveChanges();
        }
Beispiel #26
0
        /*---------------------------------------------------------------    end_ShoppingCart    ----------------------------------------------------------------*/

        /*---------------------------------------------------------------    ShoppingHistory    ----------------------------------------------------------------*/
        private void shoppingHistoryButton_Click(object sender, EventArgs e)
        {
            using (StoreDB db = new StoreDB())
            {
                if (db.Orders.Where(u => u.userId == GlobalVars.CurrentUser.userID).Count() > 0)
                {
                    byDateButton_Click(sender, e);
                    menusVisible(false, false, true, false, false);

                    List <Order> userOrders = db.Orders
                                              .Where(x => x.userId == GlobalVars.CurrentUser.userID)
                                              .ToList();

                    dgOrders(userOrders);
                }
                else
                {
                    MessageBox.Show("You have no purchases yet.");
                }
            }
        }
Beispiel #27
0
        public MainWindow()
        {
            db   = new StoreDB();
            Cart = new ObservableCollection <CartItem>();

            // первый запрос к БД долгий, поэтому
            // делаю его заранее в фоне
            // (простой, ничего не значащий запрос)
            try {
                var roles = db.Roles.ToListAsync();
            } catch (Exception ex) {
                Exception subEx = ex.InnerException;
                MessageBox.Show($"Ошибка в БД: {(subEx == null ? ex.Message : subEx.Message)}");
                Close();
            }

            InitializeComponent();

            settings.LoadFromRegistry(this);

            // Сразу открываю окно авторизации
            ActiveItem.Content = new LoginView();
        }
Beispiel #28
0
 private void uncheckedOrdersButton_Click(object sender, EventArgs e)
 {
     using (StoreDB db = new StoreDB())
     {
         var uncheckedOrders = from order in db.Orders
                               where order.IsChecked == false
                               select order;
         if (uncheckedOrders.ToList().Count == 0)
         {
             MessageBox.Show("All orders are checked.");
         }
         else
         {
             menusVisible(false, false, false, false, true);
             menuAdministrator.Items[0].Visible = true;
             menuAdministrator.Items[1].Visible = true;
             menuAdministrator.Items[2].Visible = true;
             menuAdministrator.Items[3].Visible = false;
             menuAdministrator.Items[4].Visible = false;
             dgOrdersAdmin(uncheckedOrders.ToList());
         }
     }
 }
Beispiel #29
0
        public void registrationButton_Click(object sender, EventArgs e)
        {
            using (StoreDB db = new StoreDB())
            {
                foreach (var user in db.Users)
                {
                    if (user.mail == loginTextbox.Text)
                    {
                        MessageBox.Show("A user with this email has already been created.", "Error");
                        return;
                    }
                }

                User tempUser = db.Users.Add(new User(string.Format(firstNameTextbox.Text + " " + lastNameTextbox.Text),
                                                      loginTextbox.Text,
                                                      Convert.ToDateTime(birthdayTextbox.Text),
                                                      EncodingPassword.Encryption(passwordTextbox.Text)));
                db.SaveChanges();

                if (GlobalVars.CurrentUser.name == null)
                {
                    MessageBox.Show("Registration is complited. Use your login and password to autorization.");
                    GlobalVars.registrationForm.Visible = false;
                    GlobalVars.autorizationForm.Visible = true;
                }
                else
                {
                    DialogResult dialogResult = MessageBox.Show("Make new user as manager ?", "Registration is complited", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        tempUser.IsManager = true;
                        db.SaveChanges();
                    }
                    Hide();
                }
            }
        }
Beispiel #30
0
        public List <Product> GetProductsById(string id)
        {
            int     i = Convert.ToInt32(id);
            Product prods;

            using (var db = new StoreDB())
            {
                var query = (from b in db.PRODUCTS
                             where b.ProductId == i
                             select b);
                var prod = query.ToList();
                //List<Product> prods = Mapper.Map<List<Product>>(query.ToList());
                prods = Mapper.Map <Product>(query.FirstOrDefault());

                var price = (from p in db.PURCHASE_PRODUCTS
                             where p.ProductId == i
                             select p.SellingPrice).ToList();

                //price.
                prods.PriceList = new List <decimal?>();
                price.ForEach(x => prods.PriceList.Add((x.Value)));

                var taxID = (from t in db.PRODUCT_CATEGORY_MASTER_NEW
                             where t.CategoryId == prods.ProductCategoryId
                             select t.CATEGORY_TAX_DEFINITION_NEW.TaxId).ToList();
                var tax = (from t in db.TAX_MASTER
                           where taxID.Contains(t.TaxId)
                           select t).FirstOrDefault();

                prods.ProductTax = Mapper.Map <Tax>(tax);
            }
            return(new List <Product>()
            {
                prods
            });
        }
Beispiel #31
0
        private void Product_Click(object sender, EventArgs e)
        {
            List <Product> tmpList = new List <Product>();
            var            tmp     = sender as ToolStripItem;

            using (StoreDB db = new StoreDB())
            {
                foreach (var Product in db.Products)
                {
                    if (Product.Name == tmp.Text)
                    {
                        tmpList.Add(Product);
                    }
                }
                if (tmpList.Count == 0)
                {
                    MessageBox.Show($"No product: {tmp.Text}");
                }
                else
                {
                    dgProducts(tmpList);
                }
            }
        }