如何使用日期和时间跟踪用户的活动时间&救他们? [英] How to I track the activity of users using the date & time & save them?

查看:63
本文介绍了如何使用日期和时间跟踪用户的活动时间&救他们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作汽车市场项目。我想跟踪员工用户对StaffManageCars.cs以及StaffManageParking.cs所做的更改。

我想要的是:当我调试表单时,菜单出现。让我们说用户点击管理汽车,要求用户输入他的凭据以管理汽车(如添加,更新,显示等)。在用户使用StaffManageCars管理汽车之后,它应该跟踪&节省时间和时间活动的日期自动以另一种形式,我现在没有。它适用于管理停车场。

<罢工>你能否因为截止日期的原因,我可能会尽快进行编码下午6点(新加坡时间)?



以下是我的代码:

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;          //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;
                    }
            }
        }

    }
}

推荐答案

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.
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.


这篇关于如何使用日期和时间跟踪用户的活动时间&amp;救他们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆