private void UpdateWindow()
        {   
            //
            //The selected project to edit from ProjectMessagesWindow
            //
            DataRowView drv = (DataRowView)App.Current.Properties["projectMessage"];
            int pmid = (int)drv["pmid"];

            string role = (string)App.Current.Properties["Role"];
            if (role == "user" || role == "poweruser")
            {
                btnEditProjectMessageProject.Visibility = Visibility.Collapsed;
                btnEditProjectMessageEmployee.Visibility = Visibility.Collapsed;
            }
            ProjectMaster2016.projectmasterDataSet projectmasterDataSet = ((ProjectMaster2016.projectmasterDataSet)(this.FindResource("projectmasterDataSet")));
            // Load data into the table project_costs. You can modify this code as needed.
            ProjectMaster2016.projectmasterDataSetTableAdapters.project_messagesTableAdapter projectmasterDataSetproject_messagesTableAdapter = new ProjectMaster2016.projectmasterDataSetTableAdapters.project_messagesTableAdapter();

            try
            {
                //
                //Fill message details
                //
                projectmasterDataSetproject_messagesTableAdapter.FillByProjectMessageId(projectmasterDataSet.project_messages, pmid);
                System.Windows.Data.CollectionViewSource project_messagesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("project_messagesViewSource")));
                project_messagesViewSource.View.MoveCurrentToFirst();
            }
            catch (Exception ) { }
            
            //
            //Check if user has selected a project from SelectProjectWindow
            //
            if (App.Current.Properties["SelectedProject"] != null)
            {
                DataRowView drv2 = (DataRowView)App.Current.Properties["SelectedProject"];
                lblEditProjectMessage_Project.Content = (string)drv2["projectname"];
                pid = (int)drv2["pid"];
                lblpid.Content = (int)drv2["pid"];
                App.Current.Properties["SelectedProject"] = null;
            }

            //
            //Check if user has selected an employee from SelectEmployeeWindow
            //
            if (App.Current.Properties["SelectedEmployee"] != null)
            {
                DataRowView drv3 = (DataRowView)App.Current.Properties["SelectedEmployee"];
                lblEditProjectMessage_Employee.Content = (string)drv3["name"];
                eid = (int)drv3["eid"];
                lbleid.Content = (int)drv3["eid"];
                App.Current.Properties["SelectedEmployee"] = null;
            }
        }
        private void UpdateWindow()
        {
            //display user's name in upper right corner           
            lblName.Content = App.Current.Properties["User"];

            //disable add, edit and remove for 'poweruser' in admin menu
            string role = (string)App.Current.Properties["Role"];
            if (role == "poweruser" && App.Current.Properties["thisProject"] == null)
            {

                btnAddMessage.Visibility = Visibility.Collapsed;
                ctxMenu.Visibility = Visibility.Collapsed;
            }


            ProjectMaster2016.projectmasterDataSet projectmasterDataSet = ((ProjectMaster2016.projectmasterDataSet)(this.FindResource("projectmasterDataSet")));
            // Load data into the table project_messages. You can modify this code as needed.
            ProjectMaster2016.projectmasterDataSetTableAdapters.project_messagesTableAdapter pma = new ProjectMaster2016.projectmasterDataSetTableAdapters.project_messagesTableAdapter();
            
            if (App.Current.Properties["thisProjectMessage"] == null)
            { 
                //
                //Fill all messages for all projects. For access through admin menu: add, edit and remove enabled (admin role) -> add,edit and remove disabled (poweruser role)
                //
                try { 
                        pma.FillByPID(projectmasterDataSet.project_messages);
                        System.Windows.Data.CollectionViewSource project_messagesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("project_messagesViewSource")));
                        project_messagesViewSource.View.MoveCurrentToFirst();
                    }
                catch { }
            }
            else
            {
                //
                //Fill with messages related to a particular project
                //
                try 
                { 
                    DataRowView drv = (DataRowView)App.Current.Properties["thisProjectMessage"];
                    pid = (int)drv["pid"];
                    pma.FillProjectMsgByPId(projectmasterDataSet.project_messages, pid);
                }
                catch { }
            }

            //
            //disable edit and delete if user is not owner/creator of project
            //
            eid = (int)App.Current.Properties["UserId"];
            projectmasterDataSetTableAdapters.projectTableAdapter pta = new projectmasterDataSetTableAdapters.projectTableAdapter();
            try 
            { 
                int isOwner = (int)pta.GetProjectOwner(pid);
                if(isOwner != eid)
                {
                    ctxMenu.Visibility = Visibility.Collapsed;
                }

                if (role == "poweruser" && isOwner != eid)
                {
                    btnAddMessage.Visibility = Visibility.Collapsed;
                    ctxMenu.Visibility = Visibility.Collapsed;
                }
            }
            catch { }

            //ensure add, edit and remove are enabled for admin
            if (role == "admin")
            {
                btnAddMessage.Visibility = Visibility.Visible;
                ctxMenu.Visibility = Visibility.Visible;
            }

            //ensure add is enable for poweruser
            if (role == "poweruser" && App.Current.Properties["thisProject"] != null)
            {
                btnAddMessage.Visibility = Visibility.Visible;
            }
        }
        private void btnfillByDate_Click(object sender, RoutedEventArgs e)
        {
            //
            //Select daterange by messagetimestamp
            //
            if (dpFromDate.SelectedDate <= dpToDate.SelectedDate)
            {
                DateTime from = (DateTime)dpFromDate.SelectedDate;
                DateTime to = (DateTime)dpToDate.SelectedDate.Value.AddDays(1);

                ProjectMaster2016.projectmasterDataSet projectmasterDataSet = ((ProjectMaster2016.projectmasterDataSet)(this.FindResource("projectmasterDataSet")));
                ProjectMaster2016.projectmasterDataSetTableAdapters.project_messagesTableAdapter projectmasterDataSetprojectTableAdapter = new ProjectMaster2016.projectmasterDataSetTableAdapters.project_messagesTableAdapter();
                if(App.Current.Properties["thisProjectMessage"] == null)
                    try
                    {                
                        projectmasterDataSetprojectTableAdapter.FillByPIDDate(projectmasterDataSet.project_messages, from, to);
                    }
                    catch 
                    {
 
                    }
                else
                {
                    projectmasterDataSetprojectTableAdapter.FillBythisPIDDate(projectmasterDataSet.project_messages, from, to, pid);
                }
                string fromlbl = dpFromDate.SelectedDate.Value.ToLongDateString();

                string tolbl = dpToDate.SelectedDate.Value.ToLongDateString();

                lbldateRange.Content = fromlbl + " - " + tolbl;
            }
            else
            {
                MessageBox.Show("Fylla verður rétt í dagsetningar");
            }


        }