示例#1
0
        private void UpdateWindow()
        {
            eid = (int)App.Current.Properties["UserId"];

            //User logging out
            if ((string)App.Current.Properties["CloseWindow"] == "Close")
            {
                this.Close();
            }

            lblName.Content = App.Current.Properties["User"];

            DataRowView drv = (DataRowView)App.Current.Properties["thisProject"];
            txtblTitle.Text = (string)drv["projectname"];
            pid = (int)drv["pid"];            
            

            ProjectMaster2016.projectmasterDataSet projectmasterDataSet = ((ProjectMaster2016.projectmasterDataSet)(this.FindResource("projectmasterDataSet")));
            projectmasterDataSetTableAdapters.projectTableAdapter pta = new projectmasterDataSetTableAdapters.projectTableAdapter();
            try 
            { 
                // fill view with selectd project
                pta.FillByProjectId(projectmasterDataSet.project, pid);
                System.Windows.Data.CollectionViewSource projectViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("projectViewSource")));
                projectViewSource.View.MoveCurrentToFirst();
            }
            catch { }

            //disable edit, remove and add projectemployee -> if user is not owner/creator of project
            int isOwner = (int)pta.GetProjectOwner(pid);
            if (isOwner != eid)
            {
                btnRemoveProject.Visibility = Visibility.Collapsed;
                btnEditProject.Visibility = Visibility.Collapsed;
                btnAddProjectEmployee.Visibility = Visibility.Collapsed;
                btnRemoveProjectEmployee.Visibility = Visibility.Collapsed;

            }

            lblEmp.Content = pta.GetEmployeeName((int)drv["pid"]);

            //display project status finished/unfinished
            bool status = (bool)drv["projectisfinished"];
            if (status == false)
            {
                lblStatus.Content = "Í vinnslu";
            }
            else
            {
                lblStatus.Content = "Lokið";
            }

            //display creationdate
            try
            {
                DateTime created = (DateTime)drv["pdate"];
                if (created != null)
                {
                    lblCreated.Content = created.ToLongDateString();
                }
            }
            catch
            {
            }

            //display deadline
            try
            {
                DateTime due = (DateTime)drv["pdeadline"];
                lblDue.Content = due.ToLongDateString();
            }
            catch
            {
                lblDue.Content = "Ekki tilgreint";
            }


            ProjectMaster2016.projectmasterDataSetTableAdapters.project_employeesTableAdapter peta = new ProjectMaster2016.projectmasterDataSetTableAdapters.project_employeesTableAdapter();
            try
            {
                //fill  relatedentries -> messages, costs and hours
                peta.FillByAllRelatedEntries(projectmasterDataSet.project_employees, pid);
                System.Windows.Data.CollectionViewSource project_employeesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("project_employeesViewSource")));
                project_employeesViewSource.View.MoveCurrentToFirst();
            }
            catch (Exception)
            {

            }

            // display statistics
            try { lblentriesCount.Content = (int)pta.CountOfRelatedProjectEntries(pid); }
            catch { }
            try { lbltotalHours.Content = (decimal)pta.CountOfProjectHours(pid); }
            catch { }
            try { lbltotalCost.Content = (int)pta.SumOfProjectCosts(pid); }
            catch { }
            
            //fill for add projectemployeelistbox
            try 
            { 
                ProjectMaster2016.projectmasterDataSetTableAdapters.employeeTableAdapter projectmasterDataSetemployeeTableAdapter = new ProjectMaster2016.projectmasterDataSetTableAdapters.employeeTableAdapter();
                projectmasterDataSetemployeeTableAdapter.FillByProjectEmployeeName(projectmasterDataSet.employee, pid);
                System.Windows.Data.CollectionViewSource employeeViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("employeeViewSource")));
                employeeViewSource.View.MoveCurrentToFirst();
            }
            catch { }
        }