Exemplo n.º 1
0
        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Hide();
            Advisor ps = new Advisor();

            ps.ShowDialog();
            this.Close();
        }
Exemplo n.º 2
0
        // when save button clicks
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(conURL);

            // connection opens
            con.Open();



            if (buffer < 0) // for creation of new data
            {
                try
                {
                    // here check whether boxes are empty for not
                    if (String.IsNullOrEmpty(textBoxName.Text) || String.IsNullOrEmpty(textBoxEmail.Text) || String.IsNullOrEmpty(comboBox1.Text))
                    {
                        MessageBox.Show("Fill First Name, Email, Designation must");
                    }
                    else
                    {
                        if (isalphaTest(textBoxName.Text) && (String.IsNullOrEmpty(textBoxLast.Text) || (!String.IsNullOrEmpty(textBoxLast.Text) && (isalphaTest(textBoxLast.Text)))) && Convert.ToDouble(textBoxSalary.Text) >= 0 && (String.IsNullOrEmpty(textBoxContact.Text) || (!String.IsNullOrEmpty(textBoxContact.Text) && contactNoValid(textBoxContact.Text))))
                        {
                            // getting value of radio button
                            string val     = "";
                            bool   isCheck = male.Checked;
                            if (isCheck)
                            {
                                val = male.Text;
                            }
                            bool isCheck2 = female.Checked;
                            if (isCheck2)
                            {
                                val = female.Text;
                            }
                            System.Text.RegularExpressions.Regex expr = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
                            if (expr.IsMatch(textBoxEmail.Text))
                            {
                                string cmdText = "INSERT INTO Person (FirstName,LastName, Contact, Email, DateOfBirth, Gender ) VALUES (@FirstName,@LastName, @Contact, @Email, @DateOfBirth, (SELECT Id FROM Lookup WHERE Category = 'Gender' AND Value = @Value))";

                                SqlCommand c = new SqlCommand(cmdText, con);

                                c.Parameters.Add(new SqlParameter("@FirstName", textBoxName.Text));
                                c.Parameters.Add(new SqlParameter("@LastName", textBoxLast.Text));
                                c.Parameters.Add(new SqlParameter("@Contact", textBoxContact.Text));

                                c.Parameters.Add(new SqlParameter("@Email", textBoxEmail.Text));



                                c.Parameters.Add(new SqlParameter("@DateOfBirth", dateTimePicker1.Text));

                                c.Parameters.Add(new SqlParameter("@Value", val));
                                //execute it
                                int result = c.ExecuteNonQuery();
                                if (result < 0)
                                {
                                    MessageBox.Show("Error");
                                }



                                string     cmdText3 = "INSERT INTO Advisor (Id, Designation, Salary) VALUES((SELECT Id FROM Person WHERE Email = @Email AND Contact = @Contact AND FirstName = @FirstName), (SELECT Id FROM Lookup WHERE Category = 'DESIGNATION' AND Value = @Value), @Salary)";
                                SqlCommand c3       = new SqlCommand(cmdText3, con);
                                c3.Parameters.Add(new SqlParameter("@FirstName", textBoxName.Text));

                                c3.Parameters.Add(new SqlParameter("@Contact", textBoxContact.Text));
                                c3.Parameters.Add(new SqlParameter("@Email", textBoxEmail.Text));
                                c3.Parameters.Add(new SqlParameter("@Value", comboBox1.Text));
                                c3.Parameters.Add(new SqlParameter("@Salary", textBoxSalary.Text));
                                c3.ExecuteNonQuery();

                                // connection closed
                                // show dialog box if added

                                MessageBox.Show("Successfully Added");
                                con.Close();
                                this.Hide();
                                Advisor datap = new Advisor();
                                datap.ShowDialog();
                                this.Close(); // close the form
                            }
                            else
                            {
                                throw new ArgumentNullException();
                            }
                        }
                        else
                        {
                            throw new ArgumentNullException();
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Enter Name, Email, Salary in correct Format!!  Name should be all alphabets, no extra spaces. email should have at least 4 chars before @ . contact should have digits");
                }
            }

            else  // for updation of data
            {
                try
                {
                    if (isalphaTest(textBoxName.Text) && (String.IsNullOrEmpty(textBoxLast.Text) || (!String.IsNullOrEmpty(textBoxLast.Text) && (isalphaTest(textBoxLast.Text)))) && Convert.ToDouble(textBoxSalary.Text) >= 0 && (String.IsNullOrEmpty(textBoxContact.Text) || (!String.IsNullOrEmpty(textBoxContact.Text) && contactNoValid(textBoxContact.Text))))
                    {
                        string val     = "";
                        bool   isCheck = male.Checked;
                        if (isCheck)
                        {
                            val = male.Text;
                        }
                        bool isCheck2 = female.Checked;
                        if (isCheck2)
                        {
                            val = female.Text;
                        }
                        System.Text.RegularExpressions.Regex expr = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
                        if (expr.IsMatch(textBoxEmail.Text))
                        {
                            string     cmdText2 = "Update Person SET FirstName = @FirstName ,LastName =@LastName , Contact = @Contact, Email = @Email, DateOfBirth = @DateOfBirth, Gender = (SELECT Id FROM Lookup WHERE Category = 'Gender' AND Value = @Value) WHERE Id = @Id";
                            SqlCommand c2       = new SqlCommand(cmdText2, con);
                            c2.Parameters.Add(new SqlParameter("@Id", buffer));
                            c2.Parameters.Add(new SqlParameter("@FirstName", textBoxName.Text));
                            c2.Parameters.Add(new SqlParameter("@LastName", textBoxLast.Text));
                            c2.Parameters.Add(new SqlParameter("@Contact", textBoxContact.Text));

                            c2.Parameters.Add(new SqlParameter("@Email", textBoxEmail.Text));



                            c2.Parameters.Add(new SqlParameter("@DateOfBirth", dateTimePicker1.Text));

                            c2.Parameters.Add(new SqlParameter("@Value", val));

                            c2.ExecuteNonQuery();

                            string     cmdText3 = "Update Advisor SET Designation = (SELECT Id FROM Lookup WHERE Category = 'DESIGNATION' AND Value = @Value), Salary = @Salary where Id = @Id";
                            SqlCommand c3       = new SqlCommand(cmdText3, con);
                            c3.Parameters.Add(new SqlParameter("@Id", buffer));
                            c3.Parameters.Add(new SqlParameter("@Value", comboBox1.Text));
                            c3.Parameters.Add(new SqlParameter("@Salary", textBoxSalary.Text));
                            c3.ExecuteNonQuery();
                            MessageBox.Show("Successfully Updated!!");

                            con.Close();
                            this.Hide();
                            Advisor datap = new Advisor();
                            datap.ShowDialog();
                            this.Close(); // close the form
                        }
                        else
                        {
                            throw new ArgumentNullException();
                        }
                    }
                    else
                    {
                        throw new ArgumentNullException();
                    }
                }

                catch (Exception)
                {
                    MessageBox.Show("Enter Name, Email, Salary in correct Format!!  Name should be all alphabets, no extra spaces and Enter Name, Email, Designation must. email should have at least 4 chars before @. contact should have digits!!");
                }
            }
        }
Exemplo n.º 3
0
        // goes to manage advisors
        private void Madvisors_Click(object sender, EventArgs e)
        {
            Advisor st = new Advisor();

            st.ShowDialog();
        }