Ejemplo n.º 1
0
        private void addNotice_Click(object sender, EventArgs e)
        {
            addNotice Addnotice = new addNotice();

            this.Hide();
            Addnotice.Show();
        }
        private void AddNotice_Click(object sender, EventArgs e)
        {
            ArrayList error2    = new ArrayList();
            Boolean   NoticeCat = true;
            Boolean   Details   = true;

            if (Category.Equals(""))
            {
                NoticeCat = false;
                error2.Add("please Add Notice Category");
            }
            if (richTextBox1.Text.Equals(""))
            {
                Details = false;
                error2.Add("please add Details");
            }

            string errorArr2 = "";

            foreach (Object ob in error2)
            {
                errorArr2 = errorArr2 + "\n" + ob;
            }

            if (NoticeCat && Details)
            {
                OpenConnection();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = ("set IDENTITY_INSERT ON");
                cmd.CommandText = ("insert into Notices( [Published Date] ,[Expiration Date], [Category],[Details]) values('" + dateTimePicker1.Value.ToString() + "','" + dateTimePicker2.Value.ToString() + "','" + Category + "','" + richTextBox1.Text + "')");
                cmd.ExecuteNonQuery();
                CloseConnection();
                ResetRecords();
                DialogResult dResult = MessageBox.Show("Add more Notices", "Record Inserted Successfully", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

                if (dResult == DialogResult.Yes)
                {
                    addNotice Addnotice = new addNotice();
                    this.Hide();
                    Addnotice.Show();
                }
            }
            else
            {
                MessageBox.Show(errorArr2);
            }
        }