private void ClassForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dgvClass[0, 0].Selected = true;
            // ----------------------------------------------------------------------------------------------
            //
            var db = new LINQDataContext();
            //
            // Delete Group_ID_List Where Class_ID == this.ID
            //
            db.Group_ID_ListDeleteAll();
            db.Priority_ProfessorDelete();
            for (int rowCounter = 0; rowCounter < dgvClass.RowCount - 1; rowCounter++)
            {
                try
                {
                    //
                    // search dgvClass.rows in db.Class
                    //
                    int id_class = int.Parse(dgvClass[0, rowCounter].Value.ToString());

                    var query = (from QC in db.Classes
                                 where QC.Class_ID == id_class
                                 select QC).SingleOrDefault();
                    if (dgvClass[2, rowCounter].Value.ToString() == "")
                    {
                        new LINQDataContext().ClassDelete(int.Parse(dgvClass[0, rowCounter].Value.ToString()));
                        throw new Exception("Null Professor Value's");
                    }
                    if (query != null) // edit (UPDATE)
                    {
                        int PU = 0;
                        int TU = 0;
                        decimal code = 0;
                        db.ClassEdit(id_class, (dgvClass[3, rowCounter].Value != null) ?
                                               (from courseID in db.Courses
                                                where (courseID.Name_Course == dgvClass[3, rowCounter].Value.ToString()) &&
                                                      (courseID.CourseCode == ((decimal.TryParse(dgvClass[4, rowCounter].Value.ToString(), out code)) ? code : 0))
                                                select courseID.Course_ID).Single() : 0,
                                    (int.TryParse(dgvClass[5, rowCounter].Value.ToString(), out PU)) ? PU : 0,
                                    (int.TryParse(dgvClass[6, rowCounter].Value.ToString(), out TU)) ? TU : 0,
                                     dgvClass[7, rowCounter].Value.ToString());
                    }
                    else //save (INSERT or Create NEW)
                    {
                        int PU = 0;
                        int TU = 0;
                        decimal code = 0;
                        db.ClassSave(id_class, (dgvClass[3, rowCounter].Value != null) ?
                                               (from courseID in db.Courses
                                                where (courseID.Name_Course == dgvClass[3, rowCounter].Value.ToString()) &&
                                                      (courseID.CourseCode == ((decimal.TryParse(dgvClass[4, rowCounter].Value.ToString(), out code)) ? code : 0))
                                                select courseID.Course_ID).Single() : 0,
                                    (int.TryParse(dgvClass[5, rowCounter].Value.ToString(), out PU)) ? PU : 0,
                                    (int.TryParse(dgvClass[6, rowCounter].Value.ToString(), out TU)) ? TU : 0,
                                     dgvClass[7, rowCounter].Value.ToString());
                    }
                    //
                    // Group in db.Group_ID_List
                    //
                    saveAndCompile_Groups((dgvClass[9, rowCounter].Value != null) ?
                                           dgvClass[9, rowCounter].Value.ToString() : " ",
                                          Convert.ToInt32(dgvClass[0, rowCounter].Value.ToString()));
                    //
                    // Priority in db.Priority_Professors
                    //
                    saveAndCompile_Priority((dgvClass[2, rowCounter].Value != null) ?
                                             dgvClass[2, rowCounter].Value.ToString() : " ",
                                            Convert.ToInt32(dgvClass[0, rowCounter].Value.ToString()));
                }
                catch { }
            }
        }
Esempio n. 2
0
        private void ClassForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dgvClass[0, 0].Selected = true;
            // ----------------------------------------------------------------------------------------------
            //
            var db = new LINQDataContext();

            //
            // Delete Group_ID_List Where Class_ID == this.ID
            //
            db.Group_ID_ListDeleteAll();
            db.Priority_ProfessorDelete();
            for (int rowCounter = 0; rowCounter < dgvClass.RowCount - 1; rowCounter++)
            {
                try
                {
                    //
                    // search dgvClass.rows in db.Class
                    //
                    int id_class = int.Parse(dgvClass[0, rowCounter].Value.ToString());

                    var query = (from QC in db.Classes
                                 where QC.Class_ID == id_class
                                 select QC).SingleOrDefault();
                    if (dgvClass[2, rowCounter].Value.ToString() == "")
                    {
                        new LINQDataContext().ClassDelete(int.Parse(dgvClass[0, rowCounter].Value.ToString()));
                        throw new Exception("Null Professor Value's");
                    }
                    if (query != null) // edit (UPDATE)
                    {
                        int     PU   = 0;
                        int     TU   = 0;
                        decimal code = 0;
                        db.ClassEdit(id_class, (dgvClass[3, rowCounter].Value != null) ?
                                     (from courseID in db.Courses
                                      where (courseID.Name_Course == dgvClass[3, rowCounter].Value.ToString()) &&
                                      (courseID.CourseCode == ((decimal.TryParse(dgvClass[4, rowCounter].Value.ToString(), out code)) ? code : 0))
                                      select courseID.Course_ID).Single() : 0,
                                     (int.TryParse(dgvClass[5, rowCounter].Value.ToString(), out PU)) ? PU : 0,
                                     (int.TryParse(dgvClass[6, rowCounter].Value.ToString(), out TU)) ? TU : 0,
                                     dgvClass[7, rowCounter].Value.ToString());
                    }
                    else //save (INSERT or Create NEW)
                    {
                        int     PU   = 0;
                        int     TU   = 0;
                        decimal code = 0;
                        db.ClassSave(id_class, (dgvClass[3, rowCounter].Value != null) ?
                                     (from courseID in db.Courses
                                      where (courseID.Name_Course == dgvClass[3, rowCounter].Value.ToString()) &&
                                      (courseID.CourseCode == ((decimal.TryParse(dgvClass[4, rowCounter].Value.ToString(), out code)) ? code : 0))
                                      select courseID.Course_ID).Single() : 0,
                                     (int.TryParse(dgvClass[5, rowCounter].Value.ToString(), out PU)) ? PU : 0,
                                     (int.TryParse(dgvClass[6, rowCounter].Value.ToString(), out TU)) ? TU : 0,
                                     dgvClass[7, rowCounter].Value.ToString());
                    }
                    //
                    // Group in db.Group_ID_List
                    //
                    saveAndCompile_Groups((dgvClass[9, rowCounter].Value != null) ?
                                          dgvClass[9, rowCounter].Value.ToString() : " ",
                                          Convert.ToInt32(dgvClass[0, rowCounter].Value.ToString()));
                    //
                    // Priority in db.Priority_Professors
                    //
                    saveAndCompile_Priority((dgvClass[2, rowCounter].Value != null) ?
                                            dgvClass[2, rowCounter].Value.ToString() : " ",
                                            Convert.ToInt32(dgvClass[0, rowCounter].Value.ToString()));
                }
                catch { }
            }
        }