Пример #1
0
        private void btn_student_Click(object sender, EventArgs e)
        {
            StudentDetails d = new StudentDetails();

            d.Show();
            this.Hide();
        }
Пример #2
0
        private void btn_submit_Click(object sender, EventArgs e)
        {
            Regex reg = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");

            if (txt_fname.Text != "" && txt_lname.Text != "" && txt_contact.Text != "" && txt_email.Text != "" && txt_registration.Text != "" && cmb_status.Text != "" && reg.IsMatch(txt_email.Text) && txt_contact.Text.All(c => char.IsDigit(c)))
            {
                SqlConnection conn     = new SqlConnection("Data Source=DESKTOP-M9PBVHQ;Initial Catalog=ProjectB;Integrated Security=True");
                int           LookupId = 5;
                if (cmb_status.Text == "Active")
                {
                    LookupId = 5;
                }
                else
                {
                    LookupId = 6;
                }
                if (update == 1)
                {
                    conn.Open();
                    string     query2         = "Update Student set FirstName = '" + txt_fname.Text + " ', LastName = '" + txt_lname.Text + "' , Contact = '" + txt_contact.Text + "', Email = '" + txt_email.Text + "' , RegistrationNumber= '" + txt_registration.Text + " ', Status = '" + LookupId + "' where Id = '" + this.id + "'";
                    SqlCommand update_command = new SqlCommand(query2, conn);
                    int        j = update_command.ExecuteNonQuery();
                    if (j != 0)
                    {
                        MessageBox.Show("Student Record Updated Successfully");
                        Student ff = new Student();
                        ff.Close();
                        StudentDetails ss = new StudentDetails();
                        ss.Show();
                        this.Hide();
                    }
                    conn.Close();
                }
                else
                {
                    conn.Open();
                    string     query   = "Insert into Student (FirstName, LastName, Contact, Email, RegistrationNumber, Status) values('" + txt_fname.Text + "', '" + txt_lname.Text + "', '" + txt_contact.Text + "', '" + txt_email.Text + "', '" + txt_registration.Text + "', '" + LookupId + "')";
                    SqlCommand command = new SqlCommand(query, conn);
                    int        i       = command.ExecuteNonQuery();
                    if (i != 0)
                    {
                        MessageBox.Show("Student Record Inserted Successfully");
                        Student f = new Student();
                        f.Close();
                        StudentDetails s = new StudentDetails();
                        this.Hide();
                        s.Show();
                    }
                    conn.Close();
                }
            }
            else
            {
                if (!txt_contact.Text.All(c => char.IsDigit(c) && txt_contact.Text != ""))
                {
                    error_msg.Text = "Contact Number Must Be Digits";
                }
                else if (!reg.IsMatch(txt_email.Text) && txt_email.Text != "")
                {
                    error_msg.Text = "Email is not in correct format";
                }
                else
                {
                    error_msg.Text = "Please Fill In All The Required Fields";
                }
                error_msg.Show();
            }
        }