Esempio n. 1
0
        private void btn_teach_reg_Click(object sender, EventArgs e)
        {
            this.Hide();
            Registered_teachers teacher = new Registered_teachers();

            teacher.Show();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Registered_teachers obj = new Registered_teachers();

            obj.Show();
        }
        public void save()
        {
            if ((text_tchname.Text == "") || (text_tchlastname.Text == "") || (text_tchfathername.Text == "") ||
                (text_tchCNIC.Text == "") || (text_tchemail.Text == "") || (text_tchmobile.Text == "") ||

                (combo_course.Text == "") || (tchdob.Text == "") || (text_tchaddress.Text == "") || (combo_tchprovince.Text == "") || (combo_tchcity.Text == "") || (combo_tchcountry.Text == "")

                || (tchpictureBox.Image == null) ||
                (rdn_tchmale.Checked == false) && (rdn_tchfemale.Checked == false))
            {
                MessageBox.Show("One or more Fields are Empty..!");
            }

            else
            {
                con.openconn();
                if (flag == 0)
                {
                    if (rdn_tchmale.Checked)
                    {
                        gender = "Male";
                    }
                    else
                    {
                        gender = "Female";
                    }
                    SqlCommand   cmd    = new SqlCommand("INSERT INTO Teacher(fname,lname,fathername,cnic,email,mobile,crsid,dateofbirth,address,gender,con_id,c_id,pro_id,pic) VALUES ('" + text_tchname.Text + "','" + text_tchlastname.Text + "','" + text_tchfathername.Text + "','" + text_tchCNIC.Text + "','" + text_tchemail.Text + "','" + text_tchmobile.Text + "','" + Convert.ToInt32(combo_course.SelectedValue.ToString()) + "','" + Convert.ToDateTime(tchdob.Text) + "','" + text_tchaddress.Text + "','" + gender + "','" + Convert.ToInt32(combo_tchcountry.SelectedValue.ToString()) + "','" + Convert.ToInt32(combo_tchcity.SelectedValue.ToString()) + "','" + Convert.ToInt32(combo_tchprovince.SelectedValue.ToString()) + "',@pic)", con.openconn());
                    MemoryStream stream = new MemoryStream();
                    tchpictureBox.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

                    byte[] pic = stream.ToArray();
                    cmd.Parameters.AddWithValue("@pic", pic);
                    j = cmd.ExecuteNonQuery();
                    if (j > 0)
                    {
                        MessageBox.Show("Record Save Successfully!");
                    }
                }
                else
                {
                    SqlCommand cmd = new SqlCommand("update Teacher set fname='" + text_tchname.Text + "', lname='" + text_tchlastname.Text + "',fathername='" + text_tchfathername.Text + "',cnic='" + text_tchCNIC.Text + "',email='" + text_tchemail.Text + "', mobile='" + text_tchmobile.Text + "', pic='" + tchpictureBox.Image + "',crsid='" + combo_course.SelectedValue.ToString() + "',dateofbirth='" + Convert.ToDateTime(tchdob.Text) + "',address='" + text_tchaddress.Text + "',gender='" + gender + "',con_id='" + Convert.ToInt32(combo_tchcountry.SelectedValue) + "',pro_id='" + Convert.ToInt32(combo_tchprovince.SelectedValue) + "',c_id='" + Convert.ToInt32(combo_tchcity.SelectedValue) + "' Where teacherid = '" + id + "'", con.openconn());
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Record Update Successfully!");
                    Registered_teachers r = new Registered_teachers();
                    r.Show();
                    this.Dispose();
                }
                con.connclose();
            }
        }