Click here to Skip to main content
15,891,423 members
Articles / Web Development / ASP.NET

Integrated College Management System[Credit Hours Sys.] --Part 1-- Class Library & Database

Rate me:
Please Sign up or sign in to vote.
3.90/5 (24 votes)
21 May 2005CC (ASA 2.5)8 min read 103.5K   7.5K   47  
This project is established for helping students to make registration easily. It also simplifies this process for both students and employees and prevent usual problems the Credit Hours System faces.
//==========================================================================================//
//                                                                                          //
//                                             www.sansoft.tk                               //
//                                        Advanced Software solutions                       //
//                                                  Egypt                                   //
//                                                                                          //
//                                   Integrated College Management System                   //
//                                              Class Library                               //
//                                                                                          //
//                                          the code Developed by:                          //
//                                    Ameen Abudbush [ ameen@sansoft.tk ]                   //
//                                    Mohamed Elmashad [ elmashad@sansoft.tk ]              //
//                                                                                          //
//                                   Email: info@sansoft.tk  T:  +2 012 3591584             //
//==========================================================================================//


using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Mail;
using System.Data.SqlTypes;
using System.Collections;


namespace Registration_System_class
{
	/// <summary>
	/// Summary description for Student.
	/// </summary>
	public class Student:Person
	{	
		public readonly StudentLevel studentlevel;
		public readonly bool Late;
		public readonly string  Department;
		public readonly string CurrentTerm;
		public readonly float StudentSum;
		public readonly DateTime TermStratDate;
		public readonly TermType termtype;

		private  ArrayList myresult;
		private QuareTable	MyTable;
		public QuareTable GetMyTable
		{
			get
			{	
				this.MyTable=new QuareTable(myconnection,this.serial,TableOperation.StudentQueryLec);
				return MyTable;
			}
		}
		public Student(SqlConnection myconn,string myserial):base(myconn,myserial)
		{
			String SqlString="SELECT * FROM Student Where Student='"+this.serial.Trim()+"'";
			SqlDataReader MyDataReader;
			try
			{
				if(myconnection.State==ConnectionState.Closed)
				{
					myconnection.Open();
				}
				SqlCommand MyCommand=new SqlCommand(SqlString,myconnection);
				MyDataReader=MyCommand.ExecuteReader();
				while(MyDataReader.Read())
				{	
					this.Department=MyDataReader["Department"].ToString();
					this.studentlevel=Myconvert.convettolevel(Convert.ToInt16(MyDataReader["Slevel"]));
					MyDataReader.Close();
					/////////////////////////////////////
					string sql="Select Student from Late where Student='"+this.serial+"'";
					MyCommand=new SqlCommand(sql,myconnection);
					MyDataReader=MyCommand.ExecuteReader();
					this.Late=MyDataReader.HasRows;
					MyDataReader.Close();
					///////////////////////////////////////////
					//sql="SELECT Sum(Result) as stu_sum ";
					//sql+="FROM Result where Student='"+this.serial+"'";
					//MyCommand=new SqlCommand(sql,myconnection);
					//this.StudentSum=float.Parse(MyCommand.ExecuteScalar().ToString());;
					//while(MyDataReader.Read())
					//{
					//	this.StudentSum=float.Parse(MyDataReader["stu_sum"].ToString());
					//}
					//MyDataReader.Close();
					///////////////////////////////
					sql="select top 1 * from Term ";
					sql+="order by Term.Term desc";
					MyCommand=new SqlCommand(sql,myconnection);
					MyDataReader=MyCommand.ExecuteReader();
					while(MyDataReader.Read())
					{
						this.CurrentTerm=MyDataReader["Term"].ToString();
						this.TermStratDate=Convert.ToDateTime(MyDataReader["Startdate"]);
						this.termtype=Myconvert.convettotermtype(Convert.ToInt16(MyDataReader["Type"]));
					}
					MyDataReader.Close();
					//////////////////////////////////////////
					sql="SELECT * FROM Result join Subject on Result.Subject=Subject.Subject where Student='"+this.serial+"'"; 
					MyCommand=new SqlCommand(sql,myconnection);
					MyDataReader=MyCommand.ExecuteReader();
					if(MyDataReader.HasRows)
					{myresult=new ArrayList();this.StudentSum=0;}
					while(MyDataReader.Read())
					{
						myresult.Add(new SubjectResult(MyDataReader["Name"].ToString(),MyDataReader["Term"].ToString(),float.Parse(MyDataReader["Result"].ToString())));
						this.StudentSum+=float.Parse(MyDataReader["Result"].ToString());
					}
					MyDataReader.Close();
					myconnection.Close();
					this.MyTable=new QuareTable(myconnection,this.serial,TableOperation.StudentQueryLec);
					return;
				}
				MyDataReader.Close();
				myconnection.Close();
				throw(new Exception("CMS APPLICATION:No Location Have this Serial"));
			}
			catch(Exception e)
			{
				throw (e);
			}
			finally
			{	
				if(myconnection.State==ConnectionState.Open)
				{
					myconnection.Close();
				}
			}
		}
	
		public static String GenrateSerial(SqlConnection mycon)
		{
			if(mycon.State==ConnectionState.Closed)
			{
				mycon.Open();
			}
			String sqlstring="select max(serial) as Maxserial From Login ";
			sqlstring+=" Where serial like 'S'+'%'";
			try
			{
				SqlCommand MyCommand=new SqlCommand(sqlstring,mycon);
				SqlDataReader MyDatareader=MyCommand.ExecuteReader();
				while(MyDatareader.Read())
				{	
					string newserial=MyDatareader["Maxserial"].ToString();
					string subnewserial=newserial.Substring(3);
					int x=Int32.Parse(subnewserial)+1;
					MyDatareader.Close();
					mycon.Close();
					string s;
					if(x<10)s="0000"+x.ToString();
					else if(x<100)s="000"+x.ToString();
					else if(x<1000)s="00"+x.ToString();
					else if(x<10000)s="0"+x.ToString();
					else s=x.ToString();
					return(newserial.Substring(0,1)+DateTime.Now.Year.ToString().Substring(2,2)+s);
				}
				throw(new Exception("CMS application: un exception error "));
			}
			catch(Exception e)
			{
				throw(e);
			}
			finally
			{
				if(mycon.State==ConnectionState.Open)mycon.Close();
			}
		}
		public ArrayList Result()
		{
			return myresult;
		}
		public Table SubjectCanITake()
		{
			Table tab=new Table();
			if(myconnection.State==ConnectionState.Closed)
			{
				myconnection.Open();
			}
			try
			{
				SqlCommand MyCommand=new SqlCommand("SubjectCanITake",myconnection);
				MyCommand.CommandType=CommandType.StoredProcedure;
				SqlParameter myparameter=MyCommand.Parameters.Add("@Student",SqlDbType.Char,8);
				myparameter.Direction=ParameterDirection.Input;
				myparameter.Value=this.serial;

				SqlDataReader MyDatareader=MyCommand.ExecuteReader();
				while(MyDatareader.Read())
				{
						tab.Add(
						new Subject(MyDatareader["Name"].ToString(),MyDatareader["Subject"].ToString(),float.Parse(MyDatareader["Credit"].ToString())),
						new Location(myconnection,MyDatareader["Location"].ToString(),Myconvert.converttolocation(Convert.ToInt16(MyDatareader["loctype"]))),
						new MyTimeLec(Myconvert.converttodayofweek(Convert.ToInt16(MyDatareader["Subjectday"])),Myconvert.convettohoure(Convert.ToInt16(MyDatareader["Starthour"])),Myconvert.convettohoure(Convert.ToInt16(MyDatareader["Endhour"])))
							);
				}
				MyDatareader.Close();
				myconnection.Close();
				return tab;
			}
			catch(Exception e)
			{
				throw e;
			}
			finally
			{
				if(myconnection.State==ConnectionState.Open)myconnection.Close();
			}

		}
		
		public bool RegstNow (Table tab)
		{
			
			if(this.MyTable.TableSubjectCount>0)return false;
			if(!tab.TimePlan)
			{
				System.Collections.ArrayList OutPut;
				if(tab.CheckTimeplan(out OutPut))return false;
			}
		if(myconnection.State==ConnectionState.Closed)
				{
					myconnection.Open();
				}
		SqlTransaction MyTran=myconnection.BeginTransaction();
				try
				{
					foreach(SubjectLecture Suba in tab)
					{	
						SqlCommand MyCommand=new SqlCommand();
						MyCommand.Transaction=MyTran;
						MyCommand.Connection=myconnection;
						MyCommand.CommandText="insert into Currentterm(Student,Subject) ";
						MyCommand.CommandText+="values('"+this.serial+"','"+Suba.subInfo.GetSerial+"')";
						MyCommand.ExecuteNonQuery();
					}
					MyTran.Commit();
					if(myconnection.State==ConnectionState.Open)myconnection.Close();
					return true;
				}
				catch(Exception)
				{
					MyTran.Rollback();
					return false;
				}
				finally
				{	
					if(myconnection.State==ConnectionState.Open)
					{
						myconnection.Close();
					}
				}
			}
	///////////////////////////////////////////////////////////
		public static  ArrayList Students(SqlConnection mycon)
		{
			String SqlString="SELECT login.serial, Login.[name] FROM Student join Login on Student.Student=login.serial";
			SqlDataReader MyDataReader;
			try
			{
				if(mycon.State==ConnectionState.Closed)
				{
					mycon.Open();
				}
				ArrayList StudentList=new ArrayList();
				SqlCommand MyCommand=new SqlCommand(SqlString,mycon);
				MyDataReader=MyCommand.ExecuteReader();
				while(MyDataReader.Read())
				{	
					Actorinfo d=new Actorinfo();
					d.ActorName=MyDataReader["name"].ToString();
					d.Actorserial=MyDataReader["serial"].ToString();
					StudentList.Add(d);
				}
				MyDataReader.Close();
				mycon.Close();
				return StudentList;
				
			}
			catch(Exception e)
			{
				throw (e);
			}
			finally
			{	
				if(mycon.State==ConnectionState.Open)
				{
					mycon.Close();
				}
			}
		}
		public bool AddRemoveWithdrow(Table tab)
		{
			
			if(this.MyTable.TableSubjectCount==0)return false;
			if(!tab.TimePlan)
			{
				System.Collections.ArrayList OutPut;
				if(tab.CheckTimeplan(out OutPut))return false;
			}
			if(myconnection.State==ConnectionState.Closed)
			{
				myconnection.Open();
			}
			SqlTransaction MyTran=myconnection.BeginTransaction();
			try
			{	
				foreach(SubjectLecture Suba in this.MyTable)
				{	
					if(tab.Contains(Suba.subInfo.GetSerial)){tab.RemoveFromTable(Suba.subInfo.GetSerial); continue;}
					SqlCommand MyCommand=new SqlCommand();
					MyCommand.Transaction=MyTran;
					MyCommand.Connection=myconnection;
					MyCommand.CommandText="delete from Currentterm Where Student='"+this.serial+"' and Subject='"+Suba.subInfo.GetSerial+"'";
					MyCommand.ExecuteNonQuery();
				}
				foreach(SubjectLecture Suba in tab)
					{	
						SqlCommand MyCommand=new SqlCommand();
						MyCommand.Transaction=MyTran;
						MyCommand.Connection=myconnection;
						MyCommand.CommandText="insert into Currentterm(Student,Subject) ";
						MyCommand.CommandText+="values('"+this.serial+"','"+Suba.subInfo.GetSerial+"')";
						MyCommand.ExecuteNonQuery();
					}

				MyTran.Commit();
				if(myconnection.State==ConnectionState.Open)myconnection.Close();
				return true;
			}
			catch(Exception)
			{
				MyTran.Rollback();
				return false;
			}
			finally
			{	
				if(myconnection.State==ConnectionState.Open)
				{
					myconnection.Close();
				}
			}
		}

	}
}

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, along with any associated source code and files, is licensed under The Creative Commons Attribution-ShareAlike 2.5 License


Written By
Team Leader
United Arab Emirates United Arab Emirates
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions