public void Update(PRODUCT entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             var obj = from o in db.PRODUCTs
                       where o.id_product == entity.id_product
                       select o;
             obj.ToList()[0].title     = entity.title;
             obj.ToList()[0].category  = entity.category;
             obj.ToList()[0].size      = entity.size;
             obj.ToList()[0].color     = entity.color;
             obj.ToList()[0].photo     = entity.photo;
             obj.ToList()[0].price     = entity.price;
             obj.ToList()[0].count     = entity.count;
             obj.ToList()[0].id_supply = entity.id_supply;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #2
0
 public void Update(CLIENT entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             var obj = from o in db.CLIENTs
                       where o.id_client == entity.id_client
                       select o;
             obj.ToList()[0].name         = entity.name;
             obj.ToList()[0].surname      = entity.surname;
             obj.ToList()[0].patronymic   = entity.patronymic;
             obj.ToList()[0].login        = entity.login;
             obj.ToList()[0].password     = entity.password;
             obj.ToList()[0].access_level = entity.access_level;
             obj.ToList()[0].password     = entity.password;
             obj.ToList()[0].mail         = entity.mail;
             obj.ToList()[0].phone_number = entity.phone_number;
             obj.ToList()[0].sex          = entity.sex;
             obj.ToList()[0].growth       = entity.growth;
             obj.ToList()[0].chest        = entity.chest;
             obj.ToList()[0].waist        = entity.waist;
             obj.ToList()[0].hip          = entity.hip;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public List <ProductInfoContainer> GetProductsInfo()
        {
            try
            {
                using (StudioDB db = new StudioDB())
                {
                    List <ProductInfoContainer> productsInfo = new List <ProductInfoContainer>();
                    List <PRODUCT> products = AllProducts();
                    foreach (PRODUCT item in products)
                    {
                        var productMaterials = from ps in db.PRODUCT_STRUCTURE
                                               join m in db.MATERIALs
                                               on ps.id_material equals m.id_material
                                               where ps.id_product == item.id_product
                                               select new { m.id_material, m.name, ps.count };
                        List <ProductMaterial> materialsInfo = productMaterials.ToList()
                                                               .Select(x => new ProductMaterial(x.id_material, x.name, x.count))
                                                               .ToList();
                        productsInfo.Add(new ProductInfoContainer(item, materialsInfo));
                    }

                    return(productsInfo);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #4
0
        private bool LoadClientProducts()
        {
            try
            {
                using (StudioDB db = new StudioDB())
                {
                    var products = from p in db.PRODUCTs
                                   join b in db.BASKETs on p.id_product equals b.id_product
                                   where b.id_client == client.id_client
                                   select p;

                    clientProducts = products.ToList();
                    if (clientProducts.Count == 0)
                    {
                        return(false);
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public List <MaterialInfoContainer> GetMaterialsInfo()
        {
            try
            {
                using (StudioDB db = new StudioDB())
                {
                    List <MaterialInfoContainer> materialsInfo = new List <MaterialInfoContainer>();
                    List <MATERIAL> materials = AllMaterials();
                    foreach (MATERIAL item in materials)
                    {
                        var products = from ps in db.PRODUCT_STRUCTURE
                                       join m in db.MATERIALs
                                       on ps.id_material equals m.id_material
                                       join p in db.PRODUCTs
                                       on ps.id_product equals p.id_product
                                       where ps.id_material == item.id_material
                                       select p;
                        materialsInfo.Add(new MaterialInfoContainer(item, products.ToList()));
                    }

                    return(materialsInfo);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #6
0
        public decimal GetTotalSumMonth(int month, int year)
        {
            try
            {
                using (StudioDB db = new StudioDB())
                {
                    var     orders = orderS.All();
                    decimal res    = 0;
                    foreach (var item in orders)
                    {
                        if (Parser.ParseStringToIntArray(item.order_date, '.')[1] == month &&
                            Parser.ParseStringToIntArray(item.order_date, '.')[2] == year)
                        {
                            res += item.total_sum;
                        }
                    }

                    return(res);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        /// <summary>
        /// Уменьшить количество имеющегося материала
        /// </summary>
        /// <param name="entity"></param>
        public void DecreaseMaterialCount(PRODUCT entity)
        {
            try
            {
                List <MATERIAL>          lMaterials;
                List <PRODUCT_STRUCTURE> lProductStructures;
                using (StudioDB db = new StudioDB())
                {
                    var productStructures = from ps in db.PRODUCT_STRUCTURE
                                            where ps.id_product == entity.id_product
                                            select ps;
                    lProductStructures = productStructures.ToList();
                    var materials = from m in db.MATERIALs
                                    join ps in db.PRODUCT_STRUCTURE
                                    on m.id_material equals ps.id_material
                                    where ps.id_product == entity.id_product
                                    select m;
                    lMaterials = materials.ToList();
                }

                for (int i = 0; i < lMaterials.Count; i++)
                {
                    lMaterials[i].count -= lProductStructures[i].count;
                    materialS.Update(lMaterials[i]);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #8
0
 /// <summary>
 /// Select all record from CLIENT table
 /// </summary>
 public IEnumerable <CLIENT> SelectAll()
 {
     using (StudioDB db = new StudioDB())
     {
         var clientQuery = from cl in db.CLIENTs
                           select cl;
         return(clientQuery);
     }
 }
 public List <PRODUCT> All()
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             return(db.PRODUCTs.ToList());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public List <MATERIAL> All()
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             return(db.MATERIALs.ToList());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public List <SUPPLY> All()
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             return(db.SUPPLies.ToList());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #12
0
 public List <ORDER> All()
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             return(db.ORDERs.ToList());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #13
0
 public void Add(CLIENT entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             db.CLIENTs.Add(entity);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Add(SUPPLY entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             db.SUPPLies.Add(entity);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Add(PRODUCT_STRUCTURE entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             db.PRODUCT_STRUCTURE.Add(entity);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Add(PRODUCT entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             db.PRODUCTs.Add(entity);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e; //ERROR!
     }
 }
 public void Add(MATERIAL entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             db.MATERIALs.Add(entity);
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public List <string> GetColorsList()
        {
            try
            {
                using (StudioDB db = new StudioDB())
                {
                    var tmpList = db.PRODUCTs.Select(x => x.color).Distinct().ToList();

                    return(tmpList);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #19
0
 public List <CLIENT> SearchClientByLogin(string login)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             var tmpclient = from cl in db.CLIENTs
                             where cl.login == login
                             select cl;
             return(tmpclient.ToList());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #20
0
 public List <PRODUCT> GetSuppliesProducts(SUPPLY entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             var products = from p in db.PRODUCTs
                            where p.id_supply == entity.id_supply
                            select p;
             return(products.ToList());
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Update(SUPPLY entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             var obj = from o in db.SUPPLies
                       where o.id_supply == entity.id_supply
                       select o;
             obj.ToList()[0].delivery_date = entity.delivery_date;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #22
0
        public decimal GetTotalSumMonthSupply(int month, int year)
        {
            try
            {
                using (StudioDB db = new StudioDB())
                {
                    var supplies = supplyS.All();
                    int idSupply = -1;
                    foreach (var item in supplies)
                    {
                        if (Parser.ParseStringToIntArray(item.delivery_date, '.')[1] == month &&
                            Parser.ParseStringToIntArray(item.delivery_date, '.')[2] == year)
                        {
                            idSupply = item.id_supply;
                        }
                    }

                    decimal res = 0;
                    if (idSupply != -1)
                    {
                        var products = db.PRODUCTs.Where(x => x.id_supply == idSupply);
                        foreach (var item in products)
                        {
                            res += DecrementPercentages(item.price, 10) * item.count;
                        }

                        var salesProducts = from b in db.BASKETs
                                            join p in db.PRODUCTs
                                            on b.id_product equals p.id_product
                                            where p.id_supply == idSupply
                                            select new { b.count, p.price };
                        foreach (var item in salesProducts)
                        {
                            res += DecrementPercentages(item.price, 10) * item.count;
                        }
                    }
                    return(res);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public void Update(MATERIAL entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             var obj = from o in db.MATERIALs
                       where o.id_material == entity.id_material
                       select o;
             obj.ToList()[0].name  = entity.name;
             obj.ToList()[0].count = entity.count;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #24
0
 public void Delete(ORDER entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             ORDER order = db.ORDERs.
                           FirstOrDefault(c => c.id_order == entity.id_order);
             if (order != null)
             {
                 db.ORDERs.Remove(order);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Update(PRODUCT_STRUCTURE entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             var obj = from o in db.PRODUCT_STRUCTURE
                       where o.id_product_structure == entity.id_product_structure
                       select o;
             obj.ToList()[0].count       = entity.count;
             obj.ToList()[0].id_material = entity.id_material;
             obj.ToList()[0].id_product  = entity.id_product;
             db.SaveChanges();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Delete(BASKET entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             BASKET basket = db.BASKETs.
                             FirstOrDefault(c => c.id_basket == entity.id_basket);
             if (basket != null)
             {
                 db.BASKETs.Remove(basket);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Delete(MATERIAL entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             MATERIAL material = db.MATERIALs.
                                 FirstOrDefault(c => c.id_material == entity.id_material);
             if (material != null)
             {
                 db.MATERIALs.Remove(material);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Delete(SUPPLY entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             SUPPLY supply = db.SUPPLies.
                             FirstOrDefault(c => c.id_supply == entity.id_supply);
             if (supply != null)
             {
                 db.SUPPLies.Remove(supply);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public void Delete(PRODUCT entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             PRODUCT product = db.PRODUCTs.
                               FirstOrDefault(c => c.id_product == entity.id_product);
             if (product != null)
             {
                 db.PRODUCTs.Remove(product);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #30
0
 public void Delete(CLIENT entity)
 {
     try
     {
         using (StudioDB db = new StudioDB())
         {
             CLIENT client = db.CLIENTs.
                             FirstOrDefault(c => c.id_client == entity.id_client);
             if (client != null)
             {
                 db.CLIENTs.Remove(client);
                 db.SaveChanges();
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }