Ejemplo n.º 1
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedIndexComB1 = comboBox1.SelectedIndex;
            Object          o = list.Asl.ElementAt(selectedIndexComB1);
            Assignment      a = (Assignment)o;
            int             assignmentIndex = a.Id;
            Service1Client  winService      = new Service1Client();
            ListForObjects  hl        = winService.GetAllHomeworksById(assignmentIndex);
            List <Homework> homeworks = new List <Homework>();

            foreach (Object ob in hl.Asl)
            {
                Homework h = (Homework)ob;
                homeworks.Add(h);
            }

            //makes a new List with two attributes of childs name and the path
            //To avoid makeing a new wrapper and instead of child objects address it displays its name
            List <Tuple <string, string> > nameList = new List <Tuple <string, string> >();

            foreach (Homework hmw in homeworks)
            {
                nameList.Add(new Tuple <string, string>(hmw.Child.Name, hmw.DiskName));
            }

            //If there are columns it removes the last button column so that the other columns
            //don't lose their indexes after data change
            if (dataGridView1.Columns.Count > 0)
            {
                dataGridView1.Columns.Remove("Download");
            }

            //Creates new data and replaces the data in the table
            DataSet       ds = new DataSet();
            BindingSource bs = new BindingSource();

            bs.DataSource                       = nameList;
            dataGridView1.DataSource            = bs;
            dataGridView1.Columns[0].HeaderText = "Name";
            dataGridView1.Columns[1].HeaderText = "Path";

            //Adds the button column as the last column
            DataGridViewButtonColumn btnCol = new DataGridViewButtonColumn();

            btnCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            btnCol.Text         = "Download";
            btnCol.Name         = "Download";
            btnCol.UseColumnTextForButtonValue = true;
            btnCol.HeaderText = "Download";
            dataGridView1.Columns.Add(btnCol);
        }
Ejemplo n.º 2
0
        public ListForObjects GetAllAssignmentsByTeacherId(int teacherId)
        {
            AssignmentDb   asDB     = new AssignmentDb();
            PersonCtrl     userCtrl = new PersonCtrl();
            ListForObjects list     = new ListForObjects();
            ListForObjects l        = asDB.GetAllAssignmentsByTeacherId(teacherId);

            foreach (Object o in l.Asl)
            {
                Assignment a = (Assignment)o;
                a.teacher = (Teacher)userCtrl.GetPerson(a.teacher.Id);
                list.Asl.Add(a);
            }
            return(list);
        }
Ejemplo n.º 3
0
        public ListForObjects GetAllHomeworksByID(int assignmentId)
        {
            HomeworkDb     hwDb          = new HomeworkDb();
            PersonCtrl     userCtrl      = new PersonCtrl();
            AssignmentCtrl assgnmentCtrl = new AssignmentCtrl();
            ListForObjects l             = hwDb.GetAllHomeworksById(assignmentId);
            ListForObjects list          = new ListForObjects();

            foreach (Homework hw in l.Asl)
            {
                hw.Child = (Child)userCtrl.GetPerson(hw.Child.Id);
                //hw.Assignment = assgnmentCtrl.GetAssignmentById(hw.Assignment.Id);
                list.Asl.Add(hw);
            }
            return(list);
        }
Ejemplo n.º 4
0
        public ListForObjects GetAllHomeworksById(int assignmentId)
        {
            ListForObjects homeworkList = new ListForObjects();

            try
            {
                comm             = new SqlCommand();
                comm.CommandText = "SELECT * FROM Homework WHERE assignmentId = " + assignmentId;


                dbCon           = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                comm.CommandType = CommandType.Text;
                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    Homework h = new Homework();
                    h.Id = Convert.ToInt32(dr["hid"]);
                    Assignment a = new Assignment();
                    a.Id         = Convert.ToInt32(dr["assignmentId"]);
                    h.Assignment = a;
                    Child c = new Child();
                    c.Id       = Convert.ToInt32(dr["childId"]);
                    h.Child    = c;
                    h.Date     = Convert.ToDateTime(dr["date"]);
                    h.DiskName = Convert.ToString(dr["diskName"]);
                    homeworkList.AddObj(h);
                }
            }
            catch (Exception)
            {
                throw;
            }

            finally
            {
                comm.Connection.Close();
            }
            return(homeworkList);
        }
Ejemplo n.º 5
0
        public ListForObjects GetAllAssignmentsByTeacherId(int teacherId)
        {
            ListForObjects al = new ListForObjects();

            try
            {
                comm             = new SqlCommand();
                comm.CommandText = "SELECT * FROM Assignment WHERE pid = " + teacherId;

                dbCon           = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                comm.CommandType = CommandType.Text;
                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    Assignment a = new Assignment();
                    a.Id       = Convert.ToInt32(dr["aid"]);
                    a.exercise = Convert.ToString(dr["exercise"]);
                    a.date     = Convert.ToDateTime(dr["date"]);
                    a.deadline = Convert.ToDateTime(dr["deadLine"]);
                    a.subject  = Convert.ToString(dr["subject"]);
                    Teacher t = new Teacher();
                    t.Id      = Convert.ToInt32(dr["pid"]);
                    a.teacher = t;
                    a.title   = Convert.ToString(dr["title"]);
                    al.AddObj(a);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                comm.Connection.Close();
            }
            return(al);
        }
Ejemplo n.º 6
0
        private List <String> populateAssignmentCB()
        {
            Service1Client winService = new Service1Client();

            strings = new List <string>();
            list    = winService.GetAllAssignmentsForTeacherById(teacher.Id);
            foreach (Object o in list.Asl)
            {
                Assignment a = (Assignment)o;
                strings.Add(a.title);
            }

            //creates new data and replaces the data in drop down list
            DataSet       ds = new DataSet();
            BindingSource bs = new BindingSource();

            bs.DataSource        = strings;
            comboBox1.DataSource = bs;

            return(strings);
        }
Ejemplo n.º 7
0
        //Need to clean up a code a bit for the method below
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            selectedIndexComB1 = comboBox1.SelectedIndex;
            Object     o = list.Asl.ElementAt(selectedIndexComB1);
            Assignment a = (Assignment)o;
            int        assignmentIndex = a.Id;

            Service1Client winService = new Service1Client();
            ListForObjects hl         = winService.GetAllHomeworksById(assignmentIndex);

            var gridSender = (DataGridView)sender;

            if (gridSender.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                e.RowIndex >= 0)
            {
                int      index    = e.RowIndex;
                Object   ob       = hl.Asl.ElementAt(index);
                Homework homework = (Homework)ob;
                //Simulating download by showing download path...
                MessageBox.Show("The file is downloaded. Path of download was : " + homework.DiskName);
            }
        }
Ejemplo n.º 8
0
        private List<String> populateAssignmentCB()
        {
            Service1Client winService = new Service1Client();

            strings = new List<string>();
            list = winService.GetAllAssignmentsForTeacherById(teacher.Id);
            foreach (Object o in list.Asl)
            {
                Assignment a = (Assignment)o;
                strings.Add(a.title);

            }

            //creates new data and replaces the data in drop down list
            DataSet ds = new DataSet();
            BindingSource bs = new BindingSource();
            bs.DataSource = strings;
            comboBox1.DataSource = bs;

            return strings;
        }