Allot Roll No Form:
#1

Allot Roll No Form:

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 AllotRollNoForm : Form
    {
        OleDbConnection cn = new OleDbConnection(ConnectionStringForSMS.MyConnectionString());
        int l1;
        int l2;
        string m;
        string v;
        string[] val = new string[10];
        public AllotRollNoForm()
        {
            InitializeComponent();
        }

        private void AllotRollNoForm_Load(object sender, EventArgs e)
        {
            label9.Text="Fill All The Details Of Add Section,Then Fill The Admission Form Details, Then Only We Can Allot The RollNo in ";
            label11.Text = "\"Allot RollNo Form\"";
            cbxclassmed.Focus();
            lblsec.Visible = false;
            lblsection.Visible = false;
            txt();
            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 + "-Allot Section And RollNo";
            lbltitle.Text = "";
            lbltitle.Text = schooltitle;
            cbxclassmed.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;
            comboBox1.Text = "--Select--";
            cbxclasssec.Text = "--Select--";
            dataGridView1.Visible = false;
        }

        public void txt()
        {
            textBox1.Visible = false;
            textBox2.Visible = false;
            textBox3.Visible = false;
            textBox4.Visible = false;
            textBox5.Visible = false;
            textBox6.Visible = false;
            textBox7.Visible = false;
            textBox8.Visible = false;
            textBox9.Visible = false;
            textBox10.Visible = false;
            btnupdate.Visible = false;
        }

        public void data()
        {
            OleDbDataAdapter daclass = new OleDbDataAdapter("select ClassID  from Class where ClassName='" + comboBox1.SelectedItem.ToString() + "'and Medium='" + comboBox2.SelectedItem.ToString() + "'", cn);
            DataSet dsclass = new DataSet();
            daclass.Fill(dsclass);
            int classid = Convert.ToInt32(dsclass.Tables[0].Rows[0].ItemArray[0]);
            OleDbDataAdapter dase = new OleDbDataAdapter("select SectionID  from [Section] where [Section]='" + comboBox3.SelectedItem.ToString() + "' and ClassID=" + classid + " and Medium='" + comboBox2.SelectedItem.ToString() + "'", cn);
            DataSet dsse = new DataSet();
            dase.Fill(dsse);
            int seid = Convert.ToInt32(dsse.Tables[0].Rows[0].ItemArray[0]);
            l1 = classid;
            l2 = seid;
            m = comboBox2.SelectedItem.ToString();
            OleDbDataAdapter adpt3 = new OleDbDataAdapter("SELECT Admission.AdmissionNo, Admission.AdmisssionDate, Admission.StudentName, Admission.RollNo,Admission.Active FROM ((Admission INNER JOIN Class ON Admission.ClassID = Class.ClassID) INNER JOIN [Section] ON Admission.SectionID = [Section].SectionID) where Admission.ClassId=" + l1 + " and Admission.Medium='" + m + "' and Admission.SectionId=" + l2 + " and Admission.Active='Yes' order by Admission.StudentName", cn);
            DataSet ds3 = new DataSet();
            adpt3.Fill(ds3);
            if (ds3.Tables[0].Rows.Count != 0)
            {
                dataGridView1.DataSource = ds3.Tables[0];
            }
            else
            {
                dataGridView1.Visible = false;
                MessageBox.Show("No Records", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                comboBox1.SelectedIndex = 0;
                comboBox2.SelectedIndex = 0;
             }
        }

      
        private void btnsubmitsec_Click(object sender, EventArgs e)
        {
          
            if (cbxclassmed.SelectedIndex == -1||cbxclassmed.SelectedIndex ==0)
            {
                MessageBox.Show("Select Medium", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cbxclassmed.Focus();
            }
            else if (cbxclasssec.SelectedIndex == 0)
            {
                MessageBox.Show("Select Class", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cbxclasssec.Focus();
            }
            else if (txtsection.Text.Trim() == "")
            {
                MessageBox.Show("Enter Section", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtsection.Focus();
            }
            else
            {
                OleDbDataAdapter daclass = new OleDbDataAdapter("select ClassID  from Class where ClassName='" + cbxclasssec.SelectedItem.ToString() + "'and Medium='" + cbxclassmed.SelectedItem.ToString() + "'", cn);
                DataSet dsclass = new DataSet();
                daclass.Fill(dsclass);
                int classid = Convert.ToInt32(dsclass.Tables[0].Rows[0].ItemArray[0]);
                OleDbDataAdapter dasection = new OleDbDataAdapter("Select distinct [Section] from [Section] where ClassID=" + classid + " and Medium='" + cbxclassmed.SelectedItem.ToString() + "'and [Section]='"+txtsection.Text+"'", cn);
                DataSet dssection = new DataSet();
                dasection.Fill(dssection);
                if (dssection.Tables[0].Rows.Count != 0)
                {
                    MessageBox.Show("Section Already Exists", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtsection.Focus();
                }
                else
                {
                    int sectionid;
                    OleDbDataAdapter da = new OleDbDataAdapter("select max(SectionID) from [Section]", cn);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    if (ds.Tables[0].Rows[0].ItemArray[0].ToString() == "")
                    {
                        sectionid = 1;
                    }
                    else
                    {
                        sectionid = Convert.ToInt32(ds.Tables[0].Rows[0].ItemArray[0]) + 1;
                    }
                    cn.Open();
                    OleDbCommand cmd = new OleDbCommand("insert into [section](SectionID,[Section],ClassID,Medium) values(" + sectionid + ",'" + txtsection.Text + "'," + classid + ",'" + cbxclassmed.SelectedItem.ToString() + "')", cn);
                    cmd.ExecuteNonQuery();
                    OleDbDataAdapter dasection1 = new OleDbDataAdapter("Select distinct [Section] from [Section] where ClassID=" + classid + " and Medium='" + cbxclassmed.SelectedItem.ToString() + "'", cn);
                    DataSet dssection1 = new DataSet();
                    dasection1.Fill(dssection1);
                    lblsection.Text = "";
                    lblsec.Text = "";
                    lblsection.Visible = true;
                    lblsec.Visible = true;
                    lblsec.Text = "Sections in " + cbxclasssec.SelectedItem.ToString();
                    for (int i = 0; i < dssection1.Tables[0].Rows.Count; i++)
                    {
                        lblsection.Text += dssection1.Tables[0].Rows[i][0].ToString() + "\n";
                    }
                    MessageBox.Show("Successfullly Inserted", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtsection.Text = "";
                    txtsection.Focus();
                    btnmodify.Enabled = true;
                    cn.Close();
                }
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox2.SelectedIndex != -1 && comboBox1.SelectedIndex != 0)
            {
                comboBox3.Text = "--Select--";
                OleDbDataAdapter daclass = new OleDbDataAdapter("select ClassID  from Class where ClassName='" + comboBox1.SelectedItem.ToString() + "'and Medium='" + comboBox2.SelectedItem.ToString() + "'", cn);
                DataSet dsclass = new DataSet();
                daclass.Fill(dsclass);
                int classid = Convert.ToInt32(dsclass.Tables[0].Rows[0].ItemArray[0]);
                OleDbDataAdapter dasection = new OleDbDataAdapter("Select distinct [Section] from [Section] where ClassID=" + classid + " and Medium='" + comboBox2.SelectedItem.ToString() + "'", cn);
                DataSet dssection = new DataSet();
                dasection.Fill(dssection);
                comboBox3.Items.Clear();
                if (dssection.Tables[0].Rows.Count != 0)
                {
                    for (int i = 0; i < dssection.Tables[0].Rows.Count; i++)
                    {
                        comboBox3.Items.Add(dssection.Tables[0].Rows[i][0].ToString());
                    }
                }
                else
                {
                    MessageBox.Show("Add Sections", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cbxclasssec.Focus();
                }
            }
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox2.SelectedIndex!=-1)
            {
                comboBox3.Items.Clear();
                comboBox3.Text = "--Select--";
                comboBox1.Items.Clear();
                OleDbDataAdapter daclass = new OleDbDataAdapter("Select ClassName from Class where Medium='" + comboBox2.SelectedItem.ToString() + "' order by ClassID", cn);
                DataSet dsclass = new DataSet();
                daclass.Fill(dsclass);
                comboBox1.Items.Add("--Select--");
                for (int i = 0; i < dsclass.Tables[0].Rows.Count; i++)
                {
                    comboBox1.Items.Add(dsclass.Tables[0].Rows[i][0].ToString());
                }
                comboBox1.SelectedIndex=0;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox2.SelectedIndex == -1||comboBox2.SelectedIndex ==0)
                {
                    MessageBox.Show("Select Medium", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    comboBox2.Focus();
                }
                else if (comboBox1.SelectedIndex == 0)
                {
                    MessageBox.Show("Select Class", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    comboBox1.Focus();
                }
                else if (comboBox3.SelectedIndex == -1)
                {
                    MessageBox.Show("Select Section", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    comboBox3.Focus();
                }
                else
                {
                    dataGridView1.Visible = true;
                    data();
                }
            }
            catch
            {
                MessageBox.Show("Try Again", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int rowid = e.RowIndex;
                int colid = e.ColumnIndex;
                string ano = dataGridView1[0, rowid].Value.ToString();
                string content = dataGridView1[3, rowid].Value.ToString();
                OleDbDataAdapter adpt3 = new OleDbDataAdapter("SELECT Admission.RollNo FROM ((Admission INNER JOIN Class ON Admission.ClassID = Class.ClassID) INNER JOIN [Section] ON Admission.SectionID = [Section].SectionID) where Admission.ClassId=" + l1 + " and Admission.Medium='" + m + "' and Admission.SectionId=" + l2 + " and Admission.RollNo='" + content + "' and Admission.Active='Yes' order by Admission.StudentName", cn);
                DataSet ds3 = new DataSet();
                adpt3.Fill(ds3);
                if (ds3.Tables[0].Rows.Count != 0)
                {
                    MessageBox.Show("already exists", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    data();
                }
                else
                {
                    cn.Open();
                    OleDbCommand cmd = new OleDbCommand("update Admission set RollNo='" + content + "' where AdmissionNo='" + ano + "'", cn);
                    cmd.ExecuteNonQuery();
                    cn.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            int roid = e.RowIndex;
            v = dataGridView1[3, roid].Value.ToString();
        }

        private void txtsection_Leave(object sender, EventArgs e)
        {
            txtsection.Text = ConnectionStringForSMS.Capitalize(txtsection.Text);
        }


        private void textBox1_Leave(object sender, EventArgs e)
        {
            textBox1.Text = ConnectionStringForSMS.Capitalize(textBox1.Text);
            OleDbDataAdapter daclass = new OleDbDataAdapter("select ClassID  from Class where ClassName='" + cbxclasssec.SelectedItem.ToString() + "'and Medium='" + cbxclassmed.SelectedItem.ToString() + "'", cn);
            DataSet dsclass = new DataSet();
            daclass.Fill(dsclass);
            int classid = Convert.ToInt32(dsclass.Tables[0].Rows[0].ItemArray[0]);
            OleDbDataAdapter dasub = new OleDbDataAdapter("Select distinct [Section] from [Section] where ClassID=" + classid + " and Medium='" + cbxclassmed.SelectedItem.ToString() + "'and [Section]='" + textBox1.Text + "'", cn);
            DataSet dssub = new DataSet();
            dasub.Fill(dssub);
            if (dssub.Tables[0].Rows.Count != 0 && val[0] != textBox1.Text)
            {
                MessageBox.Show("Already Exists", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox1.Focus();
            }
            else
            {

            }
        }

Note: Same for all Text Boxes…

        private void cbxclasssec_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbxclasssec.SelectedIndex != 0&&cbxclasssec.SelectedIndex!=-1)
            {
                OleDbDataAdapter daclass = new OleDbDataAdapter("select ClassID  from Class where ClassName='" + cbxclasssec.SelectedItem.ToString() + "'and Medium='" + cbxclassmed.SelectedItem.ToString() + "'", cn);
                DataSet dsclass = new DataSet();
                daclass.Fill(dsclass);
                int classid = Convert.ToInt32(dsclass.Tables[0].Rows[0].ItemArray[0]);
                OleDbDataAdapter dasection = new OleDbDataAdapter("Select distinct [Section] from [Section] where ClassID=" + classid + " and Medium='" + cbxclassmed.SelectedItem.ToString() + "'", cn);
                DataSet dssection = new DataSet();
                dasection.Fill(dssection);
                if (dssection.Tables[0].Rows.Count != 0)
                {
                    lblsection.Text = "";
                    lblsec.Text = "";
                    lblsection.Visible = true;
                    lblsec.Visible = true;
                    lblsec.Text = "Sections in " + cbxclasssec.SelectedItem.ToString();
                    for (int i = 0; i < dssection.Tables[0].Rows.Count; i++)
                    {
                        lblsection.Text += dssection.Tables[0].Rows[i][0].ToString() + "\n";
                    }
                    btnsubmitsec.Enabled = true;
                    btnmodify.Enabled = true;
                    txtsection.Enabled = true;
                    txt();
                }
                else
                {
                    lblsec.Visible = false;
                    lblsection.Text = "";
                }
            }
        }

        private void cbxclassmed_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbxclassmed.SelectedIndex != -1)
            {
                txtsection.Text = "";
                cbxclasssec.Items.Clear();
                OleDbDataAdapter daclass = new OleDbDataAdapter("Select ClassName from Class where Medium='" + cbxclassmed.SelectedItem.ToString() + "' order by ClassID", cn);
                DataSet dsclass = new DataSet();
                daclass.Fill(dsclass);
                cbxclasssec.Items.Add("--Select--");
                for (int i = 0; i < dsclass.Tables[0].Rows.Count; i++)
                {
                    cbxclasssec.Items.Add(dsclass.Tables[0].Rows[i][0].ToString());
                }
                cbxclasssec.SelectedIndex = 0;
            }
            btnsubmitsec.Enabled = true;
            btnmodify.Enabled = true;
            txtsection.Enabled = true;
            txt();
        }

        private void btnclear_Click(object sender, EventArgs e)
        {
            cbxclasssec.Items.Clear();
            cbxclassmed.SelectedIndex = -1;
            cbxclassmed.Text="--Select--";
            cbxclasssec.SelectedIndex = -1;
            cbxclasssec.Text = "--Select--";
            lblsec.Text = "";
            lblsection.Text = "";
            txt();
            txtsection.Text = "";
            comboBox2.SelectedIndex = -1;
            comboBox2.Text = "--Select--";
            comboBox1.Items.Clear();
            comboBox1.Text = "--Select--";
            comboBox3.Items.Clear();
            comboBox3.Text = "--Select--";
            dataGridView1.Visible = false;
            cbxclassmed.Focus();
        }

        private void btnclose_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Close();
            SettringsForm s = new SettringsForm();
            s.Show();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            this.Close();
            SMSMainForm a = new SMSMainForm();
            a.Show();
        }
    }
}

Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: anti roll suspension, sumi e paper roll, small roll top desks, madhyamik result by roll, roll 3928, roll tops documentation, roll of chemestry in domestic activitis,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  What are steps involved in creating a form in Access? smart paper boy 0 1,237 29-07-2011, 12:15 PM
Last Post: smart paper boy
  Marks Entry Form.cs seminar class 0 1,233 07-05-2011, 02:59 PM
Last Post: seminar class
  Entry Forms ,Admission Form: seminar class 0 1,280 07-05-2011, 02:53 PM
Last Post: seminar class

Forum Jump: