Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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:
C#
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;          //done by Shashank
        private float[] askingPrice;             //done by Shashank

        public Menu()
        {
            InitializeComponent();
        }

        public Menu(string[] vehicle_model, float[] askingPrice)      //done by Shashank
        {
            // TODO: Complete member initialization
            this.vehicle_model = vehicle_model;                       //done by Shashank
            this.askingPrice = askingPrice;                           //done by Shashank                 
            new StaffManageParking(vehicle_model, askingPrice).Show();//done by Shashank
        }

        private void btnManageCars_Click(object sender, EventArgs e)//done by Shashank
        {
            new StaffLogin(1).Show();                               //done by Shashank
        }

        private void btnManageParkingLots_Click(object sender, EventArgs e)//done by Shashank
        {

            new StaffLogin(2).Show();                                      //done by Shashank
        }

        private void btnCusPg_Click(object sender, EventArgs e)//done by Shashank
        {
            new CustomerPage().Show();                         //done by Shashank
        }
    }
}

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;                                                          //done by Shashank
        private float[] askingPrice;                                                             //done by Shashank
        public StaffLogin(int i, string[] vehicle_model, float[] askingPrice)
        {
            InitializeComponent();
            A = i;
            this.vehicle_model = vehicle_model;                    //done by Shashank
            this.askingPrice = askingPrice;                        //done by Shashank
        }
        string[] usernameDB = { "shank1995", "kuenguan94", "helen" };   //done by Shashank & Kuen Guan
        string[] passwordDB = { "12345", "67890", "1762" };      //done by Shashank & Kuen Guan
        private void button1_Click(object sender, EventArgs e) //done by Shashank & Kuen Guan
        {
            string login = txtLogin.Text;                      //done by Shashank & Kuen Guan
            string password = txtPassword.Text;                //done by Shashank & Kuen Guan
            if (((password == "12345") && (login == "shank")) || ((password == "67890") && (login == "kuenguan")) || ((password == "1762") && (login == "helen"))) //done by Shashank & Kuen Guan
            {
                MessageBox.Show("Access Granted!");            //done by Shashank & Kuen Guan
                if (A == 1)
                {
                    A = 0;
                    new StaffManageCars().Show();
                }
                else if (A == 2)
                {
                    A = 0;
                    new StaffManageParking(vehicle_model, askingPrice).Show();//done by Shashank
                }
                Close();                                       //done by Shashank & Kuen Guan
            }
            else                                               //done by Shashank & Kuen Guan
            {
                MessageBox.Show("Username & password are invalid. Please retype correctly");//done by Shashank & Kuen Guan
            }
        }
    }
}

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)
        {
            // TODO: Complete member initialization
            this.vehicle_model = vehicle_model;                    //done by Shashank
            this.askingPrice = askingPrice;                        //done by Shashank

            InitializeComponent();
        }

        string [,] usedCars = new string [4,20];//done by Shashank
        private string[] vehicle_model;         //done by Shashank
        private float[] askingPrice;            //done by Shashank
        private void btnDisplay_Click(object sender, EventArgs e)                   //done by Shashank(done)
        {
            richTextBox1.Clear();                                                   //done by Shashank
            richTextBox1.AppendText("       \t");                                   //done by Shashank
            for (int col = 1; col <= usedCars.GetLength(1); col++)                  //done by Shashank
            {
                richTextBox1.AppendText(" Col " + col + " \t");                     //done by Shashank
            }
            richTextBox1.AppendText("\n");                                          //done by Shashank
            for (int row = 0; row < usedCars.GetLength(0); row++)                   //done by Shashank
            {
                richTextBox1.AppendText(" Row " + (row + 1) + ":\t");               //done by Shashank
                for (int col = 0; col < usedCars.GetLength(1); col++)               //done by Shashank
                {
                    richTextBox1.AppendText("[ " + usedCars[row, col] + " ]\t");    //done by Shashank
                }
                richTextBox1.AppendText("\n");                                      //done by Shashank
            }
        }

        private void btnDisplayCarLocation_Click(object sender, EventArgs e)      //done by Shashank(needs to be fixed)
        {
            int c = 0;

            string wantedCar = txtCarModel.Text;                                  //done by Shashank
            for (int row = 0; row < usedCars.GetLength(0); row++)                 //done by Shashank
            {
                for (int col = 0; col < usedCars.GetLength(1); col++)             //done by Shashank
                {
                    if (wantedCar == usedCars[row, col])                          //done by Shashank
                    {
                        richTextBox1.AppendText("Found: " + wantedCar.ToString() + " @ parking floor: " + (row + 1).ToString() + " & parking space: " + (col + 1).ToString());//done by Shashank
                        break;
                    }
                    else
                    {
                        c++;
                    }
                }
            }

            if (c != 0)
            {
                MessageBox.Show("The car is not found in the parking plan");//done by Shashank
            }       
        }

        private void btnAssignParking_Click(object sender, EventArgs e)//done by Shashank(done)
        {
            int floor = int.Parse(parkingFloor.Text);                  //done by Shashank
            int space = int.Parse(parkingSpace.Text);                  //done by Shashank
            usedCars[floor - 1, space - 1] = txtCarModel.Text;         //done by Shashank
            MessageBox.Show("Car: " + txtCarModel.Text + " is assigned parking lot number: " + floor + "." + space);
        }
        private void btnTotalValue_Click(object sender, EventArgs e)                                       //done by Shashank(needs to be fixed)
        {
            float total_sum = 0.0f;                                                                        //done by Shashank
            for (int i = 0; i < askingPrice.Length; i++)                                                   //done by Shashank
            {
                total_sum = total_sum + askingPrice[i];                                                     //done by Shashank
            }
            richTextBox1.AppendText("The total sum of all used cars are " + total_sum.ToString("c") + "\n");//done by Shashank
        }

        private void btnEmptyParking_Click(object sender, EventArgs e)//done by Shashank(done)
        {
            int floor = int.Parse(parkingFloor.Text);                 //done by Shashank
            int space = int.Parse(parkingSpace.Text);                 //done by Shashank
            string carModel = usedCars[floor - 1, space - 1];         //done by Shashank
            usedCars[floor - 1, space - 1] = "";                      //done by Shashank
            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]; //done by Shashank
        string[] vehicle_model = new string[80];           //done by Shashank
        int[] vehicle_yearMake = new int[80];              //done by Shashank
        float[] askingPrice = new float[80];               //done by Shashank
        float[] transactedPrice = new float[80];           //done by Shashank
        int index = 0;                                     //done by Shashank
        int found = 0;//for search & update                //done by Shashank
        private void btnUpdate_Click(object sender, EventArgs e)//done by Shashank(done)
        {
           

            vehicle_registrationNum[found] = txtVehicleRegistryNo.Text;  //done by Shashank
            vehicle_model[found] = txtVehicleModel.Text;                 //done by Shashank
            vehicle_yearMake[found] = int.Parse(txtYearVehicleMake.Text);//done by Shashank
            askingPrice[found] = float.Parse(txtAskingPrice.Text);       //done by Shashank
            transactedPrice[found] = float.Parse(txtTransactionPrice.Text);//done by Shashank
            simpleton.askPrice = askingPrice;
            simpleton.vehiModel = vehicle_model;

            MessageBox.Show("Data successfully updated for " + txtVehicleModel.Text + " with registration number: " + txtVehicleRegistryNo.Text);//done by Shashank
            rtbDisplay.AppendText("Updated Registration No.\t  Updated Model\t   Updated Year Make\t   Updated Asking Price\t   Updated Transaction Price\t \n");//done by Shashank
            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");//done by Shashank
        }

        private void btnClear_Click(object sender, EventArgs e)//done by Shashank(done)
        {
            txtVehicleRegistryNo.Clear();                      //done by Shashank
            txtVehicleModel.Clear();                           //done by Shashank
            txtYearVehicleMake.Clear();                        //done by Shashank
            txtAskingPrice.Clear();                            //done by Shashank
            txtTransactionPrice.Clear();                       //done by Shashank
            txtVehicleModel.Focus();                           //done by Shashank
            rtbTable.Clear();                                  //done by Shashank
            rtbDisplay.Clear();                                //done by Shashank
        }

        private void btnAdd_Click(object sender, EventArgs e)                //done by Shashank(done)
        {
              vehicle_model[index] = txtVehicleModel.Text;                   //done by Shashank
              vehicle_registrationNum[index] = txtVehicleRegistryNo.Text;    //done by Shashank
              vehicle_yearMake[index] = int.Parse(txtYearVehicleMake.Text);  //done by Shashank
              askingPrice[index] = float.Parse(txtAskingPrice.Text);         //done by Shashank
              transactedPrice[index] = float.Parse(txtTransactionPrice.Text);//done by Shashank
              index++;
              simpleton.askPrice = askingPrice;
              simpleton.vehiModel = vehicle_model;
              MessageBox.Show("Record Added Successfully \n");               //done by Shashank
        }

        private void btnList_Click(object sender, EventArgs e)//done by Shashank(done)
        {
            rtbTable.Clear();                                 //done by Shashank
            rtbTable.AppendText("Registration No.\t   Model\t    Year Make\t    Asking Price\t    Transaction Price\t \n");//done by Shashank
            //for-loop to display data in 1D array
            for (int i = 0; i < index; i++)                   //done by Shashank
            {
                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");//done by Shashank
            }
            rtbTable.AppendText("* * * END OF LIST * * *\n"); //done by Shashank
        }

        private void btnFindHighestTransactedPrice_Click(object sender, EventArgs e)                            //done by Shashank(done)
        {
            float highest_transactedPrice = transactedPrice[0];                                                 //done by Shashank
            int max_index = 0;                                                                                  //done by Shashank
            for (int i = 0; i < 80; i++)                                                                        //done by Shashank
            {
                if (highest_transactedPrice < transactedPrice[i])                                               //done by Shashank
                {
                    highest_transactedPrice = transactedPrice[i];                                               //done by Shashank
                    max_index = i;                                                                              //done by Shashank
                }
            }
            MessageBox.Show("The Highest Transacted Price is " + highest_transactedPrice.ToString("c") + "\n"); //done by Shashank
        }

        private void btnSearch_Click(object sender, EventArgs e)           //done by Shashank
        {
            int vehicleYearMake = int.Parse(txtYearVehicleMake.Text);      //done by Shashank
            string vehicleModel = txtVehicleModel.Text;                    //done by Shashank
            float transactionPrice = float.Parse(txtTransactionPrice.Text);//done by Shashank
            string vehicleRegNum = txtVehicleRegistryNo.Text;              //done by Shashank
            for (int i = 0; i < vehicle_model.GetLength(0); i++)           //done by Shashank
            {
                    if ((vehicleModel == vehicle_model[i]) && (vehicleYearMake == vehicle_yearMake[i]) && (transactionPrice == transactedPrice[i]) && (vehicleRegNum == vehicle_registrationNum[i]))//done by Shashank
                    {
                        MessageBox.Show("Found Vehicle Model : " + vehicle_model[i] + ",Made in year " + vehicle_yearMake[i] + ",Cost: " + transactedPrice[i].ToString("c") + ",Registration Number:" + vehicle_registrationNum[i]);//done by Shashank
                        break;                                      //done by Shashank
                    }
                    else                                            //done by Shashank
                    {
                        MessageBox.Show("Car Not Found!");          //done by Shashank`
                        break;
                    }
            }
        }

    }
}
Posted
Updated 8-Feb-13 13:10pm
v3
Comments
Sergey Alexandrovich Kryukov 7-Feb-13 22:32pm    
Why tracking activity of the users?
—SA
Salman Ali Shah 7-Feb-13 22:49pm    
Its a requirement of my project, my friend.
Sergey Alexandrovich Kryukov 7-Feb-13 22:59pm    
Some of the Nazi also said they had "requirements" from Hitler, who tool all responsibility but other participated in Resistance. I'm not joking. This is your choice, but I don't know why helping you.
—SA
Salman Ali Shah 7-Feb-13 23:02pm    
In the 1st place, I have never studied FULL history of Hitler before. So I really don't understand what you are talking. Can you please put in simple words?
Salman Ali Shah 7-Feb-13 23:25pm    
Its a minimum project requirement,not an additional feature from myself. At least please tell me whether this code really exists? If it is, then can you please code it for me?

1 solution

Create 4 columns in all your tables, could be named as:

Updation_Date datetime - set current date and time in it.
Updated_By integer - set user who is updating record.
Updated_IP varchar - set client IP from where record got updated.
Update_Details varchar - set Details what changes are made.

Then set these values for every database transaction.


Also, You can use triggers to record history for each transaction.
 
Share this answer
 
Comments
Salman Ali Shah 10-Feb-13 4:00am    
I ve never reached the advanced stage MR Sheikh & Mr Richard. Tell mea simple one.
[no name] 10-Feb-13 4:06am    
hmm ... its a simple option man. Anyways, what have to tried so far?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900