Ejemplo n.º 1
0
        private void cmbClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            CmbSection.Items.Clear();
            CmbSection.Text    = "";
            CmbSection.Enabled = true;
            CmbSection.Focus();

            try
            {
                con = new SqlConnection(cs.DBcon);
                con.Open();


                string ct = "select distinct RTRIM(Section) from  class  where ClassName = '" + cmbClass.Text + "'";

                cmd            = new SqlCommand(ct);
                cmd.Connection = con;

                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    CmbSection.Items.Add(rdr[0]);
                }
                con.Close();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtGender.Text == "")
                {
                    MessageBox.Show("Please select gender", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtGender.Focus();
                    return;
                }
                if (cmbCategory.Text == "")
                {
                    MessageBox.Show("Please select Category", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cmbCategory.Focus();
                    return;
                }
                if (txtFathername.Text == "")
                {
                    MessageBox.Show("Please enter father's name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtFathername.Focus();
                    return;
                }
                if (txtSession.Text == "")
                {
                    MessageBox.Show("Please enter session", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtSession.Focus();
                    return;
                }
                if (dtpDOB.Text == "")
                {
                    MessageBox.Show("Please enter dob", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtpDOB.Focus();
                    return;
                }

                if (txtMotherName.Text == "")
                {
                    MessageBox.Show("Please enter mother's name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtMotherName.Focus();
                    return;
                }

                if (cmbReligion.Text == "")
                {
                    MessageBox.Show("Please select religion", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cmbReligion.Focus();
                    return;
                }
                if (txtPermanentAddress.Text == "")
                {
                    MessageBox.Show("Please select address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtPermanentAddress.Focus();
                    return;
                }

                if (txtContactNo.Text == "")
                {
                    MessageBox.Show("Please enter contact no.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtContactNo.Focus();
                    return;
                }
                if (txtEmailID.Text == "")
                {
                    MessageBox.Show("Please enter email", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtEmailID.Focus();
                    return;
                }
                if (cmbClass.Text == "")
                {
                    MessageBox.Show("Please select class", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cmbClass.Focus();
                    return;
                }
                if (CmbSection.Text == "")
                {
                    MessageBox.Show("Please select Section", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    CmbSection.Focus();
                    return;
                }

                if (cmbSchoolName.Text == "")
                {
                    MessageBox.Show("Please select SchoolName", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cmbSchoolName.Focus();
                    return;
                }

                if (txtNationality.Text == "")
                {
                    MessageBox.Show("Please enter nationality", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtNationality.Focus();
                    return;
                }
                auto();

                con = new SqlConnection(cs.DBcon);
                con.Open();

                string cb = "insert into Student(AdmissionNo, EnrollmentNo, StudentName, FatherName, MotherName, FatherCN, PermanentAddress, TemporaryAddress, ContactNo, EmailID, DOB, Gender, AdmissionDate, Session, Caste, Religion, Class,Photo, Status,Nationality,Section,SchoolID) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9,@d10,@d11,@d12,@d13,@d14,@d15,@d16,@d17,@d18,@d19,@d20,@d21,@d22)";  //id  li

                cmd = new SqlCommand(cb);

                cmd.Connection = con;
                cmd.Parameters.AddWithValue("@d1", txtAdmissionNo.Text);
                cmd.Parameters.AddWithValue("@d2", txtEnrollmentNo.Text);
                cmd.Parameters.AddWithValue("@d3", txtStudentName.Text);
                cmd.Parameters.AddWithValue("@d4", txtFathername.Text);
                cmd.Parameters.AddWithValue("@d5", txtMotherName.Text);
                cmd.Parameters.AddWithValue("@d6", txtFatherContactNo.Text);
                cmd.Parameters.AddWithValue("@d7", txtPermanentAddress.Text);
                cmd.Parameters.AddWithValue("@d8", txtTemrorayAddress.Text);
                cmd.Parameters.AddWithValue("@d9", txtContactNo.Text);
                cmd.Parameters.AddWithValue("@d10", txtEmailID.Text);
                cmd.Parameters.AddWithValue("@d11", dtpDOB.Text);
                cmd.Parameters.AddWithValue("@d12", txtGender.Text);
                cmd.Parameters.AddWithValue("@d13", dtpAdmissionDate.Text);
                cmd.Parameters.AddWithValue("@d14", txtSession.Text);
                cmd.Parameters.AddWithValue("@d15", cmbCategory.Text);
                cmd.Parameters.AddWithValue("@d16", cmbReligion.Text);
                cmd.Parameters.AddWithValue("@d17", cmbClass.Text);
                cmd.Parameters.AddWithValue("@d19", cmbStatus.Text);
                cmd.Parameters.AddWithValue("@d20", txtNationality.Text);
                cmd.Parameters.AddWithValue("@d21", CmbSection.Text);
                cmd.Parameters.AddWithValue("@d22", txtSchoolID.Text);
                MemoryStream ms       = new MemoryStream();
                Bitmap       bmpImage = new Bitmap(Picture.Image);
                bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                byte[]       data = ms.GetBuffer();
                SqlParameter p    = new SqlParameter("@d18", SqlDbType.Image);
                p.Value = data;
                cmd.Parameters.Add(p);
                cmd.ExecuteReader();
                con.Close();
                st1 = lblUser.Text;
                st2 = "added the new student '" + txtStudentName.Text + "'";
                cf.LogFunc(st1, System.DateTime.Now, st2);
                MessageBox.Show("Successfully saved", "Student Details", MessageBoxButtons.OK, MessageBoxIcon.Information);


                btnSave.Enabled = false;
            }

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