示例#1
0
        /// <summary>
        /// Populate Kasa tab
        /// </summary>
        /// <param name="customerList">List of <see cref="Customer"/></param>
        public void WriteKasaTab(List <Customer> customerList)
        {
            if (customerList == null)
            {
                return;
            }

            List <object> header = new List <object> {
                "Id", "Ime i prezime", "Suma"
            };
            ValueRange kasaData = new ValueRange {
                Values = new List <IList <object> > {
                    header
                }
            };

            foreach (var customer in customerList)
            {
                kasaData.Values.Add(new List <object>
                {
                    customer.Id,
                    customer.Name,
                    customer.Orders.Where(o => o.Meal.Foods[0].Restaurant.Name == Restaurant.Name).Sum(o => o.Price)
                });
            }

            GoogleSheetService.Clear(SheetId, _kasaSheet);
            GoogleSheetService.Update(kasaData, SheetId, _kasaSheet);
        }
示例#2
0
        public override void WriteMenu(List <Food> foods)
        {
            var header = new List <object> {
                "Naziv jela", "Opis", "Cena", "Tip"
            };
            var foodRange = new ValueRange {
                Values = new List <IList <object> > {
                    header
                }
            };

            foreach (var food in foods)
            {
                foodRange.Values.Add(new List <object>
                {
                    food.Name,
                    food.Description,
                    food.Price,
                    GetLocalFoodType(food.Type)
                });
            }

            // Clear sheet and write new data
            GoogleSheetService.Clear(_sheetId, FoodListSheet);
            GoogleSheetService.Update(foodRange, _sheetId, FoodListSheet);
        }
示例#3
0
        /// <summary>
        /// Populate Orders tab in sheet with new order data
        /// </summary>
        /// <param name="orders">List of orders to write</param>
        public void PlaceOrders(List <Order> orders)
        {
            if (orders == null)
            {
                throw new ArgumentNullException(nameof(orders));
            }

            var header = new List <object> {
                "Jelo", "Komada", "Cena", "Cena Ukupno", "Narucili"
            };
            var orderRange = new ValueRange {
                Values = new List <IList <object> > {
                    header
                }
            };

            List <Food> listOFOrderdFood = new List <Food>();

            foreach (var order in orders)
            {
                foreach (var food in order.Meal.Foods)
                {
                    listOFOrderdFood.Add(food);
                }
            }

            var distinctFood = listOFOrderdFood.GroupBy(f => f.Id).Select(o => o.FirstOrDefault());
            int rowCounter   = 2; // First row with orders, used for formula

            foreach (var food in distinctFood)
            {
                var customerList = new List <object>();
                var formatedData = new List <object>();

                foreach (var order in orders)
                {
                    if (order.Meal.Foods.FirstOrDefault(f => f.Name == food.Name) != null)
                    {
                        if (!string.IsNullOrEmpty(order.Note))
                        {
                            customerList.Add(order.Customer.Name + "(" + order.Note + ")");
                        }
                        else
                        {
                            customerList.Add(order.Customer.Name);
                        }
                    }
                }

                formatedData.Add(food.Name);
                formatedData.Add(customerList.Count);
                formatedData.Add(food.Price);
                formatedData.Add($"=B{rowCounter}*C{rowCounter}"); // Add formula to sum
                rowCounter++;
                formatedData.AddRange(customerList);
                orderRange.Values.Add(formatedData);
            }

            GoogleSheetService.Clear(SheetId, OrdersSheet);
            GoogleSheetService.Update(orderRange, SheetId, OrdersSheet);
        }
示例#4
0
        /// <summary>
        /// Setup daily menu sheet, making today first column
        /// </summary>
        public void DnevniMenuSheetSetup()
        {
            // Get data
            ValueRange sheetData = GoogleSheetService.GetColumns(SheetId, DailyMenuSheet);

            DateTime dateCounter = DateTime.Today;

            var sheetValues = sheetData.Values;
            var dayOfWeek   = GetLocalDayName(dateCounter.DayOfWeek);
            int today       = 0;

            for (int i = 0; i < sheetValues.Count; i++)
            {
                if (sheetValues[i][0].ToString() == dayOfWeek)
                {
                    today = i;
                }
            }

            ValueRange updatedRange = new ValueRange {
                Values = new List <IList <object> >()
            };
            const int daysToAdd = 0;

            // Insert today and after
            for (int i = today; i < sheetValues.Count; i++)
            {
                sheetValues[i][1] = dateCounter.AddDays(daysToAdd).ToString("dd-MM-yyyy");
                updatedRange.Values.Add(sheetValues[i]);
                if (dateCounter.DayOfWeek == DayOfWeek.Friday)
                {
                    dateCounter = dateCounter.AddDays(3);
                }
                else
                {
                    dateCounter = dateCounter.AddDays(1);
                }
            }

            // Insert before today
            for (int k = 0; k < today; k++)
            {
                sheetValues[k][1] = dateCounter.AddDays(daysToAdd).ToString("dd-MM-yyyy");
                updatedRange.Values.Add(sheetValues[k]);
                if (dateCounter.DayOfWeek == DayOfWeek.Friday)
                {
                    dateCounter = dateCounter.AddDays(3);
                }
                else
                {
                    dateCounter = dateCounter.AddDays(1);
                }
            }

            // Transpose values
            ValueRange formatedRange = new ValueRange {
                Values = new List <IList <object> >()
            };

            bool empty  = true;
            int  rowNum = 0;

            do
            {
                empty = true;
                List <object> row = new List <object>();
                for (int i = 0; i < updatedRange.Values.Count; i++)
                {
                    if (updatedRange.Values[i].Count > rowNum)
                    {
                        row.Add(updatedRange.Values[i][rowNum].ToString());
                        empty = false;
                    }
                    else
                    {
                        row.Add(string.Empty);
                    }
                }

                if (!empty)
                {
                    formatedRange.Values.Add(row);
                    rowNum++;
                }
            }while (!empty);

            GoogleSheetService.Clear(SheetId, DailyMenuSheet);
            GoogleSheetService.Update(formatedRange, SheetId, DailyMenuSheet);
        }