/* private void Start_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
         {

             txtROCEnd.DisplayDateEnd = new DateTime(2200, 1, 1);
             txtROCEnd.DisplayDateStart = txtROCStart.SelectedDate;
         }
         private void End_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
         {
             txtROCStart.DisplayDateStart = new DateTime(1900, 1, 1);
             txtROCStart.DisplayDateEnd = txtROCEnd.SelectedDate;
         }*/


        private void dtgList_CellClick(object sender, EventArgs e)
        {
            try
            {

                if (rbGrants.IsChecked == true)
                {
                    int pos = dtgList.CurrentRow.Index;

                    if (pos < Researcher.resDT.Rows.Count)
                    {
                        String sysID = dtgList.CurrentRow.Cells[0].Value.ToString();

                        curRes = new Researcher(sysID);
                        btnAgAdd.Content = "Assign";
                        btnAgAdd.ToolTip = "Click to assign a supervisor";

                        //curJour = Journal.JournalDS[pos]; //this was if i was using a list
                    }
                    //btnUpdate.Visibility = Visibility.Visible;


                    setDataSource();
                    if (txtaASID.Text == "-1")
                    {
                        txtaASID.Text = "";
                        
                    }
                    else
                    {
                        
                    }

                    if (txtaSID.Text == "-1")
                    {
                        txtaSID.Text = "";
                        
                    }
                    else
                    {
                        
                    }
                }
                else
                    if (rbAgencies.IsChecked == true)
                    {
                        int pos = dtgList.CurrentRow.Index;
                        // txtGagenID.SetBinding(TextBlock.TextProperty, "AgencyID");
                        if (pos < Supervisor.supDT.Rows.Count)
                        {
                            String sysID = dtgList.CurrentRow.Cells[0].Value.ToString();

                            // curSup = new Supervisor(sysID);
                            curRes.getsuper(sysID);
                            btnAgAdd.Content = "Update";
                            btnAgAdd.ToolTip = "Click to update researcher's details";



                            if(SupS == "SupervisorID")
                            curRes.SetNewSupervisor(curRes.returnSupName(sysID));
                            else
                            curRes.SetNewAASupervisor(curRes.returnSupName(sysID));

                            //curSup.getfund(agencyID);
                            //curFund = new FundAgency(agencyID);
                            //curJour = Journal.JournalDS[pos]; //this was if i was using a list
                        }

                        setDataSource();

                    }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        private void btnAgAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {

                {
                    RegisteredUser NewOne = new RegisteredUser();
                    Char G;
                    String photo = @"\\openbox\WRR301\Team03\RISDB\Images\" + curUser.SysID.ToString() + ".jpg";
                    if (rbGenM.IsChecked == true)
                    {
                        G = '1';
                    }
                    else
                    {
                        G = '0';
                    }
                    String depcode = NewOne.getDcode(cmbxDep.Text);
                    NewOne.AddUser(txtName.Text, cmbxTitle.Text, txtSname.Text, txtUN.Text, pBPass.Text, txtCNo.Text, depcode, photo, dpDoB.Text, txtEmail.Text, G, cmbxToU.Text);

                    if (cmbxToU.Text == "Administrative Assistant")
                    {
                        AdministrativeAssistant AA = new AdministrativeAssistant();
                        String sysID = AA.getID(txtUN.Text);
                        AA.AddUser(sysID, txtStID.Text);
                    }
                    else
                        if (cmbxToU.Text == "Independent Researcher")
                        {
                            IndependentResearcher IR = new IndependentResearcher();
                            String sysID = IR.getID(txtUN.Text);
                            IR.AddUser(sysID, txtStID.Text);
                        }
                        else
                            if (cmbxToU.Text == "Lecturer")
                            {
                                Lecturer LT = new Lecturer();
                                String sysID = LT.getID(txtUN.Text);
                                LT.AddUser(sysID, txtStID.Text);
                            }
                            else
                                if (cmbxToU.Text == "Researcher")
                                {
                                    Researcher RS = new Researcher();
                                    String sysID = RS.getID(txtUN.Text);
                                    RS.AddUser(sysID, txtRID.Text);
                                }
                                else
                                    if (cmbxToU.Text == "Student")
                                    {
                                        Student SD = new Student();
                                        String sysID = SD.getID(txtUN.Text);
                                        SD.AddUser(sysID, txtStID.Text);
                                    }
                                    else
                                        if (cmbxToU.Text == "Supervisor")
                                        {
                                            Supervisor SP = new Supervisor();
                                            String sysID = SP.getID(txtUN.Text);
                                            SP.AddUser(sysID, txtStID.Text);
                                        }
                                        else
                                            if (cmbxToU.Text == "System Administrator")
                                            {
                                                SystemAdministrator SA = new SystemAdministrator();
                                                String sysID = SA.getID(txtUN.Text);
                                                SA.AddUser(sysID, txtStID.Text, txtPos.Text);
                                            }

                    MessageBox.Show("Registered User Added", "~Added~");

                    InitializeGrid();
                    txtUN.Text = "";
                    pBPass.Text = "";
                    pBConf.Text = "";

                    cmbxTitle.SelectedIndex = -1;
                    cmbxDep.SelectedIndex = -1;
                    //cmbxToU.SelectedIndex = -1;

                    txtName.Text = "";
                    txtSname.Text = "";
                    txtCNo.Text = "";
                    txtEmail.Text = "";
                    txtStID.Text = "";
                    txtPos.Text = "";
                    txtRID.Text = "";

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {


            curRes = new Researcher();
            setResearcherDataSource();
            //////////////add clearfields
            /////enable and disable rbs


            btnUpdate.Visibility = Visibility.Hidden;


        }