Esempio n. 1
0
 public AccountLookup(Controller controller, Form frm, Invoice aInvoice)
 {
     this.controller = controller;
     this.frm = frm;
     this.invoice = aInvoice;
     InitializeComponent();
 }
Esempio n. 2
0
        public void saveInvoice(Invoice invoice)
        {
            try{
                DateTime dt = DateTime.Parse(invoice.getDate());

                string sql = "INSERT INTO Invoice (CarId, AccountId, Duration, PreCharge, Date) values(@carId, @accountId, @duration, @preCharge, @date)";
                conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);

                MySqlCommand command = new MySqlCommand(sql,conn);
                command.Parameters.AddWithValue("carId", invoice.getCarID());
                command.Parameters.AddWithValue("accountId", invoice.getAccountID());
                command.Parameters.AddWithValue("duration", invoice.getDuration());
                command.Parameters.AddWithValue("preCharge", invoice.getPreCharge());
                command.Parameters.AddWithValue("date", dt.ToString("yyyy-MM-dd"));
                conn.Open();

                command.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
            }
        }
Esempio n. 3
0
 private void btnRent_Click(object sender, EventArgs e)
 {
     if(txtPreCharge.Text == "" || txtPreCharge.Text == "0" || txtPreCharge.Text == null){
         MessageBox.Show("You must enter and calculate fields");
     } else {
         Invoice invoice = new Invoice(cmboCar.SelectedValue.ToString(), txtDuration.Text, txtPreCharge.Text, DateTime.Today.ToString("yyyy-MM-dd"));
         loadForm(new AccountLookup(controller, this, invoice));
     }
 }
Esempio n. 4
0
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     invoice = controller.lookupInvoiceForAccount(txtDriversLicense.Text);
     if (invoice != null)
     {
         loadForm(new ReturnRentalReceipt(controller, invoice,this));
     }
     else
     {
         lblMessage.Text = "No rentals found.";
     }
 }
        public ReturnRentalReceipt(Controller controller, Invoice invoice, Form frm)
        {
            this.controller = controller;
            this.invoice = invoice;
            this.frm = frm;
            account = controller.getAccount(invoice.getAccountID());
            car = controller.getCar(invoice.getCarID());

            InitializeComponent();
            lblLastName.Text = account.getLastName();
            lblFirstName.Text = account.getFirstName();
            lblAccountNumber.Text = account.getDriversLicense();
            lblAddress.Text = account.getAddress();
            lblCity.Text = account.getCity();
            lblState.Text = account.getState();
            lblZip.Text = account.getZip();
            lblDays.Text = invoice.getDuration();
            lblPreCost.Text = String.Format("{0:C}",Double.Parse(invoice.getPreCharge()));
            lblMake.Text = car.getMake();
            lblModel.Text = car.getModel();
            lblModelCost.Text = String.Format("{0:C}", controller.rentalModelCost(car.getRentalModel()));
        }
Esempio n. 6
0
        internal void updateInvoice(Invoice invoice)
        {
            try
            {
                string sql = "UPDATE Invoice SET Total = @total, Miles = @miles WHERE InvoiceId = @invoiceId";

                conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);

                MySqlCommand command = new MySqlCommand(sql, conn);
                command.Parameters.AddWithValue("total", invoice.getTotal());
                command.Parameters.AddWithValue("miles", invoice.getMiles());
                command.Parameters.AddWithValue("invoiceId", invoice.getInvoiceId());

                conn.Open();

                command.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
            }
        }
Esempio n. 7
0
        internal Invoice lookupInvoiceForAccount(string aDriversLicense)
        {
            Invoice invoice = null;
            try
            {
                string sql = "SELECT * FROM Invoice WHERE (Total = -1 AND AccountId = @driversLicense)";
                conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);
                MySqlCommand command = new MySqlCommand(sql, conn);
                command.Parameters.AddWithValue("driversLicense", aDriversLicense);

                conn.Open();

                MySqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        invoice = new Invoice(reader[0].ToString(), reader[1].ToString(), reader[2].ToString(), reader[3].ToString(), reader[4].ToString(), reader[5].ToString(), reader[6].ToString(), reader[7].ToString());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    // Always call Close when done reading.
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                conn.Close();
            }
            return invoice;
        }
Esempio n. 8
0
 internal void updateInvoice(Invoice invoice, bool isAvailable)
 {
     database.updateInvoice(invoice);
     database.rentCar(invoice.getCarID(), isAvailable);
 }