private void Cancel_Click(object sender, EventArgs e)
        {
            this.Hide();
            Evaluation datap = new Evaluation();

            datap.ShowDialog();
            this.Close();// close the form
        }
        // when click on save button
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(conURL);

            // connection opens
            con.Open();

            int ID = buffer;

            if (ID < 0) // insertion
            {
                try
                {
                    // here check whether boxes are empty for not
                    if (String.IsNullOrEmpty(textBoxName.Text) || String.IsNullOrEmpty(textBoxMarks.Text) || String.IsNullOrEmpty(textBoxWeghtage.Text))
                    {
                        MessageBox.Show("Fill all boxes must");
                    }
                    else
                    {
                        // if all validation are true then insert data
                        if (isalphaTest(textBoxName.Text) && Convert.ToInt32(textBoxWeghtage.Text) >= 0 && Convert.ToInt32(textBoxMarks.Text) >= 0)
                        {
                            // command store in string then execute it by passing into sqlcommand object

                            string cmdText = "INSERT INTO Evaluation (Name, TotalMarks, TotalWeightage) VALUES (@Name, @TotalMarks, @TotalWeightage)";

                            SqlCommand c = new SqlCommand(cmdText, con);

                            c.Parameters.Add(new SqlParameter("@Name", textBoxName.Text));
                            c.Parameters.Add(new SqlParameter("@TotalMarks", textBoxMarks.Text));
                            c.Parameters.Add(new SqlParameter("@TotalWeightage", textBoxWeghtage.Text));
                            //execute it
                            int result = c.ExecuteNonQuery();
                            if (result < 0)
                            {
                                MessageBox.Show("Error");
                            }


                            // show dialog box if added in table of database
                            MessageBox.Show("Successfully Added");
                            // connection closed
                            con.Close();
                            this.Hide();
                            Evaluation datap = new Evaluation();
                            datap.ShowDialog();
                            this.Close(); // close the form
                        }
                        else
                        {
                            throw new ArgumentNullException();
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Enter Name,Total marks, total weightage in correct Format!! marks and weightage can't be negative. No extra spaces in names");
                }
            }

            else // updation
            {
                try
                {
                    if (isalphaTest(textBoxName.Text) && Convert.ToInt32(textBoxWeghtage.Text) >= 0 && Convert.ToInt32(textBoxMarks.Text) >= 0)
                    {
                        string     cmdText2 = "Update Evaluation SET Name = @Name, TotalMarks = @TotalMarks, TotalWeightage = @TotalWeightage WHERE Id = @Id";
                        SqlCommand c2       = new SqlCommand(cmdText2, con);
                        c2.Parameters.Add(new SqlParameter("@Id", ID));
                        c2.Parameters.Add(new SqlParameter("@Name", textBoxName.Text));
                        c2.Parameters.Add(new SqlParameter("@TotalMarks", textBoxMarks.Text));
                        c2.Parameters.Add(new SqlParameter("@TotalWeightage", textBoxWeghtage.Text));
                        c2.ExecuteNonQuery();
                        MessageBox.Show("Successfully Updated");
                        con.Close();
                        this.Hide();
                        Evaluation datap = new Evaluation();
                        datap.ShowDialog();
                        this.Close(); // close the form
                    }
                    else
                    {
                        throw new ArgumentNullException();
                    }
                }

                catch (Exception)
                {
                    MessageBox.Show("Enter Name,Total marks, total weightage in correct Format!! marks and weightage can't be negative. No extra spaces in names");
                }
            }
        }
Beispiel #3
0
        // goes to manage evaluations form
        private void MevalButton_Click(object sender, EventArgs e)
        {
            Evaluation st = new Evaluation();

            st.ShowDialog();
        }