コード例 #1
0
        public ViewModelEmployee(MainWindow Handle)
        {
            _Handle = Handle;

            using (_EmpContext = new finalDBEContext(MainWindow.ConnectionString))
            {
                _Handle.LabelHost.Content = _EmpContext.Database.Connection.DataSource.ToString();
                _Handle.LabelDatabase.Content = _EmpContext.Database.Connection.Database.ToString();
            }
        }
コード例 #2
0
        public bool BindToClass()
        {
            try
            {
                using (_EmpContext = new finalDBEContext(MainWindow.ConnectionString))
                {
                    foreach (var D in _EmpContext.Departments)
                    {
                        _DeptCol.Add(new CDepartment(D as Department));
                    }
                }
            }
            catch
            {
                _Handle.InfoBox.Content = "An Error has Occured while loading Departments";
                return false;
            }

            try
            {
                using (_EmpContext = new finalDBEContext(MainWindow.ConnectionString))
                {
                    foreach (var D in _EmpContext.DepartmentPositions)
                    {
                        _DeptPosCol.Add(new CPosition(D as DepartmentPosition));
                    }
                }
            }
            catch
            {
                _Handle.InfoBox.Content = "An Error has Occured while loading Department Positions";
                return false;
            }

            try
            {
                using (_EmpContext = new finalDBEContext(MainWindow.ConnectionString))
                {
                    foreach (var E in _EmpContext.Employees)
                    {
                        CEmployee Emp = new CEmployee(E as Employee);
                        foreach (CPosition P in _DeptPosCol)
                        {
                            if (P.PositionID == E.PositionID)
                            {
                                Emp.Position = P;
                                break;
                            }
                        }
                        foreach (CDepartment D in _DeptCol)
                        {
                            if (D.ID == Emp.Position.DepartmentID)
                            {
                                Emp.Dept = D;
                                break;
                            }
                        }
                        _EmpCol.Add(Emp);
                    }
                }
            }
            catch(SyntaxErrorException e)
            {
                _Handle.InfoBox.Content = "An Error has Occured while loading Employees. Message:" + e.Message;
                return false;
            }
            _Handle.InfoBox.Content = "Employee Loading: Successiful";
            return true;
        }