private void PrintB_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(CashTB.Text))
            {
                double x      = Convert.ToDouble(CashTB.Text);
                string change = (x - total).ToString();

                using (FormPrint frm = new FormPrint(receiptBindingSource.DataSource as List <Receipt>, string.Format("{0}$", total), string.Format("{0}$", CashTB.Text), string.Format("{0}$", change), DateTime.Now.ToString("MM/dd/yyyy")))
                {
                    frm.ShowDialog();
                }
            }
            else
            {
                string       Error1 = "Please enter how much the customer has paid";
                CustomDialog Error  = new CustomDialog(Error1, 1);
                Error.ShowDialog();
            }
        }
Exemple #2
0
        // Actions on personal forms
        private void TBConfirm_Click(object sender, EventArgs e)
        {
            if
            (
                !(string.IsNullOrWhiteSpace(Text1.Text) &&
                  string.IsNullOrWhiteSpace(Text2.Text) &&
                  string.IsNullOrWhiteSpace(Text3.Text) &&
                  string.IsNullOrWhiteSpace(Text4.Text))
            )
            {
                Guest guestToSave;

                if (personToEdit == true)
                {
                    guestToSave = contextDB.Guest.Where(x => x.Id == PersonId()).SingleOrDefault();
                }
                else
                {
                    guestToSave = new Guest();
                    contextDB.Guest.InsertOnSubmit(guestToSave);
                }

                guestToSave.FirstName   = Text1.Text;
                guestToSave.LastName    = Text2.Text;
                guestToSave.Nationality = Text3.Text;
                guestToSave.IdProof     = Text4.Text;
                guestToSave.DateOfBirth = TPDateOfBirth.Value;


                contextDB.SubmitChanges();

                personToEdit        = false;
                Panel_Guest.Visible = false;
                LoadGuests();
                Panel_Reservation.Enabled = true;
                LabelResOn.Text           = "EMPTY";
            }
            else
            {
                CustomDialog cd = new CustomDialog("You should fill in the gaps", 1);
                cd.ShowDialog();
            }
        }
        private void EditB_Click(object sender, EventArgs e)
        {
            string       ErrorText = "";
            CustomDialog ErrorForm = null;

            if (string.IsNullOrWhiteSpace(textBox1.Text))
            {
                textBox1.PasswordChar = '\0';
                textBox2.PasswordChar = '\0';
                textBox3.PasswordChar = '\0';
                FillTable();
            }

            if (LoggedUser.GetRole() == true)
            {
                SearchNextB.Enabled     = false;
                SearchPreviousB.Enabled = false;

                Choice = 2;
                ChangeView("EDIT");
                DataChangeEnabled();
            }
            else if (LoggedUser.GetRole() == false)
            {
                Worker CheckWhoYouAre = listOfWorkers.SelectedItem as Worker;
                if (CheckWhoYouAre.Id == LoggedUser.GetId())
                {
                    SearchNextB.Enabled     = false;
                    SearchPreviousB.Enabled = false;

                    Choice = 2;
                    ChangeView("EDIT");
                    DataChangeEnabled();
                }
                else if (CheckWhoYouAre.Id != LoggedUser.GetId())
                {
                    ErrorText = "As a user, you can change the only yourself information";
                    ErrorForm = new CustomDialog(ErrorText, 1);
                    ErrorForm.ShowDialog();
                }
            }
        }
        private void deleteButton_Click(object sender, EventArgs e)
        {
            Room toCheck = listOfRooms.SelectedItem as Room;

            if (!contextDB.RoomReserved.Any(x => x.Room_ID == toCheck.Id))
            {
                contextDB.Room.DeleteOnSubmit(toCheck);
                contextDB.SubmitChanges();

                addButton.Enabled    = false;
                selectButton.Enabled = false;
                deleteButton.Enabled = false;

                LoadForm();
            }
            else
            {
                CustomDialog cd = new CustomDialog("it is not possible to delete a room with reservations", 1);
                cd.ShowDialog();
            }
        }
        private void AddB_Click(object sender, EventArgs e)
        {
            string       ErrorText = "";
            CustomDialog ErrorForm = null;


            if (LoggedUser.GetRole() == true)
            {
                Choice = 3;
                listOfWorkers.SelectedIndex = -1;
                ClearTable();
                ChangeView("ADD");
                DataChangeEnabled();
                addButton.Enabled = false;
            }
            else if (LoggedUser.GetRole() == false)
            {
                ErrorText = "As a user, you can't add new users";
                ErrorForm = new CustomDialog(ErrorText, 1);
                ErrorForm.ShowDialog();
            }
        }
Exemple #6
0
        private void CancelButton_Click(object sender, EventArgs e)
        {
            string       error3         = "Are you sure you want to abort this operation ??";
            CustomDialog AddReservation = new CustomDialog(error3, 2);

            AddReservation.ShowDialog();
            if (AddReservation.DialogResult.Equals(DialogResult.Yes))
            {
                AddOrEdit = 1;
                var mainForm = Application.OpenForms.OfType <MainMenu>().Single();
                mainForm.RefreshData();
                this.Close();
            }
            else
            {
            }


            //var mainForm = Application.OpenForms.OfType<MainMenu>().Single();
            //mainForm.FillData();
            //
            //this.Close();
        }
Exemple #7
0
        // Saving reservations in the database
        private void ReservationConfirmButton_Click(object sender, EventArgs e)
        {
            CustomDialog cd;

            if (roomsSelectedListbox.Items.Count > 0 && LabelResOn.Text != "EMPTY")
            {
                Reservation  ResToSave  = null;
                RoomReserved RoomToSave = null;

                // New booking has been added old is edit \/
                if (task == 0)
                {
                    ResToSave = new Reservation();
                    contextDB.Reservation.InsertOnSubmit(ResToSave);
                }
                else if (task == 1)
                {
                    ResToSave = (from reservation in contextDB.Reservation where reservation.Id == reservationId select reservation).SingleOrDefault();
                }

                ResToSave.StartDate   = timePickerStart.Value;
                ResToSave.EndDate     = timePickerEnd.Value;
                ResToSave.Total_price = TakePrice();
                ResToSave.Guest       = contextDB.Guest.Single(c => c.Id == (from guest in contextDB.Guest
                                                                             where guest.Id == PersonId()
                                                                             select guest.Id).Single());
                ResToSave.Worker_ID = workerId;
                contextDB.SubmitChanges();



                // when a new reservation adds room reservations \/
                if (task == 0)
                {
                    for (int i = 0; i < roomsSelectedListbox.Items.Count; i++)
                    {
                        RoomToSave = new RoomReserved();
                        contextDB.RoomReserved.InsertOnSubmit(RoomToSave);

                        RoomToSave.PriceFromDate  = TakePrice();
                        RoomToSave.Reservation_ID = (from res in contextDB.Reservation select res.Id).Max();
                        RoomToSave.Room_ID        = (from room in contextDB.Room
                                                     where room.RoomNameUnique.ToString() == roomsSelectedListbox.Items[i].ToString()
                                                     select room.Id).First();
                        contextDB.SubmitChanges();
                    }
                }
                // New room reservations added

                // when an old booking has been edited deleted room bookings
                else if (task == 1)
                {
                    // *** find all rooms that are reserved for this id ***

                    var query2 = (from roomres in contextDB.RoomReserved where roomres.Reservation_ID == reservationId select roomres).ToList();


                    for (int i = 0; i < roomsSelectedListbox.Items.Count; i++)
                    {
                        if (!contextDB.RoomReserved.Any(x => x.Room.RoomNameUnique == roomsSelectedListbox.Items[i].ToString() && x.Reservation_ID == reservationId))
                        {
                            // if it does not exist in the database add
                            RoomToSave = new RoomReserved();
                            contextDB.RoomReserved.InsertOnSubmit(RoomToSave);

                            RoomToSave.PriceFromDate  = TakePrice();
                            RoomToSave.Reservation_ID = (from res in contextDB.Reservation select res.Id).Max();
                            RoomToSave.Room_ID        = (from room in contextDB.Room
                                                         where room.RoomNameUnique.ToString() == roomsSelectedListbox.Items[i].ToString()
                                                         select room.Id).First();
                        }
                        else if (contextDB.RoomReserved.Any(x => x.Room.RoomNameUnique == roomsSelectedListbox.Items[i].ToString() && x.Reservation_ID == reservationId))
                        {
                            // if there is an extension in the database
                        }
                        contextDB.SubmitChanges();
                    }

                    for (int i = 0; i < query2.Count; i++)
                    {
                        if (!roomsSelectedListbox.Items.Contains(query2[i].Room.RoomNameUnique) && query2[i].Reservation_ID.Equals(reservationId))
                        {
                            // delete from the database there is no such room reservation in the listbox

                            RoomToSave = query2[i];
                            contextDB.RoomReserved.DeleteOnSubmit(RoomToSave);
                            contextDB.SubmitChanges();
                        }
                    }
                }

                // load database in Mainmenu Form and close active form

                task = 0;
                var mainForm = Application.OpenForms.OfType <MainMenu>().Single();
                mainForm.RefreshData();
                this.Close();
            }
            else
            {
                cd = new CustomDialog("Select the room and guest needed to make the booking", 1);
                cd.ShowDialog();
            }
        }
        private void ConfirmButtonTLO_Click(object sender, EventArgs e)
        {
            CustomDialog cd;

            if (!string.IsNullOrWhiteSpace(textBox1.Text) && (categoryCombobox.SelectedIndex != -1))
            {
                if (pictureBox1.Image != null)
                {
                    try
                    {
                        MemoryStream ms = new MemoryStream();
                        Room         roomToSave;
                        pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                        byte[] arrImage = ms.ToArray();


                        if (contextDB.Room.Any(x => x.RoomNameUnique == textBox1.Text.ToUpper().ToString()))
                        {
                            roomToSave = listOfRooms.SelectedItem as Room;
                        }
                        else
                        {
                            roomToSave = new Room();
                            contextDB.Room.InsertOnSubmit(roomToSave);
                        }

                        RoomType helper = contextDB.RoomType.Where(x => x.RoomName == categoryCombobox.SelectedItem.ToString()).FirstOrDefault();

                        roomToSave.RoomNameUnique = textBox1.Text;
                        roomToSave.Hotel_ID       = 1;
                        roomToSave.RoomType_ID    = helper.Id;
                        roomToSave.Data           = arrImage;

                        contextDB.SubmitChanges();

                        addButton.Enabled    = false;
                        selectButton.Enabled = false;
                        deleteButton.Enabled = false;

                        textBox1.Clear();
                        categoryCombobox.SelectedIndex = -1;
                        pictureBox1.Image = null;

                        panelInformation.Enabled = false;
                        LoadForm();
                        listOfRooms.Enabled = true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    cd = new CustomDialog("try to load image", 1);
                    cd.ShowDialog();
                }
            }
            else
            {
                cd = new CustomDialog("fill in the data", 1);
                cd.ShowDialog();
            }
        }
Exemple #9
0
        private void ReservationConfirmButton_Click(object sender, EventArgs e)
        {
            if (RoomSelectedLB.Items.Count > 0)
            {
                bool AllRoomsGotGuest = true;
                for (int i = 0; i < AddedRooms.Count; i++)
                {
                    if (AddedRooms[i].guests.Count < 1)
                    {
                        AllRoomsGotGuest = false;
                        break;
                    }
                }

                if (AllRoomsGotGuest == true && LabelResOn.Text != "EMPTY")
                {
                    Reservation  ResToSave  = null;
                    RoomReserved RoomToSave = null;

                    if (AddOrEdit == 1) // when adding new reservation
                    {
                        ResToSave = new Reservation();

                        contextDB.Reservation.InsertOnSubmit(ResToSave);
                    }
                    else if (AddOrEdit == 2) // when edit old reservation
                    {
                        ResToSave = (from reservation in contextDB.Reservation where reservation.Id == ReseravtionID select reservation).SingleOrDefault();
                    }

                    ResToSave.StartDate   = TimePickerStart.Value;
                    ResToSave.EndDate     = TimePickerEnd.Value;
                    ResToSave.Total_price = TakePrice();
                    ResToSave.Guest       = contextDB.Guest.Single(c => c.Id == (from guest in contextDB.Guest
                                                                                 where guest.LastName == ReservationOn[0]
                                                                                 select guest.Id).Single());
                    ResToSave.Worker_ID = WorkerId;
                    contextDB.SubmitChanges();

                    // save reservation

                    if (AddOrEdit == 1) // when new reservation add new roomres
                    {
                        for (int i = 0; i < RoomSelectedLB.Items.Count; i++)
                        {
                            RoomToSave = new RoomReserved();
                            contextDB.RoomReserved.InsertOnSubmit(RoomToSave);

                            RoomToSave.PriceFromDate  = TakePrice();
                            RoomToSave.Reservation_ID = (from res in contextDB.Reservation select res.Id).Max();
                            RoomToSave.Room_ID        = (from room in contextDB.Room
                                                         where room.RoomNameUnique.ToString() == RoomSelectedLB.Items[i].ToString()
                                                         select room.Id).First();
                            contextDB.SubmitChanges();
                        }
                    }                        // end adding new roomreservation
                    else if (AddOrEdit == 2) // when old reservation edit/delete/add new roomres
                    {
                        //ad.1 wyszukac wszystkie pokoje o tej rezerwacji i warunek zrobic na pokoje z bazy danych nie listbox
                        var query2 = (from roomres in contextDB.RoomReserved where roomres.Reservation_ID == ReseravtionID select roomres).ToList();


                        for (int i = 0; i < RoomSelectedLB.Items.Count; i++)
                        {
                            if (!contextDB.RoomReserved.Any(x => x.Room.RoomNameUnique == RoomSelectedLB.Items[i].ToString() && x.Reservation_ID == ReseravtionID))
                            {
//MessageBox.Show("nie istnieje w bazie danych");
                                RoomToSave = new RoomReserved();
                                contextDB.RoomReserved.InsertOnSubmit(RoomToSave);

                                RoomToSave.PriceFromDate  = TakePrice();
                                RoomToSave.Reservation_ID = (from res in contextDB.Reservation select res.Id).Max();
                                RoomToSave.Room_ID        = (from room in contextDB.Room
                                                             where room.RoomNameUnique.ToString() == RoomSelectedLB.Items[i].ToString()
                                                             select room.Id).First();
                            }
                            else if (contextDB.RoomReserved.Any(x => x.Room.RoomNameUnique == RoomSelectedLB.Items[i].ToString() && x.Reservation_ID == ReseravtionID))
                            {
//MessageBox.Show("istnieje w bazie danych przedluz moja rezerwacje");
                            }
                            contextDB.SubmitChanges();
                        }

                        for (int i = 0; i < query2.Count; i++)
                        {
                            if (!RoomSelectedLB.Items.Contains(query2[i].Room.RoomNameUnique) && query2[i].Reservation_ID.Equals(ReseravtionID))
                            {
//MessageBox.Show("nie istnieje w listboxie ale istnieje w bazie usun mnie");

                                RoomToSave = query2[i];
                                contextDB.RoomReserved.DeleteOnSubmit(RoomToSave);
                                contextDB.SubmitChanges();
                            }
                        }
                    } // edit roomreservation


                    // load database in Mainmenu Form and close active form
                    AddOrEdit = 1;
                    var mainForm = Application.OpenForms.OfType <MainMenu>().Single();
                    mainForm.RefreshData();
                    this.Close();
                }   // end of adding and editing reservation and roomreservation
                else if (AllRoomsGotGuest == false || LabelResOn.Text == "EMPTY")
                {
                    string       error1         = "Failed to make a reservation, please check that every room has a guest";
                    CustomDialog AddReservation = new CustomDialog(error1, 1);
                    AddReservation.ShowDialog();
                }
            }
            else
            {
                string       error2         = "Failed to make a reservation, please check that you have selected a room";
                CustomDialog AddReservation = new CustomDialog(error2, 1);
                AddReservation.ShowDialog();
            }
        }
        private void CheckPasswords()
        {
            if (Choice == 1)
            {
                string       s         = "";
                string       g         = "";
                string       ErrorText = "";
                CustomDialog ErrorForm = null;

                if (string.IsNullOrWhiteSpace(textBox1.Text) || string.IsNullOrWhiteSpace(textBox2.Text))
                {
                    ErrorText = "Make sure you fill in all the fields";
                    ErrorForm = new CustomDialog(ErrorText, 1);
                    ErrorForm.ShowDialog();

                    textBox1.Clear();
                    textBox2.Clear();
                    textBox3.Clear();
                }
                else
                {
                    // sprawdz czy podane haslo jest takie samo jak w bazie danych

                    Worker WorkerToSave = listOfWorkers.SelectedItem as Worker;
                    s = AccessOperation.EncryptPassword(textBox1.Text);
                    var usr = contextDB.Worker.Where(c => c.UserLogin == WorkerToSave.UserLogin && c.UserPassword == s).SingleOrDefault();

                    if (usr != null)
                    {
                        if (textBox2.Text != textBox3.Text || textBox2.Text == textBox1.Text)
                        {
                            ErrorText = "Check if your new password was entered correctly 2 times and if it differs from the old one";
                            ErrorForm = new CustomDialog(ErrorText, 1);
                            ErrorForm.ShowDialog();

                            textBox1.Clear();
                            textBox2.Clear();
                            textBox3.Clear();
                        }
                        else if (textBox2.Text != textBox1.Text && textBox2.Text == textBox3.Text)
                        {
                            g = AccessOperation.EncryptPassword(textBox2.Text);
                            WorkerToSave.UserPassword = g;
                            contextDB.SubmitChanges();

                            if (x.Count != 0)
                            {
                                SearchNextB.Enabled     = true;
                                SearchPreviousB.Enabled = true;
                            }
                            textBox1.PasswordChar = '\0';
                            textBox2.PasswordChar = '\0';
                            textBox3.PasswordChar = '\0';
                            DataChangeOff();
                        }
                    }
                    else
                    {
                        ErrorText = "To change the password you must enter the correct one first";
                        ErrorForm = new CustomDialog(ErrorText, 1);
                        ErrorForm.ShowDialog();

                        textBox1.Clear();
                        textBox2.Clear();
                        textBox3.Clear();
                    }
                }
            }
        }
        private void CheckWorkerInfo()
        {
            string       ErrorText = "";
            CustomDialog ErrorForm = null;

            if (String.IsNullOrWhiteSpace(textBox1.Text) || String.IsNullOrWhiteSpace(textBox2.Text) || String.IsNullOrWhiteSpace(textBox3.Text) || String.IsNullOrWhiteSpace(textBox4.Text))
            {
                ErrorText = "Check that you have not left any free fields";
                ErrorForm = new CustomDialog(ErrorText, 1);
                ErrorForm.ShowDialog();
            }
            else
            {
                //if(contextDB.Worker.Any(x => x.UserLogin == textBox4.Text))

                if (Choice == 3)
                {
                    if (contextDB.Worker.Any(x => x.UserLogin.Contains(textBox4.Text)))
                    {
//textBox8.Text = "niestety istnieje juz podany login";
                        ErrorText = "There is already a given login in the database, choose another one";
                        ErrorForm = new CustomDialog(ErrorText, 1);
                        ErrorForm.ShowDialog();
                    }
                    else
                    {
                        if (textBox6.Text != textBox7.Text)
                        {
                            ErrorText = "The given passwords do not match";
                            ErrorForm = new CustomDialog(ErrorText, 1);
                            ErrorForm.ShowDialog();
                        }
                        else
                        {
                            // dodaj nowego
                            SaveToDB(1);
                            DataChangeOff();

                            if (x.Count != 0)
                            {
                                SearchNextB.Enabled     = true;
                                SearchPreviousB.Enabled = true;
                            }
                        }
                    }
                }
                else if (Choice == 2)
                {
                    Worker WhoYouAre = listOfWorkers.SelectedItem as Worker;
                    if (contextDB.Worker.Any(x => x.UserLogin.Contains(textBox4.Text) && x.UserLogin != WhoYouAre.UserLogin))
                    {
//textBox8.Text = " istnieje juz podany login";
                        ErrorText = "There is already a given login in the database, choose another one";
                        ErrorForm = new CustomDialog(ErrorText, 1);
                        ErrorForm.ShowDialog();
                    }
                    else
                    {
                        // edytuj starego
                        SaveToDB(2);
                        DataChangeOff();
                        SearchNextB.Enabled     = true;
                        SearchPreviousB.Enabled = true;
                        //if (x.Count != 0)
                        //{
                        //    SearchNextB.Enabled = true;
                        //    SearchPreviousB.Enabled = true;
                        //}
                    }
                }
            }
        }
// BUTTONS TO EDIT LISTBOX ITEMS

        private void DeleteB_Click(object sender, EventArgs e)
        {
            string       ErrorText = "";
            CustomDialog ErrorForm = null;

            // SPRAWDZAMY CZY ADMIN
            if (LoggedUser.GetRole() == true)
            {
                Worker ToCheck = listOfWorkers.SelectedItem as Worker;

                if (ToCheck.Id == LoggedUser.GetId())
                {
                    ErrorText = "Are you sure you wanna delete your profile??";
                    ErrorForm = new CustomDialog(ErrorText, 2);
                    ErrorForm.ShowDialog();

                    if (ErrorForm.DialogResult == DialogResult.Yes)
                    {
                        // czy jestes pewny ze chcesz usunac swoj profil ?
                        DeleteUser(ToCheck);
//textBox8.Text = "profil admina usuniety";
                    }
                    else if (ErrorForm.DialogResult == DialogResult.No)
                    {
                        DataChangeOff();
//textBox8.Text = "nie udalo sie usunac profilu admina";
                    }
                }
                else if (ToCheck.Id != LoggedUser.GetId())
                {
                    ErrorText = "Are you sure you wanna delete this profile??";
                    ErrorForm = new CustomDialog(ErrorText, 2);
                    ErrorForm.ShowDialog();

                    if (ErrorForm.DialogResult == DialogResult.Yes)
                    {
                        // czy jestes pewny ze chcesz usunac swoj profil ?
                        DeleteUser(ToCheck);

                        MessageBox.Show("You have been logged out and your account has been deleted");

                        var mainForm = Application.OpenForms.OfType <MainMenu>().Single();
                        mainForm.Close();
                        this.Close();
                        var logIn = Application.OpenForms.OfType <LogIn>().Single();
                        logIn.Show();

                        //textBox8.Text = "profil uzytkownika usuniety przez admina";
                        //////////////////////////////////////////////////////////////////////////////////////////WYLOGUJ
                    }
                    else if (ErrorForm.DialogResult == DialogResult.No)
                    {
                        DataChangeOff();
//textBox8.Text = "nie udalo sie usunac profilu przez admina";
                    }
                }
            }
            else if (LoggedUser.GetRole() == false)
            {
                // sprawdzamy czy wybierasz siebie
                Worker CheckWhoYouAre = listOfWorkers.SelectedItem as Worker;
                if (CheckWhoYouAre.Id == LoggedUser.GetId())
                {
                    ErrorText = "Are you sure you wanna delete your profile??";
                    ErrorForm = new CustomDialog(ErrorText, 2);
                    ErrorForm.ShowDialog();

                    if (ErrorForm.DialogResult == DialogResult.Yes)
                    {
                        // czy jestes pewny ze chcesz usunac swoj profil ?


                        DeleteUser(CheckWhoYouAre);
                        MessageBox.Show("You have been logged out and your account has been deleted");

                        var mainForm = Application.OpenForms.OfType <MainMenu>().Single();
                        mainForm.Close();
                        this.Close();
                        var logIn = Application.OpenForms.OfType <LogIn>().Single();
                        logIn.Show();


                        //textBox8.Text = "profil pracownika usuniety";
                        //////////////////////////////////////////////////////////////////////////////////////////WYLOGUJ
                    }
                    else if (ErrorForm.DialogResult == DialogResult.No)
                    {
//textBox8.Text = "nie udalo sie usunac profilu pracownika";
                        DataChangeOff();
                    }
                }
                else if (CheckWhoYouAre.Id != LoggedUser.GetId())
                {
                    ErrorText = "You have no power here, ha ha ha!";
                    ErrorForm = new CustomDialog(ErrorText, 1);
                    ErrorForm.ShowDialog();
                }
            }

            DataChangeOff();
            // wyczysz search
        }