Beispiel #1
0
        } // end of btnViewAll

        /// <summary>
        /// this will accept the ticket number and
        /// finish the stuff for leave
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAccept_Click(object sender, EventArgs e)
        {
            #region --- hide stuffs ---
            lblValid.Visible         = false;
            lblTicketDetails.Visible = false;
            lblTcktNo.Visible        = false;
            lblTmIn.Visible          = false;
            txtBxTicketNumber.Clear();
            txtBxTicketNumber.Visible = false;
            txtBxTimeIn.Clear();
            txtBxTimeIn.Visible = false;
            #endregion -- hide --

            #region --- reveals ---
            lblTmIn.Visible      = true; // just added
            lblTicketOut.Visible = true;
            lblTmOut.Visible     = true;
            lblTtlTime.Visible   = true;
            lblAmntDue.Visible   = true;
            btnPiad.Visible      = true;
            btnPiad.Enabled      = true;
            lblTcktNo.Visible    = true;
            #endregion -- reveals --

            int    number = Convert.ToInt32(txtBxInput.Text); // sets the value for tkt number to search
            string leave  = DateTime.Now.ToString();          // sets the datetime of leaving
            // make stuff visible
            txtBxtktNumOut.Visible = true;
            txtBxTimeOut.Visible   = true;
            txtBxTotalTime.Visible = true;
            txtBxTotalDue.Visible  = true;

            XDocument doc = XDocument.Load("tickets.xml");          // loads the xml doc


            // problemn here it is not recognizing the objects after the original 5
            doc.XPathSelectElement("//tickets/Ticket[" + number + "]/timeOut").Value = leave;             // reads the doc and updates necessary fields based on ticket number
            string ventry = doc.XPathSelectElement("//tickets/Ticket[" + number + "]/timeIn").Value;

            doc.Save("tickets.xml");                        // saves the xml file

            DateTime entry     = DateTime.Parse(ventry);
            string   vexit     = doc.XPathSelectElement("//tickets/Ticket[" + number + "]/timeOut").Value;
            DateTime exit      = DateTime.Parse(vexit);
            TimeSpan timeInLot = Ticket.tmeInLot(entry, exit); // calls the tmeinlot method for calculating time in lot
            // calculate the money due
            double due;                                        // establishes the variable
            due = Ticket.AmountDue(timeInLot);                 // calls the amount due method
            // need to populate all fields
            txtBxTimeIn.Visible       = true;
            lblTmIn.Visible           = true;
            txtBxTicketNumber.Visible = true;
            txtBxTicketNumber.Text    = doc.XPathSelectElement("//tickets/Ticket[" + number + "]/tktNumber").Value;
            txtBxTimeIn.Text          = doc.XPathSelectElement("//tickets/Ticket[" + number + "]/timeIn").Value;
            txtBxtktNumOut.Text       = number.ToString();          //doc.XPathSelectElement("//tktNumber[text()='" + number + "']").Value;
            txtBxTimeOut.Text         = exit.ToString();            //doc.XPathSelectElement("//tktNumber[text()='" + number + "']/timeOut").Value;
            txtBxTotalDue.Text        = due.ToString("C0");         // stes the total due
            txtBxTotalTime.Text       = timeInLot.Hours.ToString(); // sets the time in lot

            txtBxInput.Enabled = false;
        } // end of btnAccept
Beispiel #2
0
        /// <summary>
        /// Check out tickets and check to see if that ticket is valid to check out
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCheckout_Click(object sender, EventArgs e)
        {
            int    availableSlot = AvailableSlot();
            string message;
            int    ticketOut;// index of the ticket you want to check out in TicketArray[]


            if (radBtnCheckOut.Checked == false)
            {
                message = ("Please check on the \"Check OUT\" box to check in");
                MessageBox.Show(message);
            }
            else if (!Int32.TryParse(txtBxTicketNumber.Text, out int number) || txtBxTicketNumber.Text == "")
            {
                MessageBox.Show("Please Enter YourTicket number to check out");
            }
            //!Int32.TryParse(txtBxTicketNumber.Text, out int number)
            else
            {
                // instantiate a student object with the text box data

                if (number >= idx || number < 0 || IfCheckedOut(number))
                {
                    MessageBox.Show("Cannot find this ticket number in the system.\nPlease try again.");
                }
                else
                {
                    Ticket aTicket = new Ticket();
                    aTicket.TicketNo = txtBxTicketNumber.Text;
                    //DateTime timeNow = DateTime.Now.AddHours(24).AddMinutes(15).TimeOfDay;
                    // TimeSpan trimmedTimeNow = new TimeSpan(timeNow.Hours, timeNow.Minutes, timeNow.Seconds); // Get time if format (get rid of the milliseconds)
                    aTicket.TimeOut = DateTime.Now;
                    //aTicket.TimeOut = DateTime.Now.AddHours(25).AddMinutes(59);

                    for (ticketOut = 0; ticketOut < Ticket.TicketArray.Length; ticketOut++)
                    {
                        if (Ticket.TicketArray[ticketOut] != null)
                        {
                            if (Ticket.TicketArray[ticketOut].TicketNo == aTicket.TicketNo)
                            {
                                break;
                            }
                        }
                    }
                    Ticket.TicketArray[ticketOut].TimeOut = aTicket.TimeOut;
                    decimal chargeAmount = Ticket.CalculateCharege(Ticket.TicketArray[ticketOut].TimeIn, Ticket.TicketArray[ticketOut].TimeOut);
                    MessageBox.Show($"Check Out Ticket #{Ticket.TicketArray[ticketOut].TicketNo}\n" +
                                    $"Time In:     {Ticket.TicketArray[ticketOut].TimeIn}\n" +
                                    $"Time Out: {Ticket.TicketArray[ticketOut].TimeOut}\n" +
                                    $"Charge amount: {chargeAmount:C}");

                    checkoutList.Add(number);
                    /// Delete Ticket from Garage and TicketArray
                    Ticket.Garage[ticketOut]      = (false);
                    Ticket.TicketArray[ticketOut] = null;////
                    #region XML Writer
                    // establish our xml writer settings
                    XmlWriterSettings settings = new XmlWriterSettings();
                    settings.Indent          = true;
                    settings.NewLineHandling = NewLineHandling.Replace;
                    using (XmlWriter writer = XmlWriter.Create("Tickets.xml", settings))
                    {
                        writer.WriteStartDocument();                           // write the xml header
                        writer.WriteStartElement("Tickets");                   // write our root tag
                        for (int i = 0; i < Ticket.TicketArray.Length; i++)
                        {
                            if (Ticket.TicketArray[i] != null)
                            {
                                writer.WriteStartElement("Ticket");                                               // write a Ticket tag
                                writer.WriteElementString("TicketNo", Ticket.TicketArray[i].TicketNo.ToString()); // add Ticket fields
                                writer.WriteElementString("TimeIn", Ticket.TicketArray[i].TimeIn.ToString());
                                writer.WriteElementString("TimeOut", aTicket.TimeOut.ToString());
                                writer.WriteEndElement();
                            }
                        }
                    }
                    #endregion
                    ListUpdate();
                }//End of Else
            }
            txtBxTicketNumber.Text = "";
        }// enmd of checkout button