I am making a car mart project. I want to track the staff users of the changes they make to the StaffManageCars.cs as well as StaffManageParking.cs.
How I want is: When I debug the form,the Menu appears. Let us say the user clicks on Manage Cars, the user is asked to enter his credentials in order to manage cars(like the Add,Update,Display, etc.). After the user manages the cars using the StaffManageCars,it should track & save the time & date of the activity automatically in another form,which I don't have right now.It applies the same for Manage Parking.
CAN YOU PLEASE CODE AS EARLY AS POSSIBLE BECAUSE THE DEADLINE IS 6PM (SINGAPORE TIME)?
These are my codes below:
Menu.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ProjectV2
{
public partial class Menu : Form
{
private string[] vehicle_model;
private float[] askingPrice;
public Menu()
{
InitializeComponent();
}
public Menu(string[] vehicle_model, float[] askingPrice)
{
this.vehicle_model = vehicle_model;
this.askingPrice = askingPrice;
new StaffManageParking(vehicle_model, askingPrice).Show();
}
private void btnManageCars_Click(object sender, EventArgs e)
{
new StaffLogin(1).Show();
}
private void btnManageParkingLots_Click(object sender, EventArgs e)
{
new StaffLogin(2).Show();
}
private void btnCusPg_Click(object sender, EventArgs e)
{
new CustomerPage().Show();
}
}
}
StaffLogin.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ProjectV2
{
public partial class StaffLogin : Form
{
int A;
public StaffLogin(int i)
{
InitializeComponent();
A = i;
}
private string[] vehicle_model;
private float[] askingPrice;
public StaffLogin(int i, string[] vehicle_model, float[] askingPrice)
{
InitializeComponent();
A = i;
this.vehicle_model = vehicle_model;
this.askingPrice = askingPrice;
}
string[] usernameDB = { "shank1995", "kuenguan94", "helen" };
string[] passwordDB = { "12345", "67890", "1762" };
private void button1_Click(object sender, EventArgs e)
{
string login = txtLogin.Text;
string password = txtPassword.Text;
if (((password == "12345") && (login == "shank")) || ((password == "67890") && (login == "kuenguan")) || ((password == "1762") && (login == "helen")))
{
MessageBox.Show("Access Granted!");
if (A == 1)
{
A = 0;
new StaffManageCars().Show();
}
else if (A == 2)
{
A = 0;
new StaffManageParking(vehicle_model, askingPrice).Show();
}
Close();
}
else
{
MessageBox.Show("Username & password are invalid. Please retype correctly");
}
}
}
}
StaffManageParking.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ProjectV2
{
public partial class StaffManageParking : Form
{
public StaffManageParking()
{
InitializeComponent();
}
public StaffManageParking(string[] vehicle_model, float[] askingPrice)
{
this.vehicle_model = vehicle_model;
this.askingPrice = askingPrice;
InitializeComponent();
}
string [,] usedCars = new string [4,20];
private string[] vehicle_model;
private float[] askingPrice;
private void btnDisplay_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
richTextBox1.AppendText(" \t");
for (int col = 1; col <= usedCars.GetLength(1); col++)
{
richTextBox1.AppendText(" Col " + col + " \t");
}
richTextBox1.AppendText("\n");
for (int row = 0; row < usedCars.GetLength(0); row++)
{
richTextBox1.AppendText(" Row " + (row + 1) + ":\t");
for (int col = 0; col < usedCars.GetLength(1); col++)
{
richTextBox1.AppendText("[ " + usedCars[row, col] + " ]\t");
}
richTextBox1.AppendText("\n");
}
}
private void btnDisplayCarLocation_Click(object sender, EventArgs e)
{
int c = 0;
string wantedCar = txtCarModel.Text;
for (int row = 0; row < usedCars.GetLength(0); row++)
{
for (int col = 0; col < usedCars.GetLength(1); col++)
{
if (wantedCar == usedCars[row, col])
{
richTextBox1.AppendText("Found: " + wantedCar.ToString() + " @ parking floor: " + (row + 1).ToString() + " & parking space: " + (col + 1).ToString());
break;
}
else
{
c++;
}
}
}
if (c != 0)
{
MessageBox.Show("The car is not found in the parking plan");
}
}
private void btnAssignParking_Click(object sender, EventArgs e)
{
int floor = int.Parse(parkingFloor.Text);
int space = int.Parse(parkingSpace.Text);
usedCars[floor - 1, space - 1] = txtCarModel.Text;
MessageBox.Show("Car: " + txtCarModel.Text + " is assigned parking lot number: " + floor + "." + space);
}
private void btnTotalValue_Click(object sender, EventArgs e)
{
float total_sum = 0.0f;
for (int i = 0; i < askingPrice.Length; i++)
{
total_sum = total_sum + askingPrice[i];
}
richTextBox1.AppendText("The total sum of all used cars are " + total_sum.ToString("c") + "\n");
}
private void btnEmptyParking_Click(object sender, EventArgs e)
{
int floor = int.Parse(parkingFloor.Text);
int space = int.Parse(parkingSpace.Text);
string carModel = usedCars[floor - 1, space - 1];
usedCars[floor - 1, space - 1] = "";
MessageBox.Show("Car: " + carModel + " is deleted from its parking lot number " + floor + "." + space);
}
}
}
StaffManageCars.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProjectV2;
namespace ProjectV2
{
public partial class StaffManageCars : Form
{
public StaffManageCars()
{
InitializeComponent();
}
string[] vehicle_registrationNum = new string[80];
string[] vehicle_model = new string[80];
int[] vehicle_yearMake = new int[80];
float[] askingPrice = new float[80];
float[] transactedPrice = new float[80];
int index = 0;
int found = 0;
private void btnUpdate_Click(object sender, EventArgs e)
{
vehicle_registrationNum[found] = txtVehicleRegistryNo.Text;
vehicle_model[found] = txtVehicleModel.Text;
vehicle_yearMake[found] = int.Parse(txtYearVehicleMake.Text);
askingPrice[found] = float.Parse(txtAskingPrice.Text);
transactedPrice[found] = float.Parse(txtTransactionPrice.Text);
simpleton.askPrice = askingPrice;
simpleton.vehiModel = vehicle_model;
MessageBox.Show("Data successfully updated for " + txtVehicleModel.Text + " with registration number: " + txtVehicleRegistryNo.Text);
rtbDisplay.AppendText("Updated Registration No.\t Updated Model\t Updated Year Make\t Updated Asking Price\t Updated Transaction Price\t \n");
rtbDisplay.AppendText(vehicle_registrationNum[found].ToString().PadRight(29) + vehicle_model[found].ToString().PadRight(15) + vehicle_yearMake[found].ToString().PadRight(30) + askingPrice[found].ToString("c").PadRight(30) + transactedPrice[found].ToString("c") + "\n");
}
private void btnClear_Click(object sender, EventArgs e)
{
txtVehicleRegistryNo.Clear();
txtVehicleModel.Clear();
txtYearVehicleMake.Clear();
txtAskingPrice.Clear();
txtTransactionPrice.Clear();
txtVehicleModel.Focus();
rtbTable.Clear();
rtbDisplay.Clear();
}
private void btnAdd_Click(object sender, EventArgs e)
{
vehicle_model[index] = txtVehicleModel.Text;
vehicle_registrationNum[index] = txtVehicleRegistryNo.Text;
vehicle_yearMake[index] = int.Parse(txtYearVehicleMake.Text);
askingPrice[index] = float.Parse(txtAskingPrice.Text);
transactedPrice[index] = float.Parse(txtTransactionPrice.Text);
index++;
simpleton.askPrice = askingPrice;
simpleton.vehiModel = vehicle_model;
MessageBox.Show("Record Added Successfully \n");
}
private void btnList_Click(object sender, EventArgs e)
{
rtbTable.Clear();
rtbTable.AppendText("Registration No.\t Model\t Year Make\t Asking Price\t Transaction Price\t \n");
for (int i = 0; i < index; i++)
{
rtbTable.AppendText(vehicle_registrationNum[i].ToString().PadRight(29) + vehicle_model[i].PadRight(15) + vehicle_yearMake[i].ToString().PadRight(30) + askingPrice[i].ToString("c").PadRight(30) + transactedPrice[i].ToString("c") + "\n");
}
rtbTable.AppendText("* * * END OF LIST * * *\n");
}
private void btnFindHighestTransactedPrice_Click(object sender, EventArgs e)
{
float highest_transactedPrice = transactedPrice[0];
int max_index = 0;
for (int i = 0; i < 80; i++)
{
if (highest_transactedPrice < transactedPrice[i])
{
highest_transactedPrice = transactedPrice[i];
max_index = i;
}
}
MessageBox.Show("The Highest Transacted Price is " + highest_transactedPrice.ToString("c") + "\n");
}
private void btnSearch_Click(object sender, EventArgs e)
{
int vehicleYearMake = int.Parse(txtYearVehicleMake.Text);
string vehicleModel = txtVehicleModel.Text;
float transactionPrice = float.Parse(txtTransactionPrice.Text);
string vehicleRegNum = txtVehicleRegistryNo.Text;
for (int i = 0; i < vehicle_model.GetLength(0); i++)
{
if ((vehicleModel == vehicle_model[i]) && (vehicleYearMake == vehicle_yearMake[i]) && (transactionPrice == transactedPrice[i]) && (vehicleRegNum == vehicle_registrationNum[i]))
{
MessageBox.Show("Found Vehicle Model : " + vehicle_model[i] + ",Made in year " + vehicle_yearMake[i] + ",Cost: " + transactedPrice[i].ToString("c") + ",Registration Number:" + vehicle_registrationNum[i]);
break;
}
else
{
MessageBox.Show("Car Not Found!");
break;
}
}
}
}
}