Exemple #1
0
        private void ButtonEvent_Click(object sender, EventArgs e)
        {
            AddEventform Form_ae = new AddEventform();

            this.Hide();
            Form_ae.Show();
        }
        private void AddEvent_click(object sender, EventArgs e)
        {
            ArrayList error1     = new ArrayList();
            Boolean   eventName  = true;
            Boolean   eventVenue = true;
            Boolean   time       = true;
            Boolean   status     = true;

            if (textBoxName.Text.Equals(""))
            {
                eventName = false;
                error1.Add("please Add Event Name");
            }
            if (textBoxvenue.Text.Equals(""))
            {
                eventVenue = false;
                error1.Add("please add Venue");
            }
            if (textBoxTime.Text.Equals(""))
            {
                time = false;
                error1.Add("please add time");
            }
            if (comboBoxStat.SelectedIndex == -1)
            {
                status = false;
                error1.Add("please add status");
            }

            string errorArr1 = "";

            foreach (Object ob in error1)
            {
                errorArr1 = errorArr1 + "\n" + ob;
            }

            if (eventName && eventVenue && time && status)
            {
                OpenConnection();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = ("set IDENTITY_INSERT ON");
                cmd.CommandText = ("insert into Events([Event Name], [Event Date], [Event Venue],[Time],[Status]) values ('" + textBoxName.Text + "','" + dateTimePicker1.Value.ToString() + "','" + textBoxvenue.Text + "','" + textBoxTime.Text + "','" + comboBoxStat.SelectedItem + "')");
                cmd.ExecuteNonQuery();
                CloseConnection();



                DialogResult dResult = MessageBox.Show("Add more Events", "Record Inserted Successfully", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (dResult == DialogResult.Yes)
                {
                    AddEventform Addevent = new AddEventform();
                    this.Hide();
                    Addevent.Show();
                }
            }
            else
            {
                MessageBox.Show(errorArr1);
            }
        }