ChangeCourseDataCmd.cs :  » Business-Application » Timetabler » OpenCTT » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Business Application » Timetabler 
Timetabler » OpenCTT » ChangeCourseDataCmd.cs
#region Open Course Timetabler - An application for school and university course timetabling
//
// Author:
//   Ivan urak (mailto:Ivan.Curak@fesb.hr)
//
// Copyright (c) 2007 Ivan urak, Split, Croatia
//
// http://www.openctt.org
//
//This file is part of Open Course Timetabler.
//
//Open Course Timetabler is free software;
//you can redistribute it and/or modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2 of the License,
//or (at your option) any later version.
//
//Open Course Timetabler is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
//or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//You should have received a copy of the GNU General Public License along with
//Open Course Timetabler; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
//Fifth Floor, Boston, MA  02110-1301  USA

#endregion


using System;
using System.Windows.Forms;

namespace OpenCTT{
  /// <summary>
  /// Summary description for ChangeCourseDataCmd.
  /// </summary>
  public class ChangeCourseDataCmd:AbstractCommand
  {
    Course _course;
    EduProgram _ep;

    string _oldName;
    string _oldShortName;
    string _oldGroupName;
    int _oldNumOfLessonsPerWeek;
    int _oldNumOfEnrolledStudents;
    bool _oldIsGroup;
    Teacher _oldTeacher;
    string _oldExtID;
    string _oldCourseType;

    string _newName;
    string _newShortName;
    string _newGroupName;
    int _newNumOfLessonsPerWeek;
    int _newNumOfEnrolledStudents;
    bool _newIsGroup;
    Teacher _newTeacher;
    string _newExtID;
    string _newCourseType;


    public ChangeCourseDataCmd(Course course,string newName,string newShortName,string newGroupName,int newNumOfLessonsPerWeek,int newNumOfEnrolledStudents,bool newIsGroup,Teacher newTeacher,string newExtID, string newCourseType)
    {
      _course=course;
      _ep=(EduProgram)_course.Parent;

      _oldName=_course.getName();
      _oldShortName=_course.getShortName();
      _oldGroupName=_course.getGroupName();
      _oldNumOfLessonsPerWeek=_course.getNumberOfLessonsPerWeek();
      _oldNumOfEnrolledStudents=_course.getNumberOfEnrolledStudents();
      _oldIsGroup=_course.getIsGroup();
      _oldTeacher=_course.getTeacher();
      _oldExtID=_course.ExtID;
      _oldCourseType=_course.CourseType;

      _newName=newName;
      _newShortName=newShortName;
      _newGroupName=newGroupName;
      _newNumOfLessonsPerWeek=newNumOfLessonsPerWeek;
      _newNumOfEnrolledStudents=newNumOfEnrolledStudents;
      _newIsGroup=newIsGroup;
      _newTeacher=newTeacher;
      _newExtID=newExtID;
      _newCourseType=newCourseType;
    }

    public override void doit()
    {      
      _course.setNumberOfLessonsPerWeek(_newNumOfLessonsPerWeek);
      _course.setNumberOfEnrolledStudents(_newNumOfEnrolledStudents);
      _course.setIsGroup(_newIsGroup);
      _course.setGroupName(_newGroupName);
      _course.setShortName(_newShortName);
      _course.setTeacher(_newTeacher);
      _course.ExtID=_newExtID;
      _course.CourseType=_newCourseType;

      if(_newCourseType!=_oldCourseType)
      {
        updateTSPLabels();

        if(!AppForm.CURR_OCTT_DOC.CourseTypesList.Contains(_newCourseType))
        {
          AppForm.CURR_OCTT_DOC.CourseTypesList.Add(_newCourseType);
          AppForm.CURR_OCTT_DOC.CourseTypesList.Sort();
        }

        if(HardConstraintChecks.checkIfCourseTypeIsFreeForDelete(_course))
        {
          AppForm.CURR_OCTT_DOC.CourseTypesList.Remove(_oldCourseType);
        }
      }
      
      
      if(_oldName!=_newName || _oldCourseType!=_newCourseType)
      {
        _course.setName(_newName);
        updateTSPLabels();        
      }
      
      //update of existing lessons in ListView
      updateListViewText();
      
      int diff;
      if(_oldNumOfLessonsPerWeek>_newNumOfLessonsPerWeek)
      {        
        diff=_oldNumOfLessonsPerWeek-_newNumOfLessonsPerWeek;
        for(int n=0;n<diff;n++)
        {
          _ep.removeOneLessonFromUnallocatedLessonsModelAndListView(_course,AppForm.getAppForm().getUnallocatedLessonsListView());
          AppForm.CURR_OCTT_DOC.decrUnallocatedLessonsCounter(1);          
        }
      }
      else if (_newNumOfLessonsPerWeek>_oldNumOfLessonsPerWeek)
      {            
        //we have to add lessons          
        diff = _newNumOfLessonsPerWeek-_oldNumOfLessonsPerWeek;
        for(int k=0;k<diff;k++)
        {
          string [] courseTeacher = new string[2];
          courseTeacher[0]=_course.getFullName();              
          courseTeacher[1]=_course.getTeacher().getLastName()+" "+_course.getTeacher().getName();

          ListViewItem lvi=new ListViewItem(courseTeacher);
          lvi.Tag=_course;
          lvi.EnsureVisible();
          AppForm.getAppForm().getUnallocatedLessonsListView().Items.Add(lvi);

          ListViewItem lvi2=(ListViewItem)lvi.Clone();          
          _ep.getUnallocatedLessonsList().Add(lvi2);
          AppForm.CURR_OCTT_DOC.incrUnallocatedLessonsCounter(1);    
        }
            
      }
      
      _course.setTreeText();
      sortIt();      
    }

    public override void undo()
    {
      _course.setNumberOfLessonsPerWeek(_oldNumOfLessonsPerWeek);
      _course.setNumberOfEnrolledStudents(_oldNumOfEnrolledStudents);
      _course.setIsGroup(_oldIsGroup);
      _course.setGroupName(_oldGroupName);
      _course.setShortName(_oldShortName);
      _course.setTeacher(_oldTeacher);
      _course.ExtID=_oldExtID;
      _course.CourseType=_oldCourseType;

      if(_newCourseType!=_oldCourseType)
      {
        updateTSPLabels();

        if(!AppForm.CURR_OCTT_DOC.CourseTypesList.Contains(_oldCourseType))
        {
          AppForm.CURR_OCTT_DOC.CourseTypesList.Add(_oldCourseType);
          AppForm.CURR_OCTT_DOC.CourseTypesList.Sort();
        }

        if(HardConstraintChecks.checkIfCourseTypeIsFreeForDelete(_course))
        {
          AppForm.CURR_OCTT_DOC.CourseTypesList.Remove(_newCourseType);
        }
      }

      
      if(_oldName!=_newName  || _oldCourseType!=_newCourseType)
      {
        _course.setName(_oldName);
        updateTSPLabels();  
      }

      //update of existing lessons in ListView
      updateListViewText();

      int diff;
      if(_newNumOfLessonsPerWeek>_oldNumOfLessonsPerWeek)
      {
        //delete lessons
        diff=_newNumOfLessonsPerWeek-_oldNumOfLessonsPerWeek;
        for(int n=0;n<diff;n++)
        {
          _ep.removeOneLessonFromUnallocatedLessonsModelAndListView(_course,AppForm.getAppForm().getUnallocatedLessonsListView());
          AppForm.CURR_OCTT_DOC.decrUnallocatedLessonsCounter(1);          
        }
      }
      else if (_oldNumOfLessonsPerWeek>_newNumOfLessonsPerWeek)
      {            
        //add lessons        
        diff = _oldNumOfLessonsPerWeek-_newNumOfLessonsPerWeek;
        for(int k=0;k<diff;k++)
        {
          string [] courseTeacher = new string[2];
          courseTeacher[0]=_course.getFullName();              
          courseTeacher[1]=_course.getTeacher().getLastName()+" "+_course.getTeacher().getName();

          ListViewItem lvi=new ListViewItem(courseTeacher);
          lvi.Tag=_course;
          lvi.EnsureVisible();
          AppForm.getAppForm().getUnallocatedLessonsListView().Items.Add(lvi);

          ListViewItem lvi2=(ListViewItem)lvi.Clone();          
          _ep.getUnallocatedLessonsList().Add(lvi2);
          AppForm.CURR_OCTT_DOC.incrUnallocatedLessonsCounter(1);    
        }
            
      }
            
      _course.setTreeText();
      sortIt();
    }

    public override void redo()
    {
      doit();
    }

    private void updateTSPLabels()
    {      
      foreach(TimeSlotPanel tsp in AppForm.getAppForm().getMainTimetablePanel().Controls)
      {
        foreach(Label[] oneSubLabel in tsp.getAllSubLabels())
        {
          Label courseLabel=oneSubLabel[0];
          Course thisCourse = (Course)courseLabel.Tag;
          if(thisCourse==_course)
          {
            courseLabel.Text=_course.getFullName();
          }
        }
      }    

    }

    private void updateListViewText()
    {      
      foreach(ListViewItem upLvi in AppForm.getAppForm().getUnallocatedLessonsListView().Items)
      {
        Course upCourse=(Course)upLvi.Tag;
        if(upCourse==_course)
        {
          ListViewItem.ListViewSubItem upLvsi1=upLvi.SubItems[0];
          upLvsi1.Text=_course.getFullName();
          ListViewItem.ListViewSubItem upLvsi2=upLvi.SubItems[1];
          upLvsi2.Text=_course.getTeacher().getLastName()+" "+_course.getTeacher().getName();
        }
      }
    }

    private void sortIt()
    {      
      AppForm.getAppForm().getCoursesTreeView().BeginUpdate();
      _ep.Nodes.Remove(_course);
      _ep.Nodes.Add(_course);
      AppForm.getAppForm().getCoursesTreeView().SelectedNode=_course;
      AppForm.getAppForm().getCoursesTreeView().EndUpdate();
        
      AppForm.getAppForm().getStatusBarPanel2().Text=AppForm.CURR_OCTT_DOC.getNumOfUnallocatedLessonsStatusText();

      AppForm.getAppForm().getTreeTabControl().SelectedIndex=0;
    }

  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.