Ejemplo n.º 1
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            BinaryFormatter bfmRentalOrders = new BinaryFormatter();
            Dictionary <int, RentalOrder> lstRentalOrders = new Dictionary <int, RentalOrder>();
            string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\RentalOrders.ros";

            if (File.Exists(strFileName))
            {
                using (FileStream stmRentalOrders = new FileStream(strFileName,
                                                                   FileMode.Open,
                                                                   FileAccess.Read,
                                                                   FileShare.Read))
                {
                    lstRentalOrders = (Dictionary <int, RentalOrder>)bfmRentalOrders.Deserialize(stmRentalOrders);
                }
            }

            if (string.IsNullOrEmpty(txtReceiptNumber.Text))
            {
                MessageBox.Show("You must enter a receipt number.",
                                "Bethesda Car Rental",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (File.Exists(strFileName))
            {
                using (FileStream stmRentalOrders = new FileStream(strFileName,
                                                                   FileMode.Open,
                                                                   FileAccess.Read,
                                                                   FileShare.Read))
                {
                    lstRentalOrders = (Dictionary <int, RentalOrder>)bfmRentalOrders.Deserialize(stmRentalOrders);

                    foreach (KeyValuePair <int, RentalOrder> kvp in lstRentalOrders)
                    {
                        if (kvp.Key == int.Parse(txtReceiptNumber.Text))
                        {
                            RentalOrder ro = kvp.Value;

                            //dtpDateProcessed.Value = DateTime.Parse(ro.DateProcessed);
                            txtEmployeeNumber.Text = ro.EmployeeNumber;
                            txtEmployeeNumber_Leave(sender, e);
                            txtCustomerFirstName.Text = ro.CustomerFirstName;
                            txtCustomerLastName.Text  = ro.CustomerLastName;
                            txtCustomerAddress.Text   = ro.CustomerAddress;
                            txtCustomerCity.Text      = ro.CustomerCity;
                            cbxCustomerStates.Text    = ro.CustomerState;
                            txtCustomerZIPCode.Text   = ro.CustomerZIPCode;
                            txtTagNumber.Text         = ro.VehicleTagNumber;
                            txtTagNumber_Leave(sender, e);
                            cbxVehiclesConditions.Text = ro.VehicleCondition;
                            cbxTanksLevels.Text        = ro.TankLevel;
                            txtMileageStart.Text       = ro.MileageStart.ToString();
                            txtMileageEnd.Text         = ro.MileageEnd.ToString();
                            txtMileageTotal.Text       = ro.MileageTotal.ToString();
                            //dtpRentStartDate.Value = DateTime.Parse(ro.RentStartDate);
                            //dtpRentEndDate.Value = DateTime.Parse(ro.RentEndDate);
                            txtTotalDays.Text   = ro.TotalDays.ToString();
                            txtRateApplied.Text = ro.RateApplied.ToString();
                            txtSubTotal.Text    = ro.SubTotal.ToString();
                            txtTaxRate.Text     = ro.TaxRate.ToString();
                            txtTaxAmount.Text   = ro.TaxAmount.ToString();
                            txtOrderTotal.Text  = ro.OrderTotal.ToString();
                            //cbxOrderStatus.Text = ro.OrderStatus;
                            txtNotes.Text = ro.Notes;
                            return;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void btnUpdateRentalOrder_Click(object sender, EventArgs e)
        {
            BinaryFormatter bfmRentalOrders = new BinaryFormatter();
            Dictionary <int, RentalOrder> lstRentalOrders = new Dictionary <int, RentalOrder>();
            string strFileName = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\RentalOrders.ros";

            if (string.IsNullOrEmpty(txtReceiptNumber.Text))
            {
                MessageBox.Show("The receipt number is missing.",
                                "Bethesda Car Rental",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Don't save this rental order if we don't
            // know who processed it
            if (string.IsNullOrEmpty(txtEmployeeNumber.Text))
            {
                MessageBox.Show("You must enter the employee number of the " +
                                "clerk who processed this order.",
                                "Bethesda Car Rental",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Don't save the rental order if we don't
            // know what car is being rented
            if (string.IsNullOrEmpty(txtTagNumber.Text))
            {
                MessageBox.Show("You must enter the tag number " +
                                "of the vehicle that is being rented.",
                                "Bethesda Car Rental",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (File.Exists(strFileName))
            {
                using (FileStream stmRentalOrders = new FileStream(strFileName,
                                                                   FileMode.Open,
                                                                   FileAccess.Read,
                                                                   FileShare.Read))
                {
                    lstRentalOrders = (Dictionary <int, RentalOrder>)bfmRentalOrders.Deserialize(stmRentalOrders);

                    foreach (KeyValuePair <int, RentalOrder> kvpRentalOrder in lstRentalOrders)
                    {
                        if (kvpRentalOrder.Key == int.Parse(txtReceiptNumber.Text))
                        {
                            RentalOrder order = kvpRentalOrder.Value;

                            order.DateProcessed     = dtpDateProcessed.Value;
                            order.EmployeeNumber    = txtEmployeeNumber.Text;
                            order.CustomerFirstName = txtCustomerFirstName.Text;
                            order.CustomerLastName  = txtCustomerLastName.Text;
                            order.CustomerAddress   = txtCustomerAddress.Text;
                            order.CustomerCity      = txtCustomerCity.Text;
                            order.CustomerState     = cbxCustomerStates.Text;
                            order.CustomerZIPCode   = txtCustomerZIPCode.Text;
                            order.VehicleTagNumber  = txtTagNumber.Text;
                            order.VehicleCondition  = cbxVehiclesConditions.Text;
                            order.TankLevel         = cbxTanksLevels.Text;
                            order.MileageStart      = int.Parse(txtMileageStart.Text);
                            order.MileageEnd        = int.Parse(txtMileageEnd.Text);
                            order.MileageTotal      = int.Parse(txtMileageTotal.Text);
                            order.RentStartDate     = dtpRentStartDate.Value;
                            order.RentEndDate       = dtpRentEndDate.Value;
                            order.TotalDays         = int.Parse(txtTotalDays.Text);
                            order.RateApplied       = double.Parse(txtRateApplied.Text);
                            order.SubTotal          = double.Parse(txtSubTotal.Text);
                            order.TaxRate           = double.Parse(txtTaxRate.Text);
                            order.TaxAmount         = double.Parse(txtTaxAmount.Text);
                            order.OrderTotal        = double.Parse(txtOrderTotal.Text);
                            //order.OrderStatus = cbxOrderStatus.Text;
                            order.Notes = txtNotes.Text;

                            break;
                        }
                    }
                }
            }

            using (FileStream bcrStream = new FileStream(strFileName,
                                                         FileMode.Create,
                                                         FileAccess.Write,
                                                         FileShare.Write))
            {
                bfmRentalOrders.Serialize(bcrStream, lstRentalOrders);
            }

            Close();
        }
Ejemplo n.º 3
0
        private void ShowRentalOrders()
        {
            string   orderStatus, notes;
            string   condition, tankLevel;
            DateTime dateProcessed, rentStartDate, rentEndDate;
            string   customer = "", employee = "", vehicle = "";
            int      mileageStart, mileageEnd, mileageTotal, totalDays;
            string   employeeNumber, employeeFirstName, employeeLastName;
            double   rateApplied, subTotal, taxRate, taxAmount, orderTotal;

            BinaryFormatter bfmVehicles                   = new BinaryFormatter();
            BinaryFormatter bfmEmployees                  = new BinaryFormatter();
            BinaryFormatter bfmRentalOrders               = new BinaryFormatter();
            Dictionary <string, Vehicle>  lstVehicles     = new Dictionary <string, Vehicle>();
            Dictionary <string, Employee> lstEmployees    = new Dictionary <string, Employee>();
            Dictionary <int, RentalOrder> lstRentalOrders = new Dictionary <int, RentalOrder>();
            string strVehiclesFile                        = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Vehicles.crs";
            string strEmployeesFile                       = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\Employees.cre";
            string strRentalOrdersFile                    = @"C:\Microsoft Visual C# Application Design\Bethesda Car Rental\RentalOrders.ros";

            if (File.Exists(strRentalOrdersFile))
            {
                lvwRentalOrders.Items.Clear();

                using (FileStream stmRentalOrders = new FileStream(strRentalOrdersFile,
                                                                   FileMode.Open,
                                                                   FileAccess.Read,
                                                                   FileShare.Read))
                {
                    lstRentalOrders = (Dictionary <int, RentalOrder>)bfmRentalOrders.Deserialize(stmRentalOrders);

                    foreach (KeyValuePair <int, RentalOrder> kvp in lstRentalOrders)
                    {
                        RentalOrder  ro             = kvp.Value;
                        ListViewItem lviRentalOrder = new ListViewItem(kvp.Key.ToString());

                        //dateProcessed = DateTime.Parse(ro.DateProcessed);
                        dateProcessed = new DateTime(06, 06, 2017);


                        using (FileStream stmEmployees = new FileStream(strEmployeesFile,
                                                                        FileMode.Open,
                                                                        FileAccess.Read,
                                                                        FileShare.Read))
                        {
                            // Retrieve the list of employees from file
                            lstEmployees = (Dictionary <string, Employee>)bfmEmployees.Deserialize(stmEmployees);

                            // Use the KeyValuePair class to visit each key/value item
                            foreach (KeyValuePair <string, Employee> kvpEmployee in lstEmployees)
                            {
                                Employee empl = kvpEmployee.Value;

                                if (kvpEmployee.Key == ro.EmployeeNumber)
                                {
                                    employee = kvpEmployee.Key + ": " + empl.EmployeeName;
                                    break;
                                }
                            }
                        }

                        customer = ro.CustomerFirstName + " " + ro.CustomerLastName;

                        using (FileStream stmVehicles = new FileStream(strVehiclesFile,
                                                                       FileMode.Open,
                                                                       FileAccess.Read,
                                                                       FileShare.Read))
                        {
                            lstVehicles = (Dictionary <string, Vehicle>)bfmVehicles.Deserialize(stmVehicles);

                            foreach (KeyValuePair <string, Vehicle> kvpVehicle in lstVehicles)
                            {
                                Vehicle car = kvpVehicle.Value;

                                if (kvpVehicle.Key == ro.VehicleTagNumber)
                                {
                                    vehicle = kvpVehicle.Key + ": " + car.Make + " " + car.Model;
                                }
                            }
                        }

                        condition    = ro.VehicleCondition;
                        tankLevel    = ro.TankLevel;
                        mileageStart = ro.MileageStart;
                        mileageEnd   = ro.MileageEnd;
                        mileageTotal = ro.MileageTotal;
                        //rentStartDate = DateTime.Parse(ro.RentStartDate);
                        //rentEndDate = DateTime.Parse(ro.RentEndDate);
                        totalDays   = ro.TotalDays;
                        rateApplied = ro.RateApplied;
                        subTotal    = ro.SubTotal;
                        taxRate     = ro.TaxRate;
                        taxAmount   = ro.TaxAmount;
                        orderTotal  = ro.OrderTotal;
                        //orderStatus = ro.OrderStatus;
                        notes = ro.Notes;

                        lviRentalOrder.SubItems.Add(dateProcessed.ToShortDateString());
                        lviRentalOrder.SubItems.Add(employee);
                        lviRentalOrder.SubItems.Add(customer);
                        lviRentalOrder.SubItems.Add(vehicle);
                        lviRentalOrder.SubItems.Add(condition);
                        lviRentalOrder.SubItems.Add(tankLevel);
                        lviRentalOrder.SubItems.Add(mileageStart.ToString());
                        lviRentalOrder.SubItems.Add(mileageEnd.ToString());
                        lviRentalOrder.SubItems.Add(mileageTotal.ToString());
                        //lviRentalOrder.SubItems.Add(rentStartDate.ToShortDateString());
                        //lviRentalOrder.SubItems.Add(rentEndDate.ToShortDateString());
                        lviRentalOrder.SubItems.Add(totalDays.ToString());
                        lviRentalOrder.SubItems.Add(rateApplied.ToString());
                        lviRentalOrder.SubItems.Add(subTotal.ToString());
                        lviRentalOrder.SubItems.Add(taxRate.ToString());
                        lviRentalOrder.SubItems.Add(taxAmount.ToString());
                        lviRentalOrder.SubItems.Add(orderTotal.ToString());
                        //lviRentalOrder.SubItems.Add(orderStatus);
                        lviRentalOrder.SubItems.Add(notes);

                        lvwRentalOrders.Items.Add(lviRentalOrder);
                    }
                }
            }
        }