示例#1
0
 public void DropInspection(object e)
 {
     if (SelectedInspection == null)
     {
         MessageBox.Show("Не выбрана инспекция");
     }
     else
     {
         using (var con = new UserContext())
         {
             try
             {
                 foreach (var i in SelectedInspection.Remarks)
                 {
                     con.Remarks.Remove(con.Remarks.Find(i.Id));
                     con.SaveChanges();
                 }
                 con.Inspections.Remove(con.Inspections.Find(SelectedInspection.Id));
                 con.SaveChanges();
             }
             catch (Exception exception)
             {
                 MessageBox.Show(exception.ToString());
             }
             FilterInspections.Remove(SelectedInspection);
             Inspections.Remove(SelectedInspection);
         }
     }
 }
示例#2
0
 public void Filter()
 {
     if (NameInfo != null && FilterInspector != null)
     {
         if (FilterInspector.Id != -1)
         {
             FilterInspections.Clear();
             foreach (var element in Inspections)
             {
                 if (element.Inspector.Id == FilterInspector.Id && element.InspectionName.Name.Contains(NameInfo))
                 {
                     FilterInspections.Add(element.ShallowCopy());
                 }
             }
             return;
         }
     }
     if (NameInfo != null)
     {
         FilterInspections.Clear();
         foreach (var element in Inspections)
         {
             if (element.InspectionName.Name.Contains(NameInfo))
             {
                 FilterInspections.Add(element.ShallowCopy());
             }
         }
         return;
     }
     if (FilterInspector != null)
     {
         if (FilterInspector.Id != -1)
         {
             FilterInspections.Clear();
             foreach (var element in Inspections)
             {
                 if (element.Inspector.Id == FilterInspector.Id)
                 {
                     FilterInspections.Add(element.ShallowCopy());
                 }
             }
         }
         else
         {
             foreach (var element in Inspections)
             {
                 FilterInspections.Add(element.ShallowCopy());
             }
         }
     }
 }
示例#3
0
        public void Init()
        {
            using (var con = new UserContext())
            {
                var i = con.Inspections.Include("InspectionName")
                        .Include("Remarks").Select(x => new
                {
                    Id      = x.Id,
                    Date    = x.Date,
                    Comment = x.Comment,
                    Rm      = x.Remarks.Select(o => new
                    {
                        Id         = o.Id,
                        Date       = o.Date,
                        Comment    = o.Comment,
                        RemarkName = o.RemarkName != null ? new { Id = o.RemarkName.Id, Name = o.RemarkName.Name } : null
                    }),
                    InsName = x.InspectionName != null ? new { Id = x.InspectionName.Id, Name = x.InspectionName.Name } : null,
                    Inspect = x.Inspector != null ? new { Id = x.Inspector.Id, FIO = x.Inspector.FIO } : null
                })
                        .AsEnumerable().Select(y => new Inspection
                {
                    Id             = y.Id,
                    Date           = y.Date,
                    Comment        = y.Comment,
                    InspectionName = new InspectionName
                    {
                        Id   = y.InsName.Id,
                        Name = y.InsName.Name
                    },
                    Inspector = new Inspector
                    {
                        Id  = y.Inspect.Id,
                        FIO = y.Inspect.FIO
                    },
                    Remarks = y.Rm.Select(o => new Remark
                    {
                        Id         = o.Id,
                        Date       = o.Date,
                        Comment    = o.Comment,
                        RemarkName = o.RemarkName != null ? new RemarkName {
                            Id = o.RemarkName.Id, Name = o.RemarkName.Name
                        } : null
                    }).ToList().ToObservableCollection()
                }).ToList();
                Inspections = i.ToObservableCollection();
                foreach (var copy in Inspections)
                {
                    FilterInspections.Add(copy.ShallowCopy());
                }
            }

            using (var con = new UserContext())
            {
                var i = con.Inspectors.Select(x => new
                {
                    Id  = x.Id,
                    FIO = x.FIO
                }).AsEnumerable().Select(y => new Inspector
                {
                    Id  = y.Id,
                    FIO = y.FIO
                }).ToList();
                Inspectors = i.ToObservableCollection();
                //InfoInspectors = Inspectors.Select(x => x.ShallowCopy()).ToObservableCollection();
                InfoInspectors.Add(new Inspector
                {
                    Id  = -1,
                    FIO = "Все"
                });
                foreach (var index in Inspectors)
                {
                    InfoInspectors.Add(index.ShallowCopy());
                }
            }
        }