SetClassForm.cs
#1

SetClassForm.cs

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 SetClassForm : Form
    {
        OleDbConnection cn = new OleDbConnection(ConnectionStringForSMS.MyConnectionString());
        string schooltitle,address;
        int classid;
        string[] val = new string[15];
        string Sval = null;
        public SetClassForm()
        {
            InitializeComponent();
        }

        private void SetClassForm_Load(object sender, EventArgs e)
        {
            OleDbDataAdapter datitle = new OleDbDataAdapter("select SchoolTitle from Schooltitle", cn);
            DataSet dstitle = new DataSet();
            datitle.Fill(dstitle);
            if (dstitle.Tables[0].Rows.Count != 0)
            {
                schooltitle = dstitle.Tables[0].Rows[0]["SchoolTitle"].ToString();
                lbltitle.Text = schooltitle;
            }
            this.Text = schooltitle + "-Add Class";
            pnlDisplay.Visible = false;
            pnlModify.Visible = false;
            pnlDeletion.Visible = false;
            cbMedium.SelectedIndex = 0;
        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            try
            {
                if (cbMedium.Text == "-- Select --")
                {
                    MessageBox.Show("Select Medium", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cbMedium.Focus();
                }
                else if (txtClass.Text.Trim() == "")
                {
                    MessageBox.Show("Enter Class Name", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtClass.Focus();
                }
                else
                {
                    txtClass.Text = ConnectionStringForSMS.AllCapitalize(txtClass.Text);
                    cn.Open();
                    OleDbDataAdapter daClassName = new OleDbDataAdapter("select ClassName from Class where Medium='"+cbMedium.SelectedItem.ToString()+"' and ClassName='"+txtClass.Text+"'", cn);
                    DataSet dsClassName = new DataSet();
                    daClassName.Fill(dsClassName);
                    if (dsClassName.Tables[0].Rows.Count != 0)
                    {
                        MessageBox.Show("Already Exists with same Class Name in  "+cbMedium.SelectedItem.ToString()+" Medium.");
                        txtClass.Focus();
                    }
                    else
                    {
                        OleDbDataAdapter daClassID = new OleDbDataAdapter("select max(ClassID) as ClassId from Class", cn);
                        DataSet dsClassID = new DataSet();
                        daClassID.Fill(dsClassID);
                        if (dsClassID.Tables[0].Rows.Count != 0)
                        {
                            string data = dsClassID.Tables[0].Rows[0]["ClassID"].ToString();
                            if (data == "")
                            {
                                classid = 1;
                            }
                            else
                            {
                                int no = Convert.ToInt32(dsClassID.Tables[0].Rows[0]["ClassID"].ToString());
                                no = no + 1;
                                classid = no;
                            }
                        }
                        else
                        {
                            classid = 1;
                        }
                        OleDbDataAdapter datitle = new OleDbDataAdapter("select SchoolTitle,Address from Schooltitle", cn);
                        DataSet dstitle = new DataSet();
                        datitle.Fill(dstitle);
                        if (dstitle.Tables[0].Rows.Count != 0)
                        {
                            schooltitle = dstitle.Tables[0].Rows[0]["SchoolTitle"].ToString();
                            address = dstitle.Tables[0].Rows[0]["Address"].ToString();
                        }
                        else
                        {
                            schooltitle = "";
                            address = "";
                        }
                        string classname = ConnectionStringForSMS.AllCapitalize(txtClass.Text);
                        OleDbCommand cmd = new OleDbCommand("insert into Class values(" + classid + ",'" + classname.Trim() + "','" + cbMedium.SelectedItem.ToString().Trim() + "','" + schooltitle + "','" + address + "')", cn);
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("Successfully Inserted", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtClass.Text = "";
                        txtClass.Focus();
                        RetriveData();
                    }
                }
                cn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void txtClass_Leave(object sender, EventArgs e)
        {
            txtClass.Text = ConnectionStringForSMS.AllCapitalize(txtClass.Text);
            //txtClass.Text = ConnectionStringForSMS.Capitalize(txtClass.Text);
        }
        public void unvisiable()
        {
            txtMclass1.Visible=false;
            txtMclass2.Visible = false;
            txtMclass3.Visible = false;
            txtMclass4.Visible = false;
            txtMclass5.Visible = false;
            txtMclass6.Visible = false;
            txtMclass7.Visible = false;
            txtMclass8.Visible = false;
            txtMclass9.Visible = false;
            txtMclass10.Visible = false;
            txtMclass11.Visible = false;
            txtMclass12.Visible = false;
            txtMclass13.Visible = false;
            txtMclass14.Visible = false;
            txtMclass15.Visible = false;
            txtMclass16.Visible = false;
        
        }

        public void RetriveData()
        {
            OleDbDataAdapter da1 = new OleDbDataAdapter("select ClassName from Class where Medium='" + cbMedium.SelectedItem.ToString() + "'", cn);
            DataSet ds1 = new DataSet();
            da1.Fill(ds1);
            if (ds1.Tables[0].Rows.Count != 0)
            {
                pnlDisplay.Visible = true;
                lblDclassList.Text = "";
                lblClassDtitle.Text = "";
                lblClassDtitle.Text = "Class List in " + cbMedium.SelectedItem.ToString() + " Medium";
                for (int s = 0; s < ds1.Tables[0].Rows.Count; s++)
                {
                    lblDclassList.Text += ds1.Tables[0].Rows[s]["ClassName"].ToString() + "\n";

                }
                pnlDisplay.Visible = true;
            }
            else
            {
                pnlDisplay.Visible = false;
            }
            pnlDeletion.Visible = false;
            pnlModify.Visible = false;
            
        }

        private void btndelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (cbMedium.Text == "-- Select --")
                {
                    MessageBox.Show("Select Medium for Class", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cbMedium.Focus();
                }
                else
                {
                    btnsave.Enabled = false;
                    btnmodify.Enabled = false;
                    btndelete.Enabled = false;
                    pnlDeletion.Visible = true;
                    txtClass.Enabled = false;
                    lblDelTitle.Text = "";
                    lblDelTitle.Text = "Deletion  Of Class Names in " + cbMedium.SelectedItem.ToString() + " Medium";
                    OleDbDataAdapter da2 = new OleDbDataAdapter("select ClassName from Class where Medium='" + cbMedium.SelectedItem.ToString() + "'", cn);
                    DataSet ds2 = new DataSet();
                    da2.Fill(ds2);
                    if (ds2.Tables[0].Rows.Count != 0)
                    {
                        chkClassList.Items.Clear();
                        for (int s = 0; s < ds2.Tables[0].Rows.Count; s++)
                        {
                            chkClassList.Items.Add(ds2.Tables[0].Rows[s].ItemArray[0].ToString());

                        }


                    }
                    else
                    {
                        pnlDeletion.Visible = false;
                        pnlDisplay.Visible = false;
                        pnlModify.Visible = false;
                        MessageBox.Show("No Class Names in " + cbMedium.SelectedItem.ToString() + " Medium for Deletions.");
                        btnsave.Enabled = true;
                        btnmodify.Enabled = true;
                        btndelete.Enabled = true;
                        txtClass.Enabled = true;
                        cbMedium.SelectedIndex = 0;
                        txtClass.Text = "";
                    }


                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public void clear()
        {
            cbMedium.SelectedIndex = 0;
            txtClass.Text = "";
            pnlDeletion.Visible = false;
            pnlDisplay.Visible = false;
            pnlModify.Visible = false;
            btnsave.Enabled = true;
            btnmodify.Enabled = true;
            btndelete.Enabled = true;
            txtClass.Enabled = true;
        }
      
        private void btnclear_Click(object sender, EventArgs e)
        {
            clear();
        }

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

        private void cbMedium_SelectedIndexChanged(object sender, EventArgs e)
        {
            pnlDeletion.Visible = false;
            pnlModify.Visible = false;
            pnlDisplay.Visible = true;
            btnmodify.Enabled = true;
            btndelete.Enabled = true;
            btnsave.Enabled = true;
            OleDbDataAdapter da1 = new OleDbDataAdapter("select ClassName from Class where Medium='" + cbMedium.SelectedItem.ToString() + "'", cn);
            DataSet ds1 = new DataSet();
            da1.Fill(ds1);
            if (ds1.Tables[0].Rows.Count != 0)
            {
                pnlDisplay.Visible = true;
                lblDclassList.Text = "";
                lblClassDtitle.Text = "";
                lblClassDtitle.Text = "Class List in "+cbMedium.SelectedItem.ToString() +" Medium";
                for (int s = 0; s < ds1.Tables[0].Rows.Count; s++)
                {
                    lblDclassList.Text += ds1.Tables[0].Rows[s]["ClassName"].ToString() + "\n";
                    
                }
            }
            else
            {
                pnlDisplay.Visible = false;
            }
        }

        private void txtMclass1_Leave(object sender, EventArgs e)
        {
            txtMclass1.Text = ConnectionStringForSMS.AllCapitalize(txtMclass1.Text);
            OleDbDataAdapter dd1 = new OleDbDataAdapter("select ClassName from Class where ClassName='" + txtMclass1.Text + "' and Medium='" + cbMedium.SelectedItem.ToString() + "'", cn);
            DataSet dt1 = new DataSet();
            dd1.Fill(dt1);
            if (dt1.Tables[0].Rows.Count != 0 &&val[0]!=txtMclass1.Text)
            {
                MessageBox.Show("Already Exists with same Class Name in  " + cbMedium.SelectedItem.ToString() + " Medium.", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMclass1.Focus();
            }
            else
            {
                btnupdate.Focus();
            }
          
        }



Note: Same for All Class like txtMclass2_Leave, txtMclass3_Leave...
      

        private void btnDelSeleted_Click(object sender, EventArgs e)
        {
            try
            {
                cn.Open();
                if (chkClassList.CheckedItems.Count != 0)
                {
                    for (int i = 0; i < chkClassList.CheckedItems.Count; i++)
                    {
                        OleDbDataAdapter daclassid = new OleDbDataAdapter("select ClassID from Class where ClassName='" + chkClassList.CheckedItems[i].ToString() + "' and Medium='" + cbMedium.SelectedItem.ToString() + "'", cn);
                        DataSet dsclassid = new DataSet();
                        daclassid.Fill(dsclassid);
                        classid = Convert.ToInt32(dsclassid.Tables[0].Rows[0]["ClassID"].ToString());
                        OleDbCommand cmd = new OleDbCommand("Delete from Class where ClassName='" + chkClassList.CheckedItems[i].ToString() + "'and ClassID=" + classid + " and Medium='" + cbMedium.SelectedItem.ToString() + "'", cn);
                        cmd.ExecuteNonQuery();
                    }
                    MessageBox.Show("Successfully Deleted", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    RetriveData();
                    pnlDeletion.Visible = false;
                    btnsave.Enabled = true;
                    btnmodify.Enabled = true;
                    btndelete.Enabled = true;
                    txtClass.Enabled = true;
                }
                else
                {
                    MessageBox.Show("Select Any Class Name", "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                cn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "School Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }


        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 aa = new SMSMainForm();
            aa.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: jubosree from fill up, false gfr,

[-]
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)

Forum Jump: