There are many requirements for a project recently, one of which is to record operation logs on data records, and the logs must be analyzed.
As a result, I began to analyze this requirement:
1. Most of the other projects I previously worked on only need to be refined to who changed and when. it's almost done. however, what the guys asked for this time can be used to analyze the ins and outs of the data, that is, to record who, when, and content of the data. Who else has the time to change the content. Who deleted the record at what time.
2. I figured out three things to do from above: 1. Write logs at creation; 2. Write logs at every modification; 3. Write logs at deletion.
3. Therefore, we need to consider the relationship between the log table and the real table. Each entity table corresponds to a log table.
Three fields in the log table: xgr -- modifier xgsj -- modification time xglx -- modify the type (which can be "insert, update, delete "), in addition, BH cannot be identified (the BH in the object table must be identified ).
4. Implement the SQL statements for these three tasks. The structure of the data table is as follows:
SQL statement for data source Configuration:
Select:
Select * From scd_sgryyfb
Update:
Insert into scd_sgryyfb_xgjl ([Zah], [RQ], [RS], [BH], [BS], ryfl, xgr, xgsj, xglx)
Values (@ Zah, @ RQ, @ Rs, @ BH, @ BS, @ ryfl, @ xgr, getdate (), 'update ')
Update [scd_sgryyfb] Set [Zah] = @ Zah, RQ = @ RQ, RS = @ Rs, BS = @ BS, ryfl = @ ryfl where bH = @ BH
Insert:
Insert into scd_sgryyfb ([Zah], [RQ], [RS], [BS], ryfl)
Values (@ Zah, @ RQ, @ Rs, 1, @ ryfl)
Declare @ varbh int
Select @ varbh = @ identity
Insert into scd_sgryyfb_xgjl ([Zah], [RQ], [RS], [BH], [BS], ryfl, xgr, xgsj, xglx)
Values (@ Zah, @ RQ, @ Rs, @ varbh, 1, @ ryfl, @ xgr, getdate (), 'insert ')
Delete:
Insert into scd_sgryyfb_xgjl ([Zah], [RQ], [RS], [BH], [BS], ryfl, xgr, xgsj, xglx)
Values (@ Zah, @ RQ, @ Rs, @ BH, @ BS, ryfl, @ xgr, getdate (), 'delete ')
Delete from scd_sgryyfb where bH = @ BH
@ Xgr assignment:
Protected void sqldatasource1_inserting (Object sender, sqldatasourcecommandeventargs E)
{
E. Command. Parameters ["@ xgr"]. value = user. Identity. Name; // This statement must be customized by yourself. the ID of the login user of the current system must be used.
}
Protected void sqldatasource1_deleting (Object sender, sqldatasourcecommandeventargs E)
{
E. Command. Parameters ["@ xgr"]. value = user. Identity. Name; // This statement must be customized by yourself. the ID of the login user of the current system must be used.
}
Protected void sqldatasource1_updating (Object sender, sqldatasourcecommandeventargs E)
{
E. Command. Parameters ["@ xgr"]. value = user. Identity. Name; // This statement must be customized by yourself. the ID of the login user of the current system must be used.
}