Example #1
0
        private void ShowUserReservation_Click(object sender, EventArgs e)
        {
            ShowMyReservations showres = new ShowMyReservations();

            showres.Show();
        }
Example #2
0
        private void CancelReservButt_Click(object sender, EventArgs e)
        {
            ShowMyReservations showres = new ShowMyReservations();

            showres.Show();
        }
Example #3
0
        private void DeleteSelectedReservation_Click(object sender, EventArgs e)
        {
            if (CarBox.SelectedItem == null)
            {
                MessageBox.Show("Choose car to remove please!");
                return;
            }
            var    selectedDate = DateBox.Items[CarBox.SelectedIndex].ToString();
            string selectedCar  = CarBox.SelectedItem.ToString();

            string[] filesReserved = Directory.GetFiles("data\\administrator\\carsreserved\\"); //load all files of RESERVED


            for (int i = 0; i < filesReserved.Length; i++)
            {
                if (filesReserved[i].Contains(selectedCar))
                {
                    string[] AllLines = File.ReadAllLines(filesReserved[i]);
                    for (int a = 0; a < AllLines.Length; a++)
                    {
                        bool jetamjmeno = false;
                        int  datumcount = 1;
                        if (AllLines[a].Contains(selectedDate))                                       //najdeme v souboru datum!
                        {
                            while (jetamjmeno == false)                                               //find name
                            {
                                if (DateTime.TryParse(AllLines[a - datumcount], out DateTime result)) //pokud je to datetime, hledáme dál nahoru jmeno
                                {
                                    datumcount++;
                                    continue;
                                }
                                else  //je to jmeno
                                {
                                    jetamjmeno = true;
                                    if (AllLines[a - datumcount] != "")        //vymazat jmeno
                                    {
                                        while (AllLines[a - datumcount] != "") //postupujeme dál dolu a hledáme, kde končí daná rezervace ("")
                                        {
                                            AllLines[a - datumcount] = "";
                                            datumcount--;
                                        }
                                    }
                                }
                            }
                        }
                    }


                    using (StreamWriter sw = new StreamWriter(filesReserved[i]))
                    {
                        for (int a = 0; a < AllLines.Length; a++)
                        {
                            sw.WriteLine(AllLines[a]);
                        }
                    }
                }
            }
            ShowMyReservations.ActiveForm.Dispose();
            ShowMyReservations sd = new ShowMyReservations();

            sd.Show();
        }