07-05-2011, 02:59 PM
Student Details:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace SchoolManagementSystem
{
public partial class StudentDetails : Form
{
OleDbConnection cn = new OleDbConnection(ConnectionStringForSMS.MyConnectionString());
int l1;
int l2;
string m;
int classid, sectionid;
public StudentDetails()
{
InitializeComponent();
}
private void StudentDetails_Load(object sender, EventArgs e)
{
try
{
OleDbDataAdapter da23 = new OleDbDataAdapter("select schooltitle,Address from schooltitle", cn);
DataSet ds23 = new DataSet();
da23.Fill(ds23);
string schooltitle = ds23.Tables[0].Rows[0].ItemArray[0].ToString();
string address = ds23.Tables[0].Rows[0].ItemArray[1].ToString();
this.Text = schooltitle + "-Student Details Report";
label5.Text = "";
label5.Text = schooltitle;
cn.Open();
dataGridView1.Visible = false;
}
catch (Exception e1)
{
MessageBox.Show(e1.ToString());
}
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
label3.Visible = false;
comboBox2.Visible = false;
dataGridView1.Refresh();
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
label3.Visible = true;
comboBox2.Visible = true;
dataGridView1.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (comboBox3.SelectedIndex == -1)
{
MessageBox.Show("Select Medium");
dataGridView1.Visible = false;
comboBox3.Focus();
}
else if (comboBox1.SelectedIndex == -1)
{
MessageBox.Show("Select Class", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
dataGridView1.Visible = false;
comboBox1.Focus();
}
else if (comboBox2.SelectedIndex == -1)
{
MessageBox.Show("Select Section", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
dataGridView1.Visible = false;
comboBox2.Focus();
}
else
{
dataGridView1.Visible = true;
l1 = Convert.ToInt32(comboBox1.SelectedIndex.ToString());
l2 = Convert.ToInt32(comboBox2.SelectedIndex.ToString());
l2 = l2 + 1;
m = comboBox3.SelectedItem.ToString();
OleDbDataAdapter adpt3 = new OleDbDataAdapter("SELECT A.AdmissionNo,A.AdmisssionDate,A.StudentName,A.FatherName,A.Age,Cl.ClassName,S.[Section],A.Medium,A.FirstName,A.MiddleName, A.SurName,A.DateofBirth,A.Gender,A.ResidentAddress,A.Nationality,A.Pincode,A.Telphone,C.Category,A.RollNo,A.IsBusTraveller,A.Active,A.OccuFather as PrarentOccupation,A.MotherTongue,A.Religion,CCC.ClassName as AdmisssionClass,A.SchoolCome as PreviousSchool,A.PreviousTC,A.SmallPox,A.PerIdentification as Moles FROM Admission A,Category C,Class Cl,Class CCC,[Section] S where A.CategoryID = C.CategoryID and A.SectionID = S.SectionID and A.ClassID = Cl.ClassID and A.ClassIDOnAdmission=CCC.ClassID and Cl.ClassName='" + comboBox1.SelectedItem.ToString() + "' and S.[Section]='" + comboBox2.SelectedItem.ToString() + "' and A.Medium='" + m + "' and A.Active='Yes' ", cn);
DataSet ds3 = new DataSet();
adpt3.Fill(ds3);
dataGridView1.DataSource = ds3.Tables[0];
}
}
catch (Exception e2)
{
MessageBox.Show("Try Again", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, EventArgs e)
{
StudentDetailsReport sdr = new StudentDetailsReport(classid,sectionid,m);
sdr.Show();
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Items.Clear();
comboBox2.Items.Clear();
OleDbDataAdapter da = new OleDbDataAdapter("SELECT ClassName FROM Class WHERE (Medium = '" + comboBox3.SelectedItem.ToString() + "')", cn);
DataSet ds = new DataSet();
da.Fill(ds);
comboBox1.DisplayMember = "ClassName";
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
comboBox1.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
}
}
else
{
comboBox1.Text = "";
MessageBox.Show("No Subjects", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Clear();
comboBox2.Text = "--Select--";
OleDbDataAdapter da1 = new OleDbDataAdapter("SELECT ClassID FROM Class WHERE (ClassName = '" + comboBox1.SelectedItem.ToString() + "') and Medium='" + comboBox3.SelectedItem.ToString() + "'", cn);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
if (ds1.Tables[0].Rows.Count != 0)
{
classid = Convert.ToInt32(ds1.Tables[0].Rows[0][0].ToString());
}
OleDbDataAdapter da = new OleDbDataAdapter("SELECT [Section] FROM [Section] WHERE (ClassId = " + classid + ") and Medium='" + comboBox3.SelectedItem.ToString() + "'", cn);
DataSet ds = new DataSet();
da.Fill(ds);
comboBox2.DisplayMember = "Section";
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
comboBox2.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString());
}
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
OleDbDataAdapter da = new OleDbDataAdapter("SELECT SectionID FROM [Section] WHERE ([Section] = '" + comboBox2.SelectedItem.ToString() + "') and (ClassId = " + classid + ") and (Medium='" + comboBox3.SelectedItem.ToString() + "') ", cn);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
sectionid = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.Close();
ReportsForm r = new ReportsForm();
r.Show();
}
private void pictureBox2_Click(object sender, EventArgs e)
{
this.Close();
SMSMainForm a = new SMSMainForm();
a.Show();
}
}
}