Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Developing Next Generation Smart Clients using .NET 2.0 working with Existing .NET 1.1 SOA-based XML Web Services

, 16 Aug 2005
Comprehensive guide to development of .NET 2.0 Smart Clients working with existing Service Oriented Architecture based XML web services, fully utilizing the Enterprise Library
smartclientsoa_src.zip
SmartClient
Client
SMI.App
Controls
Forms
Modules
Properties
app.manifest
Settings.settings
Resources
240.png
Bottom.png
BuilderDialog_delete.bmp
DarkBlue.bmp
download-xp.gif
Earth.png
fldropen.png
iSync.gif
Leonardo_da_Vinci_My_Computer.png
LightBlue.bmp
LoginBox.jpg
LoginButton.jpg
LoginButton1.jpg
LoginButton2.jpg
Logo1.png
LogoPic.jpg
Middle.png
Refresh.bmp
refresh.ico
refresh1.ico
RightArrow.bmp
SuccessComplete.bmp
Task.bmp
Tasks.png
Top.png
TurnOffButton.bmp
wi0062-32.ico
wi0063-32.ico
wi0064-16.ico
wi0064-32.ico
SmartInstitute.App.csproj.user
wi0064-32.ico
SMI.Automation
Commands
Course
Framework
Security
Students
UI
Controls
Documents
MiscDocuments
StudentDocuments
Factories
Forms
Helpers
Misc
Properties
Settings.settings
Resources
BuilderDialog_delete.bmp
LogoSmall.bmp
Misho.jpg
My Pic 7.jpg
table.ico
SmartInstitute.Automation.csproj.user
Web References
SmartInstituteServices.AccountService
Account.datasource
AccountService.disco
AccountService.wsdl
Reference.map
SmartInstituteServices.CourseService
Course.datasource
CourseService.disco
CourseService.wsdl
Reference.map
SmartInstituteServices.SecurityService
Reference.map
SecurityService.disco
SecurityService.wsdl
SmartInstituteServices.StudentService
Reference.map
Student.datasource
StudentService.disco
StudentService.wsdl
SMI.ObjectModel.Enhanced
Base
Models
Properties
Settings.settings
Settings
SmartInstitute.ObjectModel.csproj.user
UMS.ObjectModel.Enhanced.csproj.user
SMI.Objects
SmartInstitute.csproj.user
CodeSmith
Tier
BusinessLogicLayer
Entity.cst
EntityBase.cst
EntityCollection.cst
EntityCollectionBase.cst
Enum.cst
IEntity.cst
DataAccessLayer
App.config.cst
CommonSql.cst
Configuration.cst
DBConcurrencyException.cst
DBException.cst
Factories
EntityRepositoryFactory.cst
IEntityRepository.cst
SqlClient
CVS
Entries
Entries.Extra
Entries.Extra.Old
Entries.Old
Repository
Root
TortoiseCVS.Status
SqlEntityRepository.cst
SqlEntityRepositoryBase.cst
TransactionManager.cst
UnitTests
EntityRepositoryTest.cst
WebServiceClient
WsEntityRepository.cst
WsEntityRepositoryBase.cst
Main.cst
nant.cst
References
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
StoredProcedures.cst
vsnet2003.project.cst
vsnet2003.solution.cst
vsnet2005.project.cst
vsnet2005.solution.cst
WebService
Web.config.cst
WebService.cst
Database
SmartInstitute.bak
Library
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
Microsoft.Practices.EnterpriseLibrary.Security.dll
nunit.core.dll
nunit.framework.dll
Server
BLL
SmartInstitute.csproj.user
DAL
Factories
SmartInstitute.DataAccessLayer.csproj.user
SqlClient
Utilities
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
UnitTests
SmartInstitute.build
SmartInstitute.Facade
FacadeTest
SmartInstitute.Facade.csproj.user
SmartInstitute.Test
App.ico
SmartInstitute.Test.csproj.user
SmartInstituteServices
Global.asax
log
SmartInstituteServices.csproj.webinfo
SQL
Setup
SecurityDatabase
SecurityDatabaseConsole
App.ico
SecurityDatabaseConsole.exe.manifest
SR.strings
Tests
Tools.SecurityDatabaseConsole.csproj.user
#region Using directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SmartInstitute.Client.Automation.Views;
using SmartInstitute.Client.Automation.Commands.Students;
using SmartInstitute.Automation.Commands.Framework;
using SmartInstitute;
using SmartInstitute.ObjectModel;
using SmartInstitute.Client.Automation.Helpers;
using SmartInstitute.Client.Automation.Commands.UI;
using SmartInstitute.Automation.Commands.Students;

#endregion

namespace SmartInstitute.Client.Automation.Documents.StudentDocuments
{
	public partial class StudentRegistrationUI : StudentDocumentUIBase
	{	
		public StudentRegistrationUI()
		{
			InitializeComponent();
		}

		private void StudentRegistrationUI_Load(object sender, EventArgs e)
		{
			if (!base.DesignMode)
			{
				this.ShowRegistration();
				this.BindView();
				this.profileView.ShowProfile(base.Document.StudentModel);
            }
		}

        private void BindView()
		{
			base.Document.OnAddCourse += new StudentDocument.AddCourseHandler(_View_OnAddCourse);
			base.Document.OnAddSection += new StudentDocument.AddSectionHandler(_View_OnAddSection);
		}


		bool _View_OnAddCourse( Course course )
		{
			return false;
		}

		bool _View_OnAddSection( CourseSection courseSection )
		{
			this.AddSection(courseSection);

			return true;
		}

		private void mapCourseControl_OnAccept( CourseSection CourseSection, Course countedCourse, Course attendedCourse )
		{
			this.AddNewCourse(CourseSection);
        }

		#region Actions

		private void dropToolStripButton_Click(object sender, EventArgs e)
		{
			this.DropSelectedCourse();
		}

		/// <summary>
		/// Matk selected courses as dropped
		/// </summary>
		private void DropSelectedCourse()
		{
			decimal dropRate;
			string percent = dropRateToolStripTextBox.Text.TrimEnd('%');
			if (decimal.TryParse(percent, out dropRate))
			{
				foreach (DataGridViewRow row in grdCourses.SelectedRows)
				{
                    
					CourseTakenByStudent2 regCourse = row.Tag as CourseTakenByStudent2;
                    // if not previously dropped
                    if (!regCourse.Dropped)
                    {
                        regCourse.Dropped = true;
                    }
                    else
                    {
                        regCourse.Dropped = false;
                        // undrop
                    }
				}
			}
			else
			{

			}

			this.UpdateUI();
		}

		private void deleteToolStripButton_Click(object sender, EventArgs e)
		{
			this.DeleteSelectedCourse();
		}

		private void nonCreditToolStripButton_Click(object sender, EventArgs e)
		{
			if (nonCreditToolStripButton.CheckState == CheckState.Checked)
				this.MakeSelectedCourseNonCredit();
			else if (nonCreditToolStripButton.CheckState == CheckState.Unchecked)
				this.MakeSelectedCourseCredited();
            // update the tool strip states
            this.UpdateState();
		}

		/// <summary>
		/// Mark selected courses as dropped
		/// </summary>
		private void DeleteSelectedCourse()
		{
			foreach (DataGridViewRow row in grdCourses.SelectedRows)
			{
				CourseTakenByStudent2 regCourse = row.Tag as CourseTakenByStudent2;

				regCourse.MarkToDelete();
			}
			this.UpdateUI();
		}

		private void UpdateUI()
		{
			this.ShowCourses();
		}

		/// <summary>
		/// Mark selected courses as non credit
		/// </summary>
		private void MakeSelectedCourseNonCredit()
		{
			foreach (DataGridViewRow row in grdCourses.SelectedRows)
			{
				CourseTakenByStudent2 regCourse = row.Tag as CourseTakenByStudent2;

				regCourse.NonCredit = true;
			}

			this.UpdateUI();
		}

		/// <summary>
		/// Mark selected courses as credited
		/// </summary>
		private void MakeSelectedCourseCredited()
		{
			foreach (DataGridViewRow row in grdCourses.SelectedRows)
			{
				CourseTakenByStudent2 regCourse = row.Tag as CourseTakenByStudent2;

				regCourse.NonCredit = false;
			}

			this.UpdateUI();
		}

		private void validToolStripButton_Click(object sender, EventArgs e)
		{
			if (validToolStripButton.CheckState == CheckState.Checked)
				this.ValidateSelectedCourses();
			else if (validToolStripButton.CheckState == CheckState.Unchecked)
				this.InvalidateSelectedCourses();
		}

		private void validateAllToolStripButton_Click(object sender, EventArgs e)
		{
			grdCourses.SelectAll();
			this.ValidateSelectedCourses();
			grdCourses.ClearSelection();
		}

		private void grdCourses_SelectionChanged(object sender, EventArgs e)
		{

			//this.UpdateToolbarState();
            this.UpdateState();
		}
        private void UpdateState()
        {
            foreach (DataGridViewRow row in grdCourses.SelectedRows)
            {
                CourseTakenByStudent2 regCourse = row.Tag as CourseTakenByStudent2;

                if (regCourse != null)
                {
                    if (regCourse.NonCredit)
                    {
                        nonCreditToolStripButton.CheckState = CheckState.Checked;
                        nonCreditToolStripButton.Text = "Credit";
                    }
                    else
                    {
                        nonCreditToolStripButton.CheckState = CheckState.Unchecked;
                        nonCreditToolStripButton.Text = "Non-Credit";
                    }
                    if (regCourse.Dropped)
                    {
                        dropToolStripButton.Text = "Undrop";
                    }
                    else
                    {
                        dropToolStripButton.Text = "Drop";
                    }
                }
            }
        }
		private void UpdateToolbarState()
		{
			// first reset to original state
			validateAllToolStripButton.CheckState = CheckState.Unchecked;

			bool anyNonCredit = false;
			bool allNonCredit = true;

			bool anyValid = false;
			bool allValid = true;

			foreach (DataGridViewRow row in grdCourses.SelectedRows)
			{
				CourseTakenByStudent2 regCourse = row.Tag as CourseTakenByStudent2;

				anyNonCredit |= regCourse.NonCredit;
				allNonCredit &= regCourse.NonCredit;

				anyValid |= regCourse.Valid;
				allValid &= regCourse.Valid;
			}

			if (allNonCredit)
				nonCreditToolStripButton.CheckState = CheckState.Checked;
			else
			{
				if (anyNonCredit)
					nonCreditToolStripButton.CheckState = CheckState.Indeterminate;
				else
					nonCreditToolStripButton.CheckState = CheckState.Unchecked;
			}

			if (allValid)
				validToolStripButton.CheckState = CheckState.Checked;
			else
			{
				if (anyValid)
					validToolStripButton.CheckState = CheckState.Indeterminate;
				else
					validToolStripButton.CheckState = CheckState.Unchecked;
			}
		}

		private void ValidateSelectedCourses()
		{
			foreach (DataGridViewRow row in grdCourses.SelectedRows)
			{
				CourseTakenByStudent2 regCourse = row.Tag as CourseTakenByStudent2;
				regCourse.Valid = true;
			}
		}

		private void InvalidateSelectedCourses()
		{
			foreach (DataGridViewRow row in grdCourses.SelectedRows)
			{
				CourseTakenByStudent2 regCourse = row.Tag as CourseTakenByStudent2;
				regCourse.Valid = false;
			}
		}

		/// <summary>
		/// Add the CourseSection to student's course list
		/// </summary>
		/// <param name="CourseSection"></param>
		void AddSection(CourseSection section)
		{
			this.AddNewCourse(section);
		}

		private void AddNewCourse(CourseSection section)
		{
			if (section.Status == (int)SectionStatusEnum.Closed)
			{
				if (MessageBox.Show(this,
                    "The Section you are trying to add is --" + section.Status.ToString() + "-- . Are you sure you want to do this?",
                    "Warning", 
					MessageBoxButtons.YesNo, 
					MessageBoxIcon.Warning) == DialogResult.No)
					return;

			}
            if (section.Status == (int)SectionStatusEnum.Reserved || section.Status == (int)SectionStatusEnum.Cancel)
            {
                MessageBox.Show(this, "You can not add a " + section.Status.ToString() + " CourseSection");
                return;
            }
          
            // 1 Find the offered course for the class
			CourseModel courseModel = _Application.Courses[section.CourseID];
			Course course = courseModel.Course;

			// 2. Add a new course
			CourseTakenByStudent2 courseTaken = new CourseTakenByStudent2(
				new CourseTakenByStudent(0, base.Document.StudentModel.Profile.ID,
				section.CourseID, section.ID, 1, false, DateTime.Now));

			courseTaken.Course = course;
			courseTaken.Section = section;

			base.Document.StudentModel.Profile.CourseTakenByStudentCollection.Add(courseTaken);

			// 4. Refresh UI
			this.UpdateUI();

		}


		#endregion

		#region Loading

		private void ShowRegistration()
		{
			this.LoadRegistration();
			this.UpdateUI();			
		}

		private void LoadRegistration()
		{
			// If courses are not loaded yet, try loading it in background
			if (null == base.Document.StudentModel.AllCourses)
			{
				progress.Start();
				worker.RunWorkerAsync();
			}
		}

		/// <summary>
		/// Loads students registration in background thread
		/// Warning! No UI access
		/// </summary>
		private void LoadRegistrationInBackground()
		{
			ICommand command = new LoadStudentDetailCommand(base.Document.StudentModel.Profile.ID);
			command.Execute();
		}

		/// <summary>
		/// Render the grid from the courses taken by the student
		/// It clears and populates the grid from the current registration
		/// object's course taken by student list
		/// </summary>
		private void ShowCourses()
		{
			grdCourses.Rows.Clear();

			Font strikeFont = new Font(base.Font, FontStyle.Strikeout);

			// 1. Construct styles for courses of different state
			DataGridViewCellStyle dropStyle = new DataGridViewCellStyle(grdCourses.DefaultCellStyle);
			dropStyle.BackColor = Color.LightGray;

			DataGridViewCellStyle deleteStyle = new DataGridViewCellStyle(grdCourses.DefaultCellStyle);
			deleteStyle.ForeColor = Color.Gray;
			deleteStyle.Font = strikeFont;

			DataGridViewCellStyle noncreditStyle = new DataGridViewCellStyle(grdCourses.DefaultCellStyle);
			noncreditStyle.ForeColor = Color.Blue;
            // class ID style
            DataGridViewCellStyle classIDStyle = new DataGridViewCellStyle( grdCourses.DefaultCellStyle );
            classIDStyle.ForeColor = Color.Green;

            DataGridViewCellStyle invalidStatusStyle = new DataGridViewCellStyle(grdCourses.DefaultCellStyle);
			invalidStatusStyle.ForeColor = Color.DarkRed;

			// 2. Populate the grid with current courses

			int totalLecCredit = 0, totalSciCredit = 0, totalCompCredit = 0;

			foreach (CourseTakenByStudent2 courseTaken in base.Document.StudentModel.Profile.CourseTakenByStudentCollection)
			{
				// prepare the columns
				string courseInfo = 
					string.Format( "{0} - {1} ({2})", 
					courseTaken.Section.Description, courseTaken.Section.Title, courseTaken.Section.Capacity )
					+ Environment.NewLine;

				// Build the routine text
				if (null != courseTaken.Section.SectionRoutineCollection)
				{
					foreach (SectionRoutine routine in courseTaken.Section.SectionRoutineCollection)
					{
						courseInfo += routine.ToString();
					}
				}

				string creditInfo = courseTaken.Course.LecCredit.ToString() + " " +
					courseTaken.Course.SciCredit.ToString() + " " +
					courseTaken.Course.CompCredit.ToString();

				string status = (courseTaken.Dropped ? "Dropped" : String.Empty ) + Environment.NewLine +
				    (courseTaken.Valid ? "Valid " : "Invalid ") + Environment.NewLine + ( courseTaken.NonCredit ? "Non-Credit" : String.Empty ) ;

				totalLecCredit += courseTaken.Course.LecCredit;
				totalSciCredit += courseTaken.Course.SciCredit;
				totalCompCredit += courseTaken.Course.CompCredit;

				// add the row
				int newRowIndex = grdCourses.Rows.Add( courseTaken.Section.ClassID, courseInfo, creditInfo, status );
				DataGridViewRow newRow = grdCourses.Rows[newRowIndex];

				// Apply different style to cells according to different state
				if (courseTaken.Dropped)
					newRow.Cells[1].Style.ApplyStyle(dropStyle);

				if (courseTaken.IsDeleted)
					newRow.Cells[1].Style.ApplyStyle(deleteStyle);

				if (courseTaken.NonCredit)
					newRow.Cells[1].Style.ApplyStyle(noncreditStyle);

				if (!courseTaken.Valid)
					newRow.Cells[3].Style.ApplyStyle(invalidStatusStyle);
                // class id style
                newRow.Cells[0].Style.ApplyStyle( classIDStyle );

				newRow.Tag = courseTaken;				
			}

			lecCreditLabel.Text = totalLecCredit.ToString();
			scienceCreditLabel.Text = totalSciCredit.ToString();
			compCreditLabel.Text = totalCompCredit.ToString();

			this.CheckConflict();

			strikeFont.Dispose();
		}

		#endregion

		private void tabs_Selected(object sender, TabControlEventArgs e)
		{
			if (tabs.SelectedTab == this.assessmentTab)
				this.assessmentControl.PopulateUI();
			if( tabs.SelectedTab == this.courseTab)
				this.ShowRegistration();
		}

		private void refreshToolStripButton_Click(object sender, EventArgs e)
		{
			this.RefreshRegistration();
		}

		private void RefreshRegistration()
		{
			if (MessageBox.Show(this, "Any changes you have made will be discarded, do you want to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
				return;

			this.ShowRegistration();
		}

		private void CheckConflict()
		{			
			foreach( DataGridViewRow row1 in this.grdCourses.Rows )
			{
				CourseTakenByStudent2 course1 = row1.Tag as CourseTakenByStudent2;

				if (null != course1.Section.SectionRoutineCollection)
				{
					foreach (SectionRoutine routine1 in course1.Section.SectionRoutineCollection)
					{
						foreach (DataGridViewRow row2 in this.grdCourses.Rows)
						{
							if (row1 != row2)
							{
								CourseTakenByStudent2 course2 = row2.Tag as CourseTakenByStudent2;

								if (null != course2.Section.SectionRoutineCollection)
								{
									foreach (SectionRoutine routine2 in course2.Section.SectionRoutineCollection)
									{
										if (routine1.Overlap(routine2))
										{
											// Conflict
											row1.Cells[1].Style.BackColor = 
											row2.Cells[1].Style.BackColor = Color.Red;

											row1.Cells[1].Style.ForeColor =
											row2.Cells[1].Style.ForeColor = Color.LightYellow;

										}
									}
								}
							}
						}
					}
				}
			}
		}

		private void CloseMe()
		{
			ICommand command = new CloseCurrentDocumentCommand();
			command.Execute();
		}

		private void worker_DoWork(object sender, DoWorkEventArgs e)
		{
			// This method will run on a thread other than the UI thread.
			// Be sure not to manipulate any Windows Forms controls created
			// on the UI thread from this method.
			this.LoadRegistrationInBackground();
		}

		private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
		{
			
		}

		private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
			if (null == e.Error)
			{
				this.UpdateUI();
			}
			else
			{
				MessageBox.Show(this, e.Error.Message, 
					"Load Registration", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}

			this.progress.Stop();
		}

		private void saveToolStripButton_Click(object sender, EventArgs e)
		{
			this.SaveRegistration();
		}

		private void SaveRegistration()
		{
			// Mark this student model as dirty so that it is saved 
			base.Document.StudentModel.IsDirty = true;
			base.Document.StudentModel.NotifyChange("Save");
		}

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author


| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 17 Aug 2005
Article Copyright 2005 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid