Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            AddStudent f2 = new AddStudent();

            f2.ShowDialog();
            this.Close();
        }
Пример #2
0
        private void addStudt_Click(object sender, EventArgs e)
        {
            this.Hide();
            AddStudent f4 = new AddStudent();

            f4.ShowDialog();
            this.Close();
        }
Пример #3
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            con1.Open();

            int UP_Row      = int.Parse(e.RowIndex.ToString());
            int UP_RowIndex = int.Parse(e.ColumnIndex.ToString());

            ID1 = Convert.ToInt32(dataGridView1.Rows[UP_Row].Cells[0].Value.ToString());
            int dd = (int)dataGridView1.CurrentRow.Cells[0].Value;

            if (UP_RowIndex == 9)
            {
                if (UP_RowIndex == 1)
                {
                    if (UP_RowIndex == 0)
                    {
                        MessageBox.Show("Click Again");
                    }
                }
                if (UP_RowIndex != 0)
                {
                    var askfirst1 = MessageBox.Show("Are you sure you want to Update this?", "Update", MessageBoxButtons.YesNo);
                    if (askfirst1 == DialogResult.Yes)
                    {
                        AddStudent s = new AddStudent(dd);
                        ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
                        s.textBox1.Text        = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                        s.textBox2.Text        = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                        s.textBox3.Text        = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                        s.textBox4.Text        = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
                        s.textBox5.Text        = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
                        s.dateTimePicker1.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
                        if (dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString() == "")
                        {
                            s.comboBox1.Text = "";
                        }

                        else if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[8].Value) == 1)
                        {
                            s.comboBox1.Text = "Male";
                        }
                        else if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[8].Value) == 2)
                        {
                            s.comboBox1.Text = "Female";
                        }
                        s.ShowDialog();
                        con1.Close();
                    }
                    else
                    {
                        con1.Close();
                        this.Hide();
                        Student f2 = new Student();
                        f2.ShowDialog();
                        DisplayStudent();
                    }
                }
            }
            else if (UP_RowIndex == 8)
            {
                int URow      = int.Parse(e.RowIndex.ToString());
                int URowIndex = int.Parse(e.ColumnIndex.ToString());
                ID = Convert.ToInt32(dataGridView1.Rows[URow].Cells[0].Value.ToString());

                if (URowIndex == 0)
                {
                    MessageBox.Show("lala");
                }
                if (URowIndex != 0)
                {
                    var askfirst = MessageBox.Show("Are you sure you want to delete this?", "Delete", MessageBoxButtons.YesNo);
                    if (askfirst == DialogResult.Yes)
                    {
                        cmd1 = new SqlCommand("DELETE FROM Person where ID = @Id", con1);
                        cmd2 = new SqlCommand("DELETE FROM Student where ID = @Id", con1);
                        cmd2.Parameters.AddWithValue("@Id", ID);
                        cmd1.Parameters.AddWithValue("@Id", ID);
                        cmd2.ExecuteNonQuery();
                        cmd1.ExecuteNonQuery();

                        con1.Close();
                        MessageBox.Show("Deleted Succesfully");

                        this.Hide();
                        Student f2 = new Student();
                        f2.ShowDialog();
                        this.Close();
                    }
                    else
                    {
                        con1.Close();
                        this.Hide();
                        Student f2 = new Student();
                        f2.ShowDialog();
                        DisplayStudent();
                    }
                }
            }
            else
            {
                con1.Close();
            }
        }
Пример #4
0
        private void Save_Click(object sender, EventArgs e)
        {
            string pa = @"^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$";

            if (textBox1.Text != "" && textBox2.Text != "" && textBox5.Text != "")
            {
                if (Regex.IsMatch(textBox5.Text, pa) && Regex.IsMatch(textBox2.Text, @"^[a-zA-Z]+$") && Regex.IsMatch(textBox1.Text, @"^\d{4}(-[a-zA-Z][a-zA-Z])(-\d{2,3})"))
                {
                    if ((Regex.IsMatch(textBox3.Text, @"^[a-zA-Z\s]+$") && Regex.IsMatch(textBox4.Text, @"^9[0-9]{9}")) || (textBox3.Text == "" && Regex.IsMatch(textBox4.Text, @"^9[0-9]{9}")) || (!Regex.IsMatch(textBox3.Text, @"^[a-zA-Z0-9_\-]+$") && Regex.IsMatch(textBox4.Text, @"^9[0-9]{9}")) || (Regex.IsMatch(textBox3.Text, @"^[a-zA-Z\s]+$") && textBox4.Text == "") || (textBox3.Text == "" && textBox4.Text == ""))
                    {
                        if (comboBox1.Text != "")
                        {
                            if (Flag == 0)
                            {
                                bool reg = Reg_exists(textBox1.Text);
                                if (reg == false)
                                {
                                    bool email = Email_exists(textBox5.Text);
                                    if (email == false)
                                    {
                                        con1.Open();
                                        cmd2 = new SqlCommand("insert into Student(Student.Id, Student.RegistrationNo) values ((SELECT MAX(Person.Id) From Person), '" + textBox1.Text + "')", con1);
                                        string     gId  = string.Format("SELECT Lookup.Id From Lookup WHERE Value = '{0}'", comboBox1.Text);
                                        SqlCommand cmd3 = new SqlCommand(gId, con1);
                                        int        g    = (Int32)cmd3.ExecuteScalar();
                                        cmd1 = new SqlCommand("insert into [Person] (FirstName, LastName, Contact, Email, DateOfBirth, gender) values ('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + dateTimePicker1.Value + "','" + g + "')", con1);
                                        cmd1.ExecuteNonQuery();
                                        cmd2.ExecuteNonQuery();
                                        cmd3.ExecuteNonQuery();
                                        con1.Close();
                                        MessageBox.Show("Inserted Successfully");

                                        textBox2.Clear();
                                        textBox3.Clear();
                                        textBox4.Clear();
                                        textBox1.Clear();
                                        textBox5.Clear();
                                        this.Hide();
                                        AddStudent f4 = new AddStudent();
                                        f4.ShowDialog();
                                        this.Close();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Email Exists");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Registration no Exists");
                                }
                            }
                            if (Flag > 0)
                            {
                                bool Upemail = UpdateEmail_exists(textBox5.Text);
                                bool Upreg   = UpdateReg_exists(textBox1.Text);
                                bool email   = Email_exists(textBox5.Text);
                                bool reg     = Reg_exists(textBox1.Text);
                                if (Upreg == false)
                                {
                                    if (Upemail == false)
                                    {
                                        con1.Open();
                                        Student f = new Student();
                                        cmd1 = new SqlCommand("UPDATE Person set FirstName = @FirstName, LastName = @LastName ,Contact = @Contact, Email = @Email, DateOfBirth =@DateOfBirth, Gender = @Gender WHERE ID = @dd", con1);
                                        cmd1.Parameters.AddWithValue("@dd", Flag);
                                        cmd1.Parameters.AddWithValue("@FirstName", textBox2.Text);
                                        cmd1.Parameters.AddWithValue("@LastName", textBox3.Text);
                                        cmd1.Parameters.AddWithValue("@Contact", textBox4.Text);
                                        cmd1.Parameters.AddWithValue("@Email", textBox5.Text);
                                        cmd1.Parameters.AddWithValue("@DateOfBirth", dateTimePicker1.Value);
                                        string     gId  = string.Format("SELECT Lookup.Id From Lookup WHERE Value = '{0}'", comboBox1.Text);
                                        SqlCommand cmd3 = new SqlCommand(gId, con1);
                                        int        g    = (Int32)cmd3.ExecuteScalar();
                                        cmd1.Parameters.AddWithValue("@Gender", g);
                                        cmd2 = new SqlCommand("UPDATE Student set RegistrationNo = @RegistrationNo WHERE ID = @Id", con1);
                                        cmd2.Parameters.AddWithValue("RegistrationNo", textBox1.Text);
                                        cmd2.Parameters.AddWithValue("@Id", Flag);
                                        cmd1.ExecuteNonQuery();
                                        cmd2.ExecuteNonQuery();
                                        con1.Close();
                                        MessageBox.Show("Updated successfully");
                                        textBox2.Clear();
                                        textBox3.Clear();
                                        textBox4.Clear();
                                        textBox1.Clear();
                                        textBox5.Clear();
                                        this.Hide();
                                        AddStudent f4 = new AddStudent();
                                        f4.ShowDialog();
                                        this.Close();
                                        Flag = 0;
                                    }
                                    else
                                    {
                                        MessageBox.Show("Email Exits");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Registration No Exits");
                                }
                            }
                        }
                        else
                        {
                            if (Flag == 0)
                            {
                                bool email = Email_exists(textBox5.Text);
                                bool reg   = Reg_exists(textBox1.Text);
                                if (reg == false)
                                {
                                    if (email == false)
                                    {
                                        con1.Open();
                                        cmd2 = new SqlCommand("insert into Student(Student.Id, Student.RegistrationNo) values ((SELECT MAX(Person.Id) From Person), '" + textBox1.Text + "')", con1);
                                        cmd1 = new SqlCommand("insert into Person(FirstName, LastName, Contact, Email, DateOfBirth) values ('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + dateTimePicker1.Value + "')", con1);
                                        cmd1.ExecuteNonQuery();
                                        cmd2.ExecuteNonQuery();
                                        con1.Close();
                                        MessageBox.Show("Inserted Successfully");
                                        textBox2.Clear();
                                        textBox3.Clear();
                                        textBox4.Clear();
                                        textBox1.Clear();
                                        textBox5.Clear();
                                        this.Hide();
                                        AddStudent f4 = new AddStudent();
                                        f4.ShowDialog();
                                        this.Close();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Email Exists");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Reg No Exists");
                                }
                            }
                            if (Flag > 0)
                            {
                                bool Upemail = UpdateEmail_exists(textBox5.Text);
                                bool Upreg   = UpdateReg_exists(textBox1.Text);
                                bool email   = Email_exists(textBox5.Text);
                                bool reg     = Reg_exists(textBox1.Text);
                                if (Upreg == false)
                                {
                                    if (Upemail == false)
                                    {
                                        con1.Open();
                                        Student f = new Student();
                                        cmd1 = new SqlCommand("UPDATE Person set FirstName = @FirstName, LastName = @LastName ,Contact = @Contact, Email = @Email, DateOfBirth =@DateOfBirth WHERE ID = @dd", con1);
                                        cmd1.Parameters.AddWithValue("@dd", Flag);
                                        cmd1.Parameters.AddWithValue("@FirstName", textBox2.Text);
                                        cmd1.Parameters.AddWithValue("@LastName", textBox3.Text);
                                        cmd1.Parameters.AddWithValue("@Contact", textBox4.Text);
                                        cmd1.Parameters.AddWithValue("@Email", textBox5.Text);
                                        cmd1.Parameters.AddWithValue("@DateOfBirth", dateTimePicker1.Value);
                                        string gId = string.Format("SELECT Lookup.Id From Lookup WHERE Value = '{0}'", comboBox1.Text);
                                        cmd2 = new SqlCommand("UPDATE Student set RegistrationNo = @RegistrationNo WHERE ID = @Id", con1);
                                        cmd2.Parameters.AddWithValue("RegistrationNo", textBox1.Text);
                                        cmd2.Parameters.AddWithValue("@Id", Flag);
                                        cmd1.ExecuteNonQuery();
                                        cmd2.ExecuteNonQuery();
                                        con1.Close();
                                        MessageBox.Show("Updated successfully");
                                        textBox2.Clear();
                                        textBox3.Clear();
                                        textBox4.Clear();
                                        textBox1.Clear();
                                        textBox5.Clear();
                                        this.Hide();
                                        AddStudent f4 = new AddStudent();
                                        f4.ShowDialog();
                                        this.Close();
                                        Flag = 0;
                                    }
                                    else
                                    {
                                        MessageBox.Show("Reg no Exists");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Email Exists");
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please enter valid Last Name and Phone No or dont enter anything");
                    }
                }
                else
                {
                    MessageBox.Show("Please check Email(Full Email Id), Registration No(2016-CE/CSE-057) and first name");
                }
            }
            else
            {
                MessageBox.Show("Please Enter Entries");
            }
            con1.Close();
        }