コード例 #1
0
        private void AddMaster()
        {
            DVTEntities1       db = new DVTEntities1();
            registerController rc = new registerController();


            DataGridCell c  = dataGridHelper.GetCell(datadrid1, 0, 0);
            DataGridCell bh = dataGridHelper.GetCell(datadrid1, 0, 1); //get rows and column

            ComboBox  cmbNames = (ComboBox)c.Content;                  //get content
            TextBlock txthours = (TextBlock)bh.Content;
            var       hr       = txthours.Text;

            if (!Regex.IsMatch(hr, "^((?:[0-9]|1[0-9]|2[0-3])(?:\\.\\d{1,2})?|24(?:\\.00?)?)$"))
            {
                MessageBox.Show("Invalid input for Hours");
            }

            AttendanceMasterTb master = new AttendanceMasterTb();

            //master.Date = DpDates.SelectedDate;
            //master.MentorPersonId = 7;
            //master.Training = txtTraining.Text;

            var na1 = cmbNames.SelectedItem.ToString();//check the name

            var             mentor = txtMentors.SelectedItem.ToString();
            List <PersonTb> query1 = (from x in db.PersonTbs
                                      where x.Names == mentor
                                      select x).ToList();

            foreach (var item in query1)//loop throur the list to get the person id
            {
                master.Date           = DpDates.SelectedDate;
                master.MentorPersonId = item.PersonId;
                master.Training       = txtTraining.Text;
            }
            rc.insertMaster(master);


            var             na    = cmbNames.SelectedItem.ToString();//check the name
            List <PersonTb> query = (from x in db.PersonTbs
                                     where x.Names == na
                                     select x).ToList();
            //MessageBox.Show(na.ToString());
            AttendanceDetailsTb details = new AttendanceDetailsTb();

            foreach (var item in query)//loop throur the list to get the person id
            {
                details.MasterId        = master.MasterId;
                details.MenteeePersonId = item.PersonId;
                details.Hours           = hr;
            }


            rc.insertDetails(details);
            MessageBox.Show("Saved");
        }
コード例 #2
0
        public string insertMaster(AttendanceMasterTb details)
        {
            try
            {
                DVTEntities1 db = new DVTEntities1();

                db.AttendanceMasterTbs.Add(details);
                db.SaveChanges();
                return("Inserted");
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
        private void Display()
        {
            List <string> selectedNames = new List <string>();

            person = new List <Per>();

            using (DVTEntities1 context = new DVTEntities1())
            {
                List <AttendanceDetailsTb> queryDiteils =
                    (from D in context.AttendanceDetailsTbs
                     join M in context.AttendanceMasterTbs on D.MasterId equals M.MasterId
                     where M.Date == DpDates.SelectedDate
                     select D).ToList();


                List <AttendanceMasterTb> queryMaster = (from M in context.AttendanceMasterTbs
                                                         join D in context.AttendanceDetailsTbs on M.MasterId equals D.MasterId
                                                         where M.Date == DpDates.SelectedDate
                                                         select M).ToList();


                List <Per> persons = new List <Per>()
                {
                };

                foreach (var item in queryDiteils)
                {
                    List <AttendanceMasterTb> queryMentor = (from M in context.AttendanceMasterTbs
                                                             join D in context.AttendanceDetailsTbs on M.MasterId equals D.MasterId
                                                             join P in context.PersonTbs on D.MenteeePersonId equals P.PersonId
                                                             where M.Date == DpDates.SelectedDate
                                                             select M).ToList();


                    foreach (var item1 in queryMentor)
                    {
                        txtTraining.Text = item1.Training;
                        foreach (var i in ID)
                        {
                            datadrid1.ItemsSource = queryMentor;
                            foreach (var item3 in queryMentor)
                            {
                                txtTraining.Text = item3.Training;
                                if (DpDates.SelectedDate != item3.Date)
                                {
                                    txtMentors.SelectedIndex = 0;
                                    txtTraining.Text         = item3.Training;
                                }
                            }

                            if (i.Equals(item1.MentorPersonId))
                            {
                                selectedNames.Add(Names2.ElementAt(MenID.IndexOf(item1.MasterId)));
                                txtMentors.SelectedIndex = ID.IndexOf(item1.MasterId);
                            }
                        }
                        //menteeCm.ItemsSource = item1
                    }



                    person.Clear();
                    for (int i = 0; i < queryDiteils.Count; i++)
                    {
                        int id = Convert.ToInt32(queryDiteils[i].MenteeePersonId);

                        List <PersonTb> mentee = (from P in context.PersonTbs
                                                  where P.PersonId == id
                                                  select P).ToList();

                        person.Add(new Per(mentee[0].Names,
                                           queryDiteils[i].Hours));
                    }
                    datadrid1.ItemsSource   = person;
                    datadrid1.SelectedIndex = 0;
                }
            }
        }