Пример #1
0
        private void saveEditBtn_Click(object sender, EventArgs e)
        {
            //description is not empty
            if (descriptionTxt.Text.Length == 0)
            {
                MessageBox.Show("Description is empty! Please enter a description...", "Warning");
                return;
            }

            //capacity is not empty
            if (capTxt.Text.Length == 0)
            {
                MessageBox.Show("Capacity is empty! Please enter a capacity...", "Warning");
                return;
            }

            if (locCB.SelectedIndex < 0 || depCB.SelectedIndex < 0)
            {
                MessageBox.Show("Please do not leave empty fields..", "Warning");
                return;
            }

            try
            {
                int x = int.Parse(capTxt.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please enter number in capacity...", "Warning");
            }


            //insert event
            OracleCommand insEvent = new OracleCommand();

            insEvent.Connection  = OracleHelper.getConnection();
            insEvent.CommandText = "Update_Event";
            insEvent.CommandType = CommandType.StoredProcedure;
            insEvent.Parameters.Add("t", titleTxt.Text);
            insEvent.Parameters.Add("cap", capTxt.Text);
            insEvent.Parameters.Add("des", descriptionTxt.Text);
            insEvent.Parameters.Add("ln", locCB.SelectedItem.ToString());
            if (timeCB.SelectedIndex >= 0)
            {
                int tIndx = timeCB.SelectedIndex;
                insEvent.Parameters.Add("st", startTimes[tIndx].ToString());
                insEvent.Parameters.Add("ld", dates[tIndx].ToString().ToUpper());
            }
            else
            {
                Event ev = (Event)events[eventsCLB.SelectedIndex];
                insEvent.Parameters.Add("st", ev.start_time);
                insEvent.Parameters.Add("ld", ev.date);
            }
            insEvent.Parameters.Add("did", dids[depCB.SelectedIndex]);
            insEvent.ExecuteNonQuery();

            MessageBox.Show("Event successfully updated!", "Success");
            titleTxt.Clear();
            descriptionTxt.Clear();
            capTxt.Clear();
            listPanel[0].BringToFront();
            events.Clear();
            eventsCLB.Items.Clear();

            OracleCommand getEvents = new OracleCommand();

            getEvents.Connection  = OracleHelper.getConnection();
            getEvents.CommandType = CommandType.StoredProcedure;
            getEvents.CommandText = "GetEvents";
            getEvents.Parameters.Add("ref", OracleDbType.RefCursor, ParameterDirection.Output);
            getEvents.Parameters.Add("hst", OracleHelper.LoggedIn.user_name);
            OracleDataReader eventsDR = getEvents.ExecuteReader();

            while (eventsDR.Read())
            {
                Event ev = new Event();
                ev.title       = eventsDR[0].ToString();
                ev.capacity    = int.Parse(eventsDR[2].ToString());
                ev.description = eventsDR[3].ToString();
                ev.location    = eventsDR[4].ToString();
                ev.start_time  = eventsDR[5].ToString();
                ev.date        = eventsDR[6].ToString();
                ev.department  = eventsDR[7].ToString();
                ev.end_time    = eventsDR[8].ToString();
                if (eventsDR[1].ToString().CompareTo("Rejected") == 0)
                {
                    ev.rs = RequestStatus.REJECTED;
                }
                else if (eventsDR[1].ToString().CompareTo("accepted") == 0)
                {
                    ev.rs = RequestStatus.ACCEPTED;
                }
                else if (eventsDR[1].ToString().CompareTo("pending") == 0)
                {
                    ev.rs = RequestStatus.PENDING;
                }
                eventsCLB.Items.Add(ev.title + " " + ev.rs.ToString());
                events.Add(ev);
            }
        }
Пример #2
0
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     OracleHelper.closeConnection();
 }
        private void btn_Click(object sender, EventArgs e)
        {
            //event title is not empty
            if (titleTxt.Text.Length == 0)
            {
                MessageBox.Show("Title is empty! Please enter a title...", "Warning");
                return;
            }
            //event title is unique
            OracleCommand title = new OracleCommand();

            title.Connection  = OracleHelper.getConnection();
            title.CommandText = "IsTitleUnique";
            title.CommandType = CommandType.StoredProcedure;
            title.Parameters.Add("title", titleTxt.Text);
            int ret;

            title.Parameters.Add("ret", OracleDbType.Int32, ParameterDirection.Output);
            title.ExecuteNonQuery();

            //description is not empty
            if (descriptionTxt.Text.Length == 0)
            {
                MessageBox.Show("Description is empty! Please enter a description...", "Warning");
                return;
            }

            //capacity is not empty
            if (capTxt.Text.Length == 0)
            {
                MessageBox.Show("Capacity is empty! Please enter a capacity...", "Warning");
                return;
            }

            if (locCB.SelectedIndex < 0 || timeCB.SelectedIndex < 0 || depCB.SelectedIndex < 0)
            {
                MessageBox.Show("Please do not leave empty fields..", "Warning");
                return;
            }

            try
            {
                ret = int.Parse(title.Parameters["ret"].Value.ToString());
                if (ret == 0)
                {
                    MessageBox.Show("Title is not unique!", "Warning");
                    return;
                }
                int x = int.Parse(capTxt.Text);
            }catch (Exception ex)
            {
                MessageBox.Show("Please enter number in capacity...", "Warning");
            }


            //insert event
            OracleCommand insEvent = new OracleCommand();

            insEvent.Connection  = OracleHelper.getConnection();
            insEvent.CommandText = "Insert_Event";
            insEvent.CommandType = CommandType.StoredProcedure;
            insEvent.Parameters.Add("t", titleTxt.Text);
            insEvent.Parameters.Add("cap", capTxt.Text);
            insEvent.Parameters.Add("des", descriptionTxt.Text);
            insEvent.Parameters.Add("ln", locCB.SelectedItem.ToString());
            int tIndx = timeCB.SelectedIndex;

            insEvent.Parameters.Add("st", startTimes[tIndx].ToString());
            insEvent.Parameters.Add("et", endTimes[tIndx].ToString());
            insEvent.Parameters.Add("ld", dates[tIndx].ToString().ToUpper());
            insEvent.Parameters.Add("did", dids[depCB.SelectedIndex]);
            insEvent.Parameters.Add("hst", OracleHelper.LoggedIn.user_name);
            insEvent.ExecuteNonQuery();

            //insert hosts
            if (hostCLB.CheckedItems.Count > 0)
            {
                for (int i = 0; i < hostCLB.CheckedItems.Count; i++)
                {
                    OracleCommand addHost = new OracleCommand();
                    addHost.Connection  = OracleHelper.getConnection();
                    addHost.CommandText = "Add_Host";
                    addHost.CommandType = CommandType.StoredProcedure;
                    addHost.Parameters.Add("t", titleTxt.Text);
                    addHost.Parameters.Add("hst", usernames[hostCLB.CheckedItems[i].ToString()]);
                    addHost.ExecuteNonQuery();
                }
            }

            MessageBox.Show("Event successfully created!", "Success");
            titleTxt.Clear();
            descriptionTxt.Clear();
            capTxt.Clear();
            hostCLB.ClearSelected();
        }