public ActionResult ShowAllMeterTypes()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model        = new MeterTypeModel();
                var meterTypesDB = context.METER_TYPE.ToList();

                foreach (var mt in meterTypesDB)
                {
                    var utilityDB = context.UTILITY.Where(u => u.ID == mt.UTILITY_ID).FirstOrDefault();
                    var utility   = new Utility()
                    {
                        Id = utilityDB.ID, Name = utilityDB.NAME, ImageIconPath = CustomizedMethod.GetUtilityImage(utilityDB.ID)
                    };

                    model.MeterTypes.Add(new MeterType()
                    {
                        Id = mt.ID, Name = mt.NAME, VarificationPeriod = mt.VARIFICATION_PERIOD_YEARS, Utility = utility
                    });
                }
                var view = View("~/Views/Meter/ShowAllMeterTypes.cshtml", model);

                return(view);
            }
        }
        public ActionResult ShowUtility(string utilityName)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var utilityDB   = context.UTILITY.Where(u => u.NAME == utilityName).FirstOrDefault();
                var unitDB      = context.UNIT.Find(utilityDB.UNIT_ID);
                var utilitiesDB = context.UTILITY.ToList();

                var model = new UtilityModel();
                model.Unit.Id   = unitDB.ID;
                model.Unit.Name = unitDB.NAME;

                model.Utility.Id            = utilityDB.ID;
                model.Utility.Name          = utilityDB.NAME;
                model.Utility.Price         = utilityDB.PRICE;
                model.Utility.ImageIconPath = CustomizedMethod.GetUtilityImage(utilityDB.ID);

                if (utilityDB.USAGEFORSTANDARTPRICE != null)
                {
                    model.Utility.UsageForStandartPrice = (decimal)utilityDB.USAGEFORSTANDARTPRICE;
                }
                if (utilityDB.BIGUSAGEPRICE != null)
                {
                    model.Utility.BigUsagePrice = (decimal)utilityDB.BIGUSAGEPRICE;
                }

                model.Utility.Unit = model.Unit;

                foreach (var u in utilitiesDB)
                {
                    if (u.NAME != model.Utility.Name)
                    {
                        model.Utilities.Add(new Utility()
                        {
                            Name = u.NAME
                        });
                    }
                }

                var           meterTypesDB  = context.METER_TYPE.Where(mt => mt.UTILITY_ID == model.Utility.Id).ToList();
                var           metersDB      = context.METER.ToList();
                HashSet <int> meterTypesIds = new HashSet <int>();

                foreach (var m in meterTypesDB)
                {
                    meterTypesIds.Add(m.ID);
                }

                foreach (var m in metersDB)
                {
                    if (meterTypesIds.Contains(m.METER_TYPE_ID))
                    {
                        model.MeterQty += 1;
                    }
                }

                var view = View("~/Views/Utility/ShowUtility.cshtml", model);
                return(view);
            }
        }
Exemplo n.º 3
0
        public ActionResult ShowBill(int bill_Id)
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model = new BillModel();

                int   customerId         = 0;
                float consumedMonthValue = 0;
                float utilityCharges     = 0;

                var billDB = context.BILL.Find(bill_Id);

                if (billDB != null)
                {
                    model.Bill = new Bill()
                    {
                        Id = billDB.ID, Number = billDB.NUMBER, Date = billDB.DATE, Period = CustomizedMethod.GetFullMonthName(billDB), Sum = billDB.SUM, Paid = billDB.PAID
                    };
                    customerId = billDB.CUSTOMER_ID;
                }

                DateTime startDate          = new DateTime();
                DateTime finishDate         = new DateTime();
                DateTime startDateForChart  = new DateTime();
                DateTime finishDateForChart = new DateTime();

                startDate  = Convert.ToDateTime(model.Bill.Period + "-01");
                finishDate = startDate.AddMonths(1);

                int monthDifferenceBillPeriodAndStartUsageChart = 1;
                int presChartYear  = startDate.Year;
                int startChartDay  = 1;
                int prevChartYear  = presChartYear - 1;
                int presChartMonth = startDate.Month;

                float  valueDifference;
                string monthName;

                var customerDB = context.CUSTOMER.Where(c => c.ID == customerId).FirstOrDefault();

                if (customerDB != null)
                {
                    GetCustomerDataForView(context, model, customerDB);
                }
                else
                {
                    model.CustomerModel.Customer = null;
                }

                var metersDB = context.METER.Where(m => m.ADDRESS_ID == model.CustomerModel.Customer.Address.Id).ToList();

                List <MeterItem> meterListDB = new List <MeterItem>();

                foreach (var m in metersDB)
                {
                    List <ChartData> chartData = new List <ChartData>();
                    meterListDB.Clear();

                    startDateForChart  = new DateTime(prevChartYear, presChartMonth + monthDifferenceBillPeriodAndStartUsageChart, startChartDay);
                    finishDateForChart = startDate.AddMonths(1);

                    var meterTypeDB = context.METER_TYPE.Where(mt => mt.ID == m.METER_TYPE_ID).FirstOrDefault();
                    var utilityDB   = context.UTILITY.Where(u => u.ID == meterTypeDB.UTILITY_ID).FirstOrDefault();
                    var unitDB      = context.UNIT.Where(u => u.ID == utilityDB.UNIT_ID).FirstOrDefault();

                    var unit = new Unit()
                    {
                        Id = unitDB.ID, Name = unitDB.NAME
                    };
                    var utility = new Utility()
                    {
                        Id = utilityDB.ID, Name = utilityDB.NAME, Unit = unit, Price = utilityDB.PRICE, ImageIconPath = CustomizedMethod.GetUtilityImage(utilityDB.ID)
                    };

                    if (utilityDB.USAGEFORSTANDARTPRICE != null)
                    {
                        utility.UsageForStandartPrice = (decimal)utilityDB.USAGEFORSTANDARTPRICE;
                    }
                    if (utilityDB.BIGUSAGEPRICE != null)
                    {
                        utility.BigUsagePrice = (decimal)utilityDB.BIGUSAGEPRICE;
                    }

                    if (utility.Id == (int)Utilities.Heating)
                    {
                        GetTemperatureHistory(context, model, m);
                    }

                    var meterItemsDB = (from mi in context.METER_ITEM
                                        where mi.METER_ID == m.ID
                                        select mi).ToList();

                    foreach (var i in meterItemsDB)
                    {
                        meterListDB.Add(new MeterItem()
                        {
                            Id = i.ID, Date = i.DATE, Value = i.VALUE
                        });
                    }

                    if (meterItemsDB.Count != 0)
                    {
                        for (; startDateForChart <= finishDateForChart; startDateForChart = startDateForChart.AddMonths(1))
                        {
                            var startElValue  = meterListDB.Where(ml => ml.Date == startDateForChart.AddMonths(-1)).FirstOrDefault().Value;
                            var finishElValue = meterListDB.Where(ml => ml.Date == startDateForChart).FirstOrDefault().Value;
                            valueDifference = (float)Math.Round(finishElValue - startElValue, 2);

                            if (startDateForChart.Month != 1)
                            {
                                Months month = (Months)(startDateForChart.Month - 1);
                                monthName = month.ToString() + " " + startDateForChart.Year;
                            }
                            else
                            {
                                Months month = Months.December;
                                monthName = month.ToString() + " " + startDateForChart.AddYears(-1).Year;
                            }

                            chartData.Add(new ChartData()
                            {
                                MonthName = monthName, Value = valueDifference
                            });
                        }
                    }

                    var meterType = new MeterType()
                    {
                        Id = meterTypeDB.ID, Name = meterTypeDB.NAME, Utility = utility
                    };

                    var startMeterItem = (from item in context.METER_ITEM
                                          where item.METER_ID == m.ID && item.DATE == startDate
                                          select item).FirstOrDefault();

                    var finishMeterItem = (from item in context.METER_ITEM
                                           where item.METER_ID == m.ID && item.DATE == finishDate
                                           select item).FirstOrDefault();

                    consumedMonthValue = finishMeterItem.VALUE - startMeterItem.VALUE;

                    if (m.METER_TYPE.UTILITY_ID == (int)Utilities.Electricity && consumedMonthValue > (float)m.METER_TYPE.UTILITY.USAGEFORSTANDARTPRICE)
                    {
                        utilityCharges = (float)m.METER_TYPE.UTILITY.USAGEFORSTANDARTPRICE * (float)m.METER_TYPE.UTILITY.PRICE + (consumedMonthValue - (float)m.METER_TYPE.UTILITY.USAGEFORSTANDARTPRICE) * (float)m.METER_TYPE.UTILITY.BIGUSAGEPRICE;
                    }

                    else
                    {
                        utilityCharges = consumedMonthValue * (float)m.METER_TYPE.UTILITY.PRICE;
                    }

                    model.UtilityChargesChartData.Add(new ChartData()
                    {
                        UtilityCharges = (float)Math.Round(utilityCharges, 2)
                    });

                    model.CustomerModel.Meters.Add(
                        new Meter()
                    {
                        Id                 = m.ID,
                        SerialNumber       = m.SERIAL_NUMBER,
                        ReleaseDate        = m.RELEASE_DATE,
                        VarificationDate   = m.VARIFICATION_DATE,
                        MeterType          = meterType,
                        ConsumedMonthValue = consumedMonthValue,
                        ChartData          = chartData
                    });
                }
                return(View(model));
            }
        }
        private static CalculatorItemModel AddUtilitiesToModel(TownUtilityBillSystemEntities context)
        {
            var model       = new CalculatorItemModel();
            var utilitiesDB = context.UTILITY.ToList();

            foreach (var item in utilitiesDB)
            {
                var unitDB = context.UNIT.Where(u => u.ID == item.UNIT_ID).FirstOrDefault();
                var unit   = new Unit()
                {
                    Id = unitDB.ID, Name = unitDB.NAME
                };

                if (item.USAGEFORSTANDARTPRICE != null && item.BIGUSAGEPRICE != null)
                {
                    model.Utilities.Add(new Utility {
                        Id = item.ID, Name = item.NAME, Price = item.PRICE, BigUsagePrice = (decimal)item.BIGUSAGEPRICE, UsageForStandartPrice = Math.Round((decimal)item.USAGEFORSTANDARTPRICE, 0), ImageIconPath = CustomizedMethod.GetUtilityImage(item.ID), Unit = unit
                    });
                }

                else
                {
                    model.Utilities.Add(new Utility {
                        Id = item.ID, Name = item.NAME, Price = item.PRICE, ImageIconPath = CustomizedMethod.GetUtilityImage(item.ID), Unit = unit
                    });
                }
            }

            return(model);
        }
        public ActionResult ShowAllUtilitiesPrices()
        {
            using (var context = new TownUtilityBillSystemEntities())
            {
                var model       = new UtilityModel();
                var utilitiesDB = context.UTILITY.ToList();

                foreach (var item in utilitiesDB)
                {
                    var unitDB = context.UNIT.Where(u => u.ID == item.UNIT_ID).FirstOrDefault();
                    var unit   = new Unit()
                    {
                        Id = unitDB.ID, Name = unitDB.NAME
                    };

                    if (item.USAGEFORSTANDARTPRICE != null && item.BIGUSAGEPRICE != null)
                    {
                        model.Utilities.Add(new Utility {
                            Id = item.ID, Name = item.NAME, Price = item.PRICE, BigUsagePrice = (decimal)item.BIGUSAGEPRICE, UsageForStandartPrice = Math.Round((decimal)item.USAGEFORSTANDARTPRICE, 0), ImageIconPath = CustomizedMethod.GetUtilityImage(item.ID), Unit = unit
                        });
                    }

                    else
                    {
                        model.Utilities.Add(new Utility {
                            Id = item.ID, Name = item.NAME, Price = item.PRICE, ImageIconPath = CustomizedMethod.GetUtilityImage(item.ID), Unit = unit
                        });
                    }
                }
                return(View(model));
            }
        }