public void tryRentVehicle() { Vehicle vehicleObject = mainWindow.serverData.client.getUserVehicle(mainWindow.clientData.account); if (vehicleObject.plate != "none") { MessageBox.Show("Ви вже маєте орендований автомобіль.", "Відмова оренди", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (totalPrice > mainWindow.clientData.account.balance) { MessageBox.Show("Оренда неможлива, поповніть рахунок.", "Відміна оренди", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (vehicle.clientid != 0) { MessageBox.Show("Оренда неможлива, автомобіль вже орендований.", "Відміна оренди", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult answer = MessageBox.Show("Ви дійсно хочите орендувати " + vehicle.name + " " + vehicle.model + "?\n\n" + "Дата початку оренди: " + DateTime.Now.ToShortTimeString() + "\n" + "Дата кінця оренди: " + rentDate.ToShortTimeString(), "Підтвердіть дію", MessageBoxButtons.YesNoCancel); if (answer == DialogResult.Yes) { mainWindow.clientData.account.balance -= totalPrice; vehicle.start_date = DateTime.Now; vehicle.end_date = rentDate; vehicle.clientid = mainWindow.clientData.account.id; CashVoucher voucher = ShowCashVoucher.Collect(mainWindow.clientData.account, vehicle, totalPrice, vehicle.start_date, vehicle.end_date); int Id = mainWindow.serverData.client.writeCashVoucher(voucher); vehicle.rentlogid = mainWindow.serverData.client.log_TakeRent( mainWindow.clientData.account.id, vehicle.VIN, totalPrice, Id, vehicle.start_date, vehicle.end_date); mainWindow.serverData.client.saveVehicle(vehicle); mainWindow.updateAccountData(); mainWindow.main_page1.updateVehicleData(); mainWindow.clientData.ui.CreatePanel(mainWindow.clientData.ui.MAIN_PANEL, mainWindow); ShowCashVoucher.Create(mainWindow.serverData.client.readCashVoucher(Id)); mainWindow.dialogCreate("Ви орендовали автомобіль. Вітаємо!", "Підтвердження оренди", MessageBoxButtons.OK, MessageBoxIcon.Information); Hide(); } }
private void btn_check_Click(object sender, EventArgs e) { int Id = mainWindow.serverData.client.sendCashVoucherID(vehicleObject.rentlogid); if (Id != -1) { ShowCashVoucher.Create(mainWindow.serverData.client.readCashVoucher(Id)); } else { mainWindow.dialogCreate("Чек недоступний.", "Чек недоступний", MessageBoxButtons.OK, MessageBoxIcon.Error); } }