示例#1
0
        public void Start()
        {
            Status = "Получение данных";

            DateTime today         = DateTime.Today;
            DateTime month         = new DateTime(today.Year, today.Month, 1);
            DateTime prevMonth     = month.AddMonths(-1);
            DateTime prevPrevMonth = month.AddMonths(-2);

            var enterprises = Webservice.GetEnterprises();
            var flat        = enterprises.SelectMany(i => i.ChildEnterprises);
            var fes         = flat.Where(i => i.EnterpriseName == "ОЭС");
            var reses       = fes.SelectMany(i => i.ChildEnterprises);

            Enterprises = new List <EnterpriseViewItem>(reses);
            Enterprises.Insert(0, fes.First());

            /*var q1 = Webservice.GetSmallEngineObjects(prevMonth, prevPrevMonth, "ОшРЭС");
             * var qqq = q1.Items[0].LastSession;
             *
             * var q2 = Webservice.GetMeterProblemInformations(OrderRule.ByLastUpdate);
             *
             * //var q3 = Webservice.GetIndicationsAnalyzing(prevMonth, prevPrevMonth, Profile.Days);
             *
             * var q4 = Webservice.Statistics(Profile.Months, 0, prevMonth, prevPrevMonth);
             *
             * var q5 = Webservice.SmallEngineStatistics(Profile.Months, 0, prevMonth, prevPrevMonth);
             *
             * var q6 = Webservice.GetCollectorDevicesReport();
             *
             * var q7 = Webservice.GetChildElementsInHouseHoldSector("e19");
             *
             *
             * var t = Webservice.GetCountersGroupInformations("ОшРЭС");*/

            DetailedStatus = "получение информации по абонентам ...";
            IEnumerable <Subscriber> subscribers = Webservice.GetSubscribers();

            var groupedSubscribers = subscribers.GroupBy(i => i.SubscribersType).Select(i => new { Key = i.Key, Count = i.Count(), Items = i.ToList() });

            var sesSubscribers = groupedSubscribers.Where(i => i.Key == "");

            DetailedStatus = "получение расходов ...";
            List <AllTariffsExportIndicationViewItem> indications = Webservice.GetSmallEngineExportIndications(prevMonth);

            DetailedStatus = "получение информации по абонентам ...";
            IEnumerable <SmallEngineBillingObject> objects = Webservice.GetSmallEngineBillingObjects();

            var groupedObjects = objects.GroupBy(i => i.ResName).Select(i => new { Key = i.Key, Count = i.Count(), Items = i.ToList() });

            var emp = objects.Where(i => i.BillingPointPersonalAccount != 0);

            DetailedStatus = "подготовка списка ...";
            List <SmallEngineDataModel> list = new List <SmallEngineDataModel>();

            if (indications != null)
            {
                SmallEngineDataModel dataItem;

                List <AllTariffsExportIndicationViewItem> notFoundedAccounts = new List <AllTariffsExportIndicationViewItem>();
                foreach (AllTariffsExportIndicationViewItem item in indications)
                {
                    if (item.PersonalAccount != 0)
                    {
                        //SmallEngineBillingObject obj1 = Webservice.GetPersonalAccountInfoFromAmper(item.PersonalAccount);

                        SmallEngineBillingObject obj = objects.FirstOrDefault(i => i.BillingPointPersonalAccount == item.PersonalAccount);
                        if (obj != null)
                        {
                            dataItem = new SmallEngineDataModel(obj);
                            dataItem.SetIndications(item);
                            list.Add(dataItem);
                        }
                        else
                        {
                            notFoundedAccounts.Add(item);
                        }
                    }
                    else
                    {
                        dataItem = new SmallEngineDataModel()
                        {
                            BillingPointPersonalAccount = item.PersonalAccount
                        };
                        dataItem.SetIndications(item);
                        list.Add(dataItem);
                    }
                }

                List <SmallEngineDataModel> found    = new List <SmallEngineDataModel>();
                List <SmallEngineDataModel> notfound = new List <SmallEngineDataModel>();
                foreach (var item in list)
                {
                    if (reses.Any(res => res.EnterpriseName == item.ResName))
                    {
                        found.Add(item);
                    }
                    else
                    {
                        notfound.Add(item);
                    }
                }

                View = CollectionViewSource.GetDefaultView(found);
            }
        }