Esempio n. 1
0
        private void LoadData()
        {
            MiniSplash_TF sp0 = new MiniSplash_TF(Resources.load1) { Text = @"Загрузка данных", StatusText = @"Загрузка данных о событиях" };
            sp0.WorkingFunction = () =>
            {
                EventsDataContext context = new EventsDataContext();
                var data = context.EventsEntities.Events
                    .Include(i => i.CustomerSide)
                    .Include(i => i.EquipmentPort)
                    .Include(i => i.EquipmentPort.Equipment.Area)
                    .Where(ev => ev.CreationDate >= DbFunctions.AddDays(dpFrom.Value, -1) & ev.CreationDate <= DbFunctions.AddDays(dpTo.Value, 1));
                if (cbEventsAddData.Checked)
                {
                    _eventInfos =
                        (
                            from ev in data
                            from cust in context.EventsEntities.EventAndCustomersViews
                                .Where(c => c.Id == ev.Id)
                                .DefaultIfEmpty()
                            select new EventInfo()
                            {
                                Number = ev.Number,
                                Index = ev.EventIndex.HasValue ? ev.EventIndex.Value : 0,
                                Customer = cust.Title,
                                State = ev.State,
                                Address = ev.CustomerSide != null ? ev.CustomerSide.Description : ev.EquipmentPort != null ? ev.EquipmentPort.Equipment.Area.Description : string.Empty,
                                Description = ev.Description,
                                CreationDate = ev.CreationDate
                            }
                            ).OrderByDescending(o => o.CreationDate)
                            .ToList();
                }
                else
                {
                    _eventInfos = data.Select(ev => new EventInfo()
                    {
                        Number = ev.Number,
                        Index=ev.EventIndex.HasValue ? ev.EventIndex.Value: 0,
                        State=ev.State,
                        Address = ev.CustomerSide != null ? ev.CustomerSide.Description : ev.EquipmentPort != null ? ev.EquipmentPort.Equipment.Area.Description : string.Empty,
                        Description = ev.Description,
                        Customer=string.Empty,
                        CreationDate = ev.CreationDate
                    }).OrderByDescending(o => o.CreationDate).ToList();
                }
                Extensions.RunActionInGUIThread(() =>
                {
                    SetGridVisualStyle();
                    gvEvents.DataSource = _eventInfos;
                }, _uiScheduler);
            };
            sp0.ShowDialog(this);

        }
Esempio n. 2
0
 private void LoadReport()
 {
     _dataLoading = true;
     List<CustomerInfo> customers = new List<CustomerInfo>();
     MiniSplash_TF sp0 = new MiniSplash_TF(Resources.load1) { Text = @"Загрузка отчета", StatusText = @"Загрузка данных отчета" };
     _watch = null;
     sp0.WorkingFunction = () =>
     {
         NumEquipmentsDataContext numEquContext = new NumEquipmentsDataContext();
         if (_cachedCustomers==null)
             _cachedCustomers = numEquContext.NumEquipmentEntities.Customers.Where(cust => cust.Visible.HasValue && cust.Visible.Value).ToList();
         InstallersWorks_Entities context = new InstallersWorks_Entities();
         var data = context.InstallersWorks_Works
             .Include(i => i.InstallersWorks_WorkTypes);
         if (dpFrom.Enabled)
             data = data
                 .Where(w =>
                     DbFunctions.TruncateTime(w.WorkDate) >= DbFunctions.TruncateTime(dpFrom.Value) &
                     DbFunctions.TruncateTime(w.WorkDate) <= DbFunctions.TruncateTime(dpTo.Value));
         data = data.OrderByDescending(o => o.WorkDate);
         EventsDataContext eventsContext = new EventsDataContext();
         foreach (var grp in data.GroupBy(work => work.WorkId))
         {
             var firstWork = grp.FirstOrDefault();
             if (firstWork == default(InstallersWorks_Works))
             {
                 throw new InvalidDataException("getting firstWork");
             }
             if (!string.IsNullOrEmpty(firstWork.Event)) //авария
             {
                 var workEvent = eventsContext.EventsEntities.Events.FirstOrDefault(e => e.Number.ToString() == firstWork.Event);
                 if (workEvent==null)
                     throw new InvalidDataException("getting workEvent");
                 int firmId = workEvent.FirmId.HasValue ? workEvent.FirmId.Value : -1;
                 int customerId = workEvent.CustomerId.HasValue ? workEvent.CustomerId.Value : -1;
                 if (firmId<0 | customerId <0)
                     throw new InvalidDataException("getting customer info");
                 customers.Add(new CustomerInfo()
                 {
                     Address = firstWork.Address,
                     FirmId = firmId,
                     CustomerId = customerId,
                     WorkType = firstWork.InstallersWorks_WorkTypes.TypeDescription
                 });
             }
             else if (!string.IsNullOrEmpty(firstWork.AssNomer)) //наряд
             {
                 var workAssignment = numEquContext.NumEquipmentEntities.Assignments.SingleOrDefault(a => a.Nomer == firstWork.AssNomer);
                 if (workAssignment == null)
                     throw new InvalidDataException("getting workAssignment");
                 int firmId = workAssignment.FirmId;
                 int customerId = Convert.ToInt32(workAssignment.Customer_Id);
                 customers.Add(new CustomerInfo()
                 {
                     Address = firstWork.Address,
                     FirmId = firmId,
                     CustomerId = customerId,
                     WorkType = firstWork.InstallersWorks_WorkTypes.TypeDescription
                 });
             }
             else //другое
             {
                 customers.Add(new CustomerInfo()
                 {
                     Address = firstWork.Address,
                     Title = "Без номера договора",
                     FirmId = -1,
                     CustomerId = -1,
                     WorkType = firstWork.InstallersWorks_WorkTypes.TypeDescription
                 });
             }
         }
         foreach (CustomerInfo customerInfo in customers)
         {
             var cli = customerInfo;
             if (cli.FirmId != -1)
             {
                 var ci = _cachedCustomers.SingleOrDefault(c => c.FirmId == cli.FirmId & c.Customer_id.Trim() == cli.CustomerId.ToString());
                 customerInfo.Title = ci == null ? "Абонент удален" : ci.Title;
             }
         }
         _dataSet.PerAbonentDataSimple.Clear();
         foreach (CustomerInfo customerInfo in customers)
         {
             ReportDataSet.PerAbonentDataSimpleRow newRow = _dataSet.PerAbonentDataSimple.NewPerAbonentDataSimpleRow();
             newRow.Firmid = customerInfo.FirmId;
             newRow.CustomerId = customerInfo.CustomerId;
             newRow.Address = customerInfo.Address;
             newRow.WorkType = customerInfo.WorkType;
             newRow.Title = customerInfo.Title;
             _dataSet.PerAbonentDataSimple.AddPerAbonentDataSimpleRow(newRow);
         }
         Extensions.RunActionInGUIThread(() =>
         {
             sp0.StatusText = @"Обновление отчета";
             SetReportSource();
         }, _uiScheduler);
     };
     sp0.ShowDialog(this);
     _dataLoading = false;
 }