public EditProceduresWindow(ApplicationManager appMgr, Ward ward)
        {
            InitializeComponent();
            AppMgr = appMgr;
            Ward = ward;
            AllProcedures = new ObservableCollection<ProcedureType>();
            ChosenProcedures = new ObservableCollection<ProcedureType>();

            var procedures = AppMgr.ApplicationDb.ProcedureTypes.ToList();
            foreach (ProcedureType procedure in procedures)
                AllProcedures.Add(procedure);
            foreach (ProcedureType procedure in ward.Procedures)
            {
                ChosenProcedures.Add(procedure);
                AllProcedures.Remove(procedure);
            }

            DataContext = this;
        }
示例#2
0
        ///
        /// <param name="unit"></param>
        public void RemoveUnit(Unit unit)
        {
            Department dept = unit as Department;

            if (dept != null)
            {
                //if (unit.GetType() == AppManager.ApplicationDb.Departments.FirstOrDefault().GetType())
                //{
                foreach (Ward ward in dept.Wards)
                {
                    foreach (Employee emp in ward.Employees)
                    {
                        Hospital.Employees.Add(emp);
                    }

                    var ptype = (from p in AppManager.ApplicationDb.ProcedureTypes
                                 from w in p.Wards
                                 where w.Id == ward.Id
                                 select p).ToList();

                    foreach (var p in ptype)
                    {
                        p.Wards.Remove(ward);
                    }

                    var proc = (from p in AppManager.ApplicationDb.Procedures
                                where p.Ward.Id == ward.Id
                                select p).ToList();
                    foreach (var p in proc)
                    {
                        p.Ward = null;
                    }
                }
                foreach (Employee deptEmp in dept.Employees)
                {
                    Hospital.Employees.Add(deptEmp);
                }

                AppManager.ApplicationDb.Wards.RemoveRange(dept.Wards);
                AppManager.ApplicationDb.Departments.Remove(dept);
                AppManager.ApplicationDb.SaveChanges();
            }
            else
            {
                Ward ward = unit as Ward;
                if (ward != null)
                {
                    Unit parent = FindParentUnit(ward);
                    foreach (Employee emp in ward.Employees)
                    {
                        parent.Employees.Add(emp);
                    }

                    var ptype = (from p in AppManager.ApplicationDb.ProcedureTypes
                                 from w in p.Wards
                                 where w.Id == ward.Id
                                 select p).ToList();

                    foreach (var p in ptype)
                    {
                        p.Wards.Remove(ward);
                    }

                    var proc = (from p in AppManager.ApplicationDb.Procedures
                                where p.Ward.Id == ward.Id
                                select p).ToList();
                    foreach (var p in proc)
                    {
                        p.Ward = null;
                    }

                    AppManager.ApplicationDb.Wards.Remove(ward);
                    AppManager.ApplicationDb.SaveChanges();
                }
            }
        }