Esempio n. 1
0
        /* Delete Booking */
        private void button2_Click(object sender, EventArgs e)
        {
            // Check selection
            if (bookingsView.SelectedCells.Count < 1)
            {
                MessageBox.Show("No valid selection.");
                return;
            }

            // Get selected row
            DataGridViewRow selectedRow = bookingsView.Rows[bookingsView.SelectedCells[0].RowIndex];

            // Get selected Booking ID
            string bid = selectedRow.Cells["BID"].Value.ToString();

            // Ask user if data should be deleted
            DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete booking {0} ?", bid), "Delete?", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.No)
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            // Delete data
            var adapter = new Database_adapter();

            var blidList = adapter.get_List(string.Format("select blid from booking_lines where bid = {0};", bid));

            foreach (string blid in blidList)
            {
                adapter.set(string.Format("delete from booking_entries where blid = {0};", blid));

                // Check out
                var checkedObjects = adapter.get_List(string.Format("select name from rent_objects where currentUser = {0};", blid));
                foreach (string name in checkedObjects)
                {
                    adapter.set(string.Format("update rent_objects set currentUser = 0 where name = '{0}';", name));
                }
            }

            adapter.set(string.Format("delete from booking_lines where bid = {0};", bid));
            adapter.set(string.Format("delete from bookings where bid = {0};", bid));
            adapter.set(string.Format("delete from transfers where bid = {0};", bid));
            adapter.set(string.Format("delete from alerts where bid = {0};", bid));

            adapter.close();

            Cursor.Current = Cursors.Default;

            // Update table
            fill_Table();
        }
Esempio n. 2
0
        /* Remove button clicked */
        private void removeButton_Click(object sender, EventArgs e)
        {
            string blid = get_SelectedBlid();

            if (blid == null)
            {
                return;
            }

            var adapter = new Database_adapter();

            // Check out
            var checkedObjects = adapter.get_List(string.Format("select name from rent_objects where currentUser = {0};", blid));

            foreach (string name in checkedObjects)
            {
                adapter.set(string.Format("update rent_objects set currentUser = 0 where name = '{0}';", name));
            }

            adapter.set("delete from booking_entries where blid = " + blid + ";");
            adapter.set("delete from booking_lines where blid = " + blid + ";");

            adapter.close();

            fill_BookingLineTable();
            fill_Overview();
        }
Esempio n. 3
0
        private bool cancel()
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to cancel this booking?", "Cancel?", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.No)
            {
                return(false);
            }

            var adapter = new Database_adapter();

            var blidList = adapter.get_List(string.Format("select blid from booking_lines where bid = {0};", bid));

            foreach (string blid in blidList)
            {
                adapter.set(string.Format("delete from booking_entries where blid = {0};", blid));
            }

            adapter.set(string.Format("delete from booking_lines where bid = {0};", bid));
            adapter.set(string.Format("delete from bookings where bid = {0};", bid));
            adapter.set(string.Format("delete from alerts where bid = {0};", bid));

            adapter.close();

            return(true);
        }
Esempio n. 4
0
        private void ObjectDeleter_Shown(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            var adapter = new Database_adapter();

            var roID  = adapter.get_Value(string.Format("select roID from rent_objects where name = '{0}';", name));
            var count = Int32.Parse(adapter.get_Value(string.Format("select count(name) name from rent_objects where roID = {0}", roID)));

            var dates = adapter.get_List(string.Format(@"
                select date 
                from booking_entries
                where roID = {0}
                and date >= '{1}'
                group by date
                order by date DESC; 
            ", roID, DateTime.Now.ToString("yyyy-MM-dd")));

            deleteBar.Maximum = dates.Count;
            deleteBar.Step    = 1;
            deleteBar.Value   = 0;

            var booked = "Could not delete object. Fully booked at:\r\n";

            var delete = true;

            foreach (var date in dates)
            {
                var bookedAtDate = adapter.get_Value(string.Format("select count(beID) from booking_entries where date = '{0}' and roID = {1};", DateTime.Parse(date).ToString("yyyy-MM-dd"), roID));

                if (count - Int32.Parse(bookedAtDate) <= 0)
                {
                    delete  = false;
                    booked += DateTime.Parse(date).ToString("dd.MM.yy, ");
                }

                deleteBar.Value += 1;
            }

            Cursor.Current = Cursors.Default;

            if (delete)
            {
                DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete {0}", name), "Delete?", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    adapter.set(string.Format("delete from rent_objects where name = '{0}';", name));
                }
            }
            else
            {
                MessageBox.Show(booked);
            }

            adapter.close();
            this.Close();
        }
Esempio n. 5
0
        private bool cancel()
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to cancel this booking?", "Cancel?", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.No)
            {
                return(false);
            }

            Cursor.Current = Cursors.WaitCursor;

            var adapter = new Database_adapter();

            var blidList = adapter.get_List(string.Format("select blid from booking_lines where bid = {0};", bid));

            foreach (string blid in blidList)
            {
                adapter.set(string.Format("delete from booking_entries where blid = {0};", blid));

                // Check out
                var checkedObjects = adapter.get_List(string.Format("select name from rent_objects where currentUser = {0};", blid));
                foreach (string name in checkedObjects)
                {
                    adapter.set(string.Format("update rent_objects set currentUser = 0 where name = '{0}';", name));
                }
            }

            adapter.set(string.Format("delete from booking_lines where bid = {0};", bid));
            adapter.set(string.Format("delete from bookings where bid = {0};", bid));
            adapter.set(string.Format("delete from transfers where bid = {0};", bid));
            adapter.set(string.Format("delete from alerts where bid = {0};", bid));

            adapter.close();

            Cursor.Current = Cursors.Default;

            return(true);
        }