コード例 #1
0
        public void Update(Franqueado entity)
        {
            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    var franq_found = ctx.Franqueado.Find(entity.id);
                    if (franq_found != null)
                    {
                        var f = (from a in ctx.Franqueado where a.id == entity.id select a).SingleOrDefault();

                        f.id     = entity.id;
                        f.nif    = entity.nif;
                        f.morada = entity.morada;
                        f.nome   = entity.nome;

                        try
                        {
                            ctx.SaveChanges();
                            Console.WriteLine("Franchisee {0} updated.", entity.id);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.GetBaseException());
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error updating Franchisee {0}", entity.id);
                    }
                }
                das.Commit();
            }
        }
コード例 #2
0
        public void Delete(int ProdId)
        {
            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    var prd_found = ctx.Produto.Find(ProdId);

                    if (prd_found != null)
                    {
                        ctx.ProdVendidoPorFranqueado.RemoveRange(ctx.ProdVendidoPorFranqueado.Where(x => x.prod_id == prd_found.id));
                        ctx.HistoricoVendas.RemoveRange(ctx.HistoricoVendas.Where(x => x.prod_id == prd_found.id));
                        ctx.Entrega.RemoveRange(ctx.Entrega.Where(x => x.prod_id == prd_found.id));
                        ctx.Produto.Remove(prd_found);
                        ctx.SaveChanges();
                        Console.WriteLine("Product with ID {0} removed.", ProdId);
                    }
                    else
                    {
                        Console.WriteLine("Error removing Product {0}", ProdId);
                    }
                }
                das.Commit();
            }
        }
コード例 #3
0
 public void Delete(Franqueado key)
 {
     using (var ctx = new SI2_Bom_e_BaratoEntities())
     {
         var f = ctx.Franqueado.Find(key);
         if (f != null)
         {
             try
             {
                 ctx.HistoricoVendas.RemoveRange(ctx.HistoricoVendas.Where(x => x.franq_id == f.id));
                 ctx.Entrega.RemoveRange(ctx.Entrega.Where(x => x.franq_id == f.id));
                 ctx.ProdVendidoPorFranqueado.RemoveRange(ctx.ProdVendidoPorFranqueado.Where(x => x.franq_id == f.id));
                 ctx.Franqueado.Remove(f);
                 ctx.SaveChanges();
                 Console.WriteLine("Franchisee with ID {0} removed.", key);
             }
             catch (Exception e)
             {
                 Console.WriteLine("SQL Error removing Franchisee: {0}", e.GetBaseException());
             }
         }
         else
         {
             Console.WriteLine("Error removing Franchisee {0}", key);
         }
     }
 }
コード例 #4
0
        public void CreateScope(bool pessimisticLock, out bool isMyTr, out bool isMyConn)
        {
            bool sc, st;

            if (currentContext == null)
            {
                //currentTrans = ctx.Database.Connection.BeginTransaction();
                if (pessimisticLock)
                {
                    currentTrans = new TransactionScope();
                }
                TransactionVotes = true;
                st = true;
            }
            else
            {
                st = false;
            }
            if (currentContext == null)
            {
                currentContext = new SI2_Bom_e_BaratoEntities();
                sc             = true;
            }
            else
            {
                sc = false;
            }
            isMyTr   = st;
            isMyConn = sc;
        }
コード例 #5
0
 // Use the same list for displaying & validating user input.
 private void LoadAllProductTypes()
 {
     using (var ctx = new SI2_Bom_e_BaratoEntities())
     {
         product_types_list = ctx.TipoProduto.ToList();
     }
 }
コード例 #6
0
 public void CloseConnection(bool isMyConnection)
 {
     if (isMyConnection && currentContext != null)
     {
         currentContext.Dispose();
         currentContext = null;
         Thread.FreeNamedDataSlot("ThreadSession");
     }
 }
コード例 #7
0
 private void UpdateDueToSale(int franqId, int prodId, int quantidade)
 {
     using (var ctx = new SI2_Bom_e_BaratoEntities())
     {
         var p = ctx.ProdVendidoPorFranqueado.Where(pvpf => pvpf.franq_id == franqId && pvpf.prod_id == prodId).SingleOrDefault();
         p.stock_total -= quantidade;
         p.qtd_vendas  += quantidade;
         ctx.SaveChanges();
     }
 }
コード例 #8
0
 private void ShowFranchiseesList()
 {
     using (var ctx = new SI2_Bom_e_BaratoEntities())
     {
         List <Franqueado> fcs = ctx.Franqueado.ToList();
         foreach (Franqueado f in fcs)
         {
             Console.WriteLine("\tID:{0} | NIF:{1} | Name:{2}", f.id, f.nif, f.nome);
         }
     }
 }
コード例 #9
0
 public void DeleteAllWithProdId(int prodId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.HistoricoVendas.RemoveRange(ctx.HistoricoVendas.Where(hv => hv.prod_id == prodId));
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
コード例 #10
0
 public void Create(Franqueado entity)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.Franqueado.Add(entity);
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
コード例 #11
0
 public void DeleteAllWithProdId(int prodId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.ProdVendidoPorFranqueado.RemoveRange(ctx.ProdVendidoPorFranqueado.Where(pvpf => pvpf.prod_id == prodId));
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
コード例 #12
0
 public void DeleteAllWithProdId(int prodId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.FornecedorProduto.RemoveRange(ctx.FornecedorProduto.Where(fp => fp.prod_id == prodId));
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
コード例 #13
0
        private void ShowProductList()
        {
            using (var ctx = new SI2_Bom_e_BaratoEntities())
            {
                List <Produto> pts = ctx.Produto.ToList();

                foreach (Produto pt in pts)
                {
                    Console.WriteLine("\tID:{0} | Cod:{1} | Description:{2}", pt.id, pt.cod, pt.descricao);
                }
            }
        }
コード例 #14
0
 public void Delete(HistoricoVendas entity)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.HistoricoVendas.Attach(entity);
             ctx.HistoricoVendas.Remove(entity);
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
コード例 #15
0
        public List <ProdVendidoPorFranqueado> GetOutOfStock(double percentagemRutura, int franqId)
        {
            List <ProdVendidoPorFranqueado> ps;

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    ps = ctx.ProdVendidoPorFranqueado.Where(pvpf => pvpf.franq_id == franqId && pvpf.stock_total < pvpf.stock_max * percentagemRutura).ToList();
                }
            }
            return(ps);
        }
コード例 #16
0
        public List <Fornecedor> GetAllFornecedoresForProduto(int prodId)
        {
            List <Fornecedor> fs;

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    fs = ctx.FornecedorProduto.Where(fp => fp.prod_id == prodId).Select(fp => fp.Fornecedor).ToList();
                }
            }
            return(fs);
        }
コード例 #17
0
        public List <Franqueado> GetAll()
        {
            List <Franqueado> fs;

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    fs = ctx.Franqueado.ToList();
                }
            }
            return(fs);
        }
コード例 #18
0
        public FornecedorProduto Read(int fornId, int prodId)
        {
            FornecedorProduto fp;

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    fp = ctx.FornecedorProduto.Where(f => f.forn_id == fornId && f.prod_id == prodId).FirstOrDefault();
                }
            }
            return(fp);
        }
コード例 #19
0
        public Produto Read(int id)
        {
            Produto p;

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    p = ctx.Produto.Where(prod => prod.id == id).First();
                }
            }
            return(p);
        }
コード例 #20
0
        public Franqueado Read(int id)
        {
            Franqueado f;

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    f = ctx.Franqueado.Where(a => a.id == id).FirstOrDefault();
                }
            }
            return(f);
        }
コード例 #21
0
        public List <ProdVendidoPorFranqueado> GetAllInFranchisee(int franqId)
        {
            List <ProdVendidoPorFranqueado> ps;

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    ps = ctx.ProdVendidoPorFranqueado.Where(pvpf => pvpf.franq_id == franqId).ToList();
                }
            }
            return(ps);
        }
コード例 #22
0
        public List <Produto> GetAll()
        {
            List <Produto> ps;

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    ps = ctx.Produto.ToList();
                }
            }
            return(ps);
        }
コード例 #23
0
 public void Create(Produto entity)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             ctx.Produto.Add(entity);
             ctx.SaveChanges();
             Console.WriteLine("Product inserted with id: {0}.", entity.id);
         }
         das.Commit();
     }
 }
コード例 #24
0
        public void DeleteAllWithProdId(int prodId)
        {
            bool isMytr, isMyConn;

            MySession.CreateScope(false, out isMytr, out isMyConn);

            using (var ctx = new SI2_Bom_e_BaratoEntities())
            {
                ctx.Entrega.RemoveRange(ctx.Entrega.Where(e => e.prod_id == prodId));
                ctx.SaveChanges();
            }

            MySession.EndTransaction(true, isMytr, isMyConn);
            MySession.CloseConnection(isMytr);
        }
コード例 #25
0
 public void DeleteAllWithFranqId(int franqId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             var pvpfToDelete = ctx.ProdVendidoPorFranqueado.Where(p => p.franq_id == franqId).ToList();
             foreach (var deletepvpf in pvpfToDelete)
             {
                 ctx.ProdVendidoPorFranqueado.Remove(deletepvpf);
             }
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
コード例 #26
0
 public void DeleteAllWithFranqId(int franqId)
 {
     using (var das = new DataAccessScope(true))
     {
         using (var ctx = new SI2_Bom_e_BaratoEntities())
         {
             var histToDelete = ctx.HistoricoVendas.Where(h => h.franq_id == franqId).ToList();
             foreach (var deleteHist in histToDelete)
             {
                 ctx.HistoricoVendas.Remove(deleteHist);
             }
             ctx.SaveChanges();
         }
         das.Commit();
     }
 }
コード例 #27
0
        public void FulfillOrders(List <Proposta> encs)
        {
            List <int> pIds = encs.Select(e => e.ProdId).ToList();

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    var query = (from p in ctx.Produto where pIds.Contains(p.id) select p).ToList();
                    foreach (var q in query)
                    {
                        q.stock_total += encs.Where(e => e.ProdId == q.id).First().Qtd;
                    }
                    ctx.SaveChanges();
                }
                das.Commit();
            }
        }
コード例 #28
0
        public void DeleteAllWithFranqId(int franqId)
        {
            bool isMytr, isMyConn;

            MySession.CreateScope(false, out isMytr, out isMyConn);

            using (var ctx = new SI2_Bom_e_BaratoEntities())
            {
                var entToDelete = ctx.Entrega.Where(e => e.franq_id == franqId).ToList();
                foreach (var deleteEnt in entToDelete)
                {
                    ctx.Entrega.Remove(deleteEnt);
                    ctx.SaveChanges();
                }
            }

            MySession.EndTransaction(true, isMytr, isMyConn);
            MySession.CloseConnection(isMytr);
        }
コード例 #29
0
        public ProdVendidoPorFranqueado Read(int franqId, int prodId)
        {
            ProdVendidoPorFranqueado pvpf = new ProdVendidoPorFranqueado();

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    ViewController.ProdVendidoPorFranqueado pv = (from p in ctx.ProdVendidoPorFranqueado where p.franq_id == franqId && p.prod_id == prodId select p).FirstOrDefault();
                    pvpf.franq_id       = Decimal.ToInt32(pv.franq_id);
                    pvpf.prod_id        = pv.prod_id;
                    pvpf.preco_unitario = pv.preco_unitario;
                    pvpf.qtd_vendas     = pv.qtd_vendas.GetValueOrDefault();
                    pvpf.stock_max      = pv.stock_max.GetValueOrDefault();
                    pvpf.stock_min      = pv.stock_min.GetValueOrDefault();
                    pvpf.stock_total    = pv.stock_total.GetValueOrDefault();
                }
            }
            return(pvpf);
        }
コード例 #30
0
        public List <AvgSale> AvgSalesInPresentYear(int prodId)
        {
            List <AvgSale> avgSales;

            using (var das = new DataAccessScope(true))
            {
                using (var ctx = new SI2_Bom_e_BaratoEntities())
                {
                    avgSales = ctx.ProdVendidoPorFranqueado
                               .Where(p => p.prod_id == prodId)
                               .GroupBy(p => p.prod_id, r => r.qtd_vendas)
                               .Select(g => new AvgSale()
                    {
                        ProdId = g.Key,
                        Avg    = g.Average() ?? 0.0
                    }).ToList();;
                }
            }
            return(avgSales);
        }