Ejemplo n.º 1
0
        private void dgvClass_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            int id = 0;

            if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id))
            {
                var db = new LINQDataContext();
                db.Priority_ProfessorDeleteClass(id);
                db.Classroom_TimeDeleteClass(id);
                db.Group_ID_ListDeleteClass(id);
                db.ClassDelete(id);
                db.Dispose();
            }
        }
 private void dgvClass_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 {
     int id = 0;
     if (int.TryParse(e.Row.Cells[0].Value.ToString(), out id))
     {
         var db = new LINQDataContext();
         db.Priority_ProfessorDeleteClass(id);
         db.Classroom_TimeDeleteClass(id);
         db.Group_ID_ListDeleteClass(id);
         db.ClassDelete(id);
         db.Dispose();
     }
 }
Ejemplo n.º 3
0
        private void chkFragmental_CheckedChanged(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                ResultForm._setting.Fragmental_Classes = chkFragmental.Checked;
                if (ResultForm._setting.Fragmental_Classes)
                {
                    #region Fragment the Class more than two units
                    var dbClasses = DB.Classes.ToList();
                    //
                    /// A list for store any class by unit more than 2.
                    ///  Tuple< Classes, Unit >
                    List <Tuple <Class, int> > lstFragmentClass = new List <Tuple <Class, int> >();
                    //
                    // Delete old classroom, because it has this class information!
                    new LINQDataContext().Classroom_TimeDeleteAll();
                    //
                    // Search for any class by unit more than 2.
                    foreach (var any in dbClasses)
                    {
                        if (any.Practical_unit + any.Theory_unit > 2)
                        {
                            lstFragmentClass.Add(new Tuple <Class, int>(any, any.Practical_unit + any.Theory_unit));
                        }
                    }
                    //
                    // Read any Finded Class and Fragment that to 2 Unit Quantums.
                    foreach (var anyClass in lstFragmentClass)
                    {
                        int u = 0;
                        do
                        {
                            int id = findNewClassID(); // create a new class ID
                            //
                            // delete old and hyper data
                            DB.Group_ID_ListDeleteClass(id);
                            DB.Priority_ProfessorDeleteClass(id);
                            //
                            Class c = new Class() // create new Classes
                            {
                                Class_ID       = id,
                                Course_ID      = anyClass.Item1.Course_ID,
                                RoomType       = anyClass.Item1.RoomType,
                                Practical_unit = 0,
                                Theory_unit    = ((anyClass.Item2 - u) >= 2) ? 2 : 1
                            };
                            //
                            // create new Group_ID_List for this new Class
                            List <Group_ID_List> g = new List <Group_ID_List>();
                            g.AddRange(anyClass.Item1.Group_ID_Lists);
                            for (int i = 0; i < g.Count; i++)
                            {
                                g[i].Class_ID = id;
                            }
                            //
                            // create new Priority_Professor for this new Class
                            List <Priority_Professor> p = new List <Priority_Professor>();
                            p.AddRange(anyClass.Item1.Priority_Professors);
                            for (int i = 0; i < p.Count; i++)
                            {
                                p[i].Class_ID = id;
                            }
                            //
                            // add new data to DB
                            DB.ClassSave(c.Class_ID, c.Course_ID, c.Practical_unit, c.Theory_unit, c.RoomType);
                            foreach (var anyG in g)
                            {
                                DB.Group_ID_ListSave(anyG.Group_ID, anyG.Class_ID);
                            }
                            foreach (var anyP in p)
                            {
                                DB.Priority_ProfessorSave(anyP.Professor_ID, anyP.Class_ID, anyP.Priority);
                            }
                            //DB.Classes.InsertOnSubmit(c);
                            //DB.SubmitChanges();
                            //DB.Group_ID_Lists.InsertAllOnSubmit(g);
                            //DB.Priority_Professors.InsertAllOnSubmit(p);
                            //DB.SubmitChanges();
                            u += 2;
                        }while (anyClass.Item2 - u > 0);

                        //
                        // delete old class data (original class who has more than 2 units)
                        DB.Group_ID_ListDeleteClass(anyClass.Item1.Class_ID);
                        DB.Priority_ProfessorDeleteClass(anyClass.Item1.Class_ID);
                        DB.ClassDelete(anyClass.Item1.Class_ID);
                    }
                    #endregion

                    MakeClassSchedule.Algorithm.Configuration.GetInstance.ParseFile(new LINQDataContext());
                    chkFragmental.Enabled = false;
                }
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }