예제 #1
0
        public List <Expense> GetExpenses()
        {
            using (DeskAssemblyEntities context = DbContextCreator.Create())
            {
                //Expense테이블에서 가져옴(이걸로 끝) 3건은 이걸로!!!!
                List <Expense> expenses = context.Expenses.ToList();

                //자원구매비는 이걸로 계산,x=order
                var query = from x in context.Orders
                            where x.IsSale == false
                            select new { Date = x.Date, Cost = x.Quantity * x.Item.Price };

                //갯수보기위한식(없어도됨)
                var list = query.ToList();

                //x=이름없는익명타입(여기안에는 cost,date라는 속성이있음)
                foreach (var x in list)
                {
                    Expense resourceExpense = new Expense();
                    resourceExpense.Name = "자원구매비";
                    resourceExpense.Date = x.Date;
                    resourceExpense.Cost = x.Cost;

                    expenses.Add(resourceExpense);
                }

                return(expenses);
            }
        }
예제 #2
0
        public List <Order> Pivot()
        {
            using (DeskAssemblyEntities context = DbContextCreator.Create())
            {
                var query = from x in context.Orders
                            select new
                {
                    Order        = x,
                    ItemName     = x.Item.Name,
                    ContractName = x.Contract.Name,
                    CountryName  = x.Contract.Country.Name,
                    ItemPrice    = x.Item.Price
                };

                var list = query.ToList();

                List <Order> orders = new List <Order>();

                foreach (var x in list)
                {
                    x.Order.ItemName     = x.ItemName;
                    x.Order.ContractName = x.ContractName;
                    x.Order.CountryName  = x.CountryName;
                    x.Order.ItemPrice    = x.ItemPrice;

                    orders.Add(x.Order);
                }

                return(orders);
            }
        }
예제 #3
0
        //국가별 부품 구매량 상세 모델
        //public List<MapChartDetailModel> GetPurchasedCountryDetailModels(int countryId)
        //{
        //    using (var context = DbContextCreator.Create())
        //    {
        //        var Orders = context.Orders.ToList();

        //        var query = from x in context.Orders
        //                    where x.Contract.CountryId == countryId && x.IsSale == false
        //                    select new { Quantity = x.Quantity, ContractName = x.Contract.Name, ItemName = x.Item };
        //    }

        //}

        public List <Order> Search()
        {
            using (DeskAssemblyEntities context = DbContextCreator.Create())
            {
                var query = from x in context.Orders
                            select new
                {
                    Order        = x,
                    ItemName     = x.Item.Name,
                    TeamName     = x.Team.Name,
                    ContractName = x.Contract.Name,
                    IsSaleName   = x.IsSale
                };

                var list = query.ToList();
                foreach (var item in list)
                {
                    item.Order.ItemName     = item.ItemName;
                    item.Order.TeamName     = item.TeamName;
                    item.Order.ContractName = item.ContractName;
                    if (item.Order.IsSale == true)
                    {
                        item.Order.IsSaleName = "판매";
                    }
                    else
                    {
                        item.Order.IsSaleName = "구매";
                    }
                }
                return(list.Select(x => x.Order).ToList());
            }
        }
예제 #4
0
        public List <OrderModel> OrderModels()
        {
            using (DeskAssemblyEntities context = DbContextCreator.Create())
            {
                var query = from p in context.Orders
                            where p.IsSale == true
                            select new
                {
                    Order         = p,
                    Price         = p.Item.Price,
                    Quantity      = p.Quantity,
                    Month         = p.Date.Month,
                    QuantityPrice = p.Quantity * p.Item.Price,
                };

                var query2 = from x in query
                             group x by x.Month into g
                             select g;

                List <OrderModel> models = new List <OrderModel>();

                foreach (var @group in query2)
                {
                    OrderModel model = new OrderModel();
                    model.Month         = group.Key;
                    model.QuantityPrice = group.Sum(g => g.QuantityPrice);
                    if (model.Month != 1)
                    {
                        model.ProfitRate = (((model.QuantityPrice - models[models.Count - 1].QuantityPrice) * 1.0) / models[models.Count - 1].QuantityPrice) * 100;
                    }
                    models.Add(model);
                }

                return(models);
            }
        }