I'm starting a new project which will need to allow edits on forms but to keep track of the original and who did what edits and where (p.s. I wouldn't be able to use any extra software other than visual studio 2010 and Microsoft SQL Server Management Studio so no point suggesting any addition software, this is purely a code or table design minded question) .
I'm a perfectionist and I know some possible routes to achieve this will prob change my overall project design but I'm not sure if the ideas I have on how to implement this are best so I like to hear others opinions on below ideas and your own ideas on the quickest most effective way to implement above problem.
Ideas:-
I'd set it up so that when they edit it would display all existing ranges of data from textboxs to radiobuttons and even some drop downs and the value which they had and then on submit it would copy the original record via the Id into a achieve table, create the new record and then delete the original from the main table.
I figure some way to add X amount of comments to any section of the form and each would have a timestamp and username from win auth recorded at the bottom.
Edit - My intention was to get a variety of solutions but I suppose once I'm able to start on the editing section of this project if the single solution given works then I'll mark that correct.
I'm not sure whether this is what you are looking for but I have the need to log all changes to data (for audit reasons) and the way I have implemented this is to create a new 'History' table in SQL Server that will store the record ID, username of person who changed it, whether they added/modified/deleted something and when this happened etc.
In the code to add/edit/delete things in my database I always call ObjectContext.SaveChanges (I use Entity Framework 4) so what I have implemented is an extension to this method that uses various parts of the ObjectStateManager to get the information required about the entity that has changed and inserts the details into the History table. You then just need to query this table in the database to display details of what has changed.
Related
I have a simple form with DataGridView thas uses DataSet's DataTables as a data source. I need to save data added, changed or deleted in the DataGridView to the database. However, there is a catch. I don't have all the database information hardcoded. Instead, user inputs it at the runtime. I was trying to use SqlCommandBuilder, but it looks like the database has to have an unique identifier in order for it to work. Is there any other way around? Or do i have to limit the user to use only databases with unique identifiers? And even then, do i have to write custom commands for insert/delete/update? Or standart methods will work?
I'm not completely sure where you are going with your application so I may be a little of base with some details below, but feel free to leave some comments and I'll try to restructure the answer if I'm off base.
First, if you are building an application of any size, consider using WPF rather than winforms. It provides significantly more power and flexibility and is recommended over winforms. If you do use WPF, then you should take a look at the MVVM pattern to track your data.
As far as the user choosing a database at runtime. Do you have a finite set of Databases that can be connected to? If so you can set the connection details behind the scenes and let the user select from a dropdown which connection they want to use.
For reading/writing to a database I would recommend using the Entity Framework.
I am developing an application that requires "some" customization by the enduser afecting the database design (beyond the parametrization).
Now a days this application supports to work with new columns for the existing tables or even new tables in runtime. But the enduser is not capable to alter the tables, and all the design work must be done using Microsoft SQL Server Magament Studio.
My question is: there is any kind of control (or tool) which implements this functionality? I would like to have it embeded in my application, but if it is a external tool wouldn't be so bad.
What I want to have is some tool that let the user define a repository of columns (name, type, size) for example:
CustomerCode, BIGINT, n/a
CustomerName, Varchar, 50
And then create or alter a table or view by adding these predefined columns. And underneath should execute the needed SQL script or maybe using SMO (SQL Management Objects).
Updated
Currently it's the application works with WinForms, but any WPF / ASP solution would be appreciated.
And referring to and enduser I mean a app administrator but not with programing skills.
Purpouse
The purpose is to be able to extend and customize the functionality from the own apllication without having to use SQL Server Managment Studio.
Imagine that you have an ERP, as a user you want to inform in your customers table something that the application was not orginally intended and even has no free fields for it, for example: GPS location, logo, CEO's photo...
Of course I can suggest to some advanced users to install SSMS Express, but that will give them too much freedom. I also think it is a IT tool. What I wanted is to develop the capability to modify the application from the own framework of the application.
If it can be done from the own application, some controls can be performed:
Check that a table field called X will be always defined with the same type,
Disable the capability to modify the non-customizable fields (application fields),
...
Alex, I think you should try to give the user the flexibility to add new information to the database without really change the design of the database.
You can take a look at EAV Model (entity-attribute-value). This give you the flexibilty to add any new attribute to customer without change the design of customer table (e.g.).
One good example is Magento, they did a great job with EAV (entity-attribute-value) but you must know that this design model will hit your performance a little (or a lot depends how you implement it).
It seems that this kind of control does not exists, so I will scratch it from 0.
#BrunoCosta's idea of using an EAV model to extend the standard application is a good practice. But I pretend to have a tool to modify the standard, and have a tool used for the final user and also for the developer. A pseudo SQL Server Studio + Visual Studio embedded in the a application.
Once I develop it, I will to post it in CodeProject.
I think that the control you are looking for may be a little too unique. However, I don't think it would be too difficult create this yourself using other controls/libraries.
I am just finishing up a similar WPF project.
I found that the DataGrid class worked well for representing a table. You can add/remove columns programmatically. Although you would be generating the SQL script yourself.
I am creating a website that will be used by an accounting dept. to track budget expenditures by different projects.
I am using SQL Server 2008 R2 for the database and ASP.net C# MVC 3 for the website.
What my boss has asked me to do is every time any user updates or creates a project, we need to log that change into a new table called Mapping_log. It should record the whole Mapping row being saved or created, and additionally the user and the datestamp. The notes field will now be mandatory, and the note should be saved to the Mapping_log.
Now when editing the PA, the Notes field will always be empty and below it, it should have a list of the older notes organized by date. I have been looking into maybe using Nlog and Log4net but I have not been able to find any good tutorials for a situation like mine. It seems that those modules are mostly used for error logging, which although important is not exactly what I am try to do at the moment.
I need some direction... does anyone have any advice or tutorials that I could use to learn how I can implement a process that will keep track of changes made to the data by users of the site.
Thanks for your help/advice!
You can consider two new features that SQL Server 2008 introduced: Change Tracking and Change Data Capture.
You could use that and avoid your custom Mapping_log table.
But if you need to apply a more complex -business- rule, perhaps it will better doing that in the application layer, rather than purely in the database.
Regards.
I would just create two triggers - one for the update, one for the insert.
These triggers would look something like this - assuming you also want to log the operation (insert vs. update) in your Mapping_Log table:
CREATE TRIGGER trg_Mapping_Insert
ON dbo.Mapping
AFTER INSERT
AS
INSERT INTO dbo.Mapping_Log(col1, col2, ..., colN, User, DateStamp, Operation)
SELECT
col1, col2, ..., colN, SUSER_NAME(), GETDATE(), 'INSERT'
FROM
Inserted
(your UPDATE trigger would be very similar - just replace "insert" by "update" wherever it appears)
This is done "behind the scenes" for you - once in place, you don't have to do anything anymore to have these operations "logged" to your Mapping_Log table.
I using visual studio 2010 and using Entity Framework, and SQL Server 2008 R2. I have after trigger on my table, and When Save one record in table, another column in other table changed.
Is it possible to change automatically changed record on my application.
There is an InsertOnSubmit event that fires as noted here, not sure that's going to help you..
but there are various event fired when saving / modifying entities, but you'd have to bring your "trigger" logic into the code side, and then probably intelligently handle various Entity Changes.. here's more here : How To Execute Business Logic When Saving Changes
and after taking a deeper look at the title of your question it seems that you're trying to get the data from the updated table.. and as the comment suggests.. anything outside the scope of the entity "context" is going to have to be "reloaded". Now if that "loading" code is handled in your "change event" handling, you could accomplish this.. so why not just put all of that logic in your code layer? make the updates to your 2 "entities" and then save them in one swoop..
Though, not the answer you are after, I think you should move the "trigger" logic from the database to the application code. That will solve your problem, AND allow you to write a unit test verifying that data is updated correctly.
I Search for this question and find below code to refresh data in EF :
MyModelEntities.Refresh(System.Data.Objects.RefreshMode.StoreWins, TbMyRecord);
I have some C# form application.I'm using some central data base which is developed on SQLServer2005.According to my application there are several user levels such as admin,reception,...
problem
There is a requirement that if someone has changed the database(eg: add new record/delete record) that will be noticed admin and higher level of user.
What will be the way that should I follow to achieve this task!
Thank in advance!
Audit trial could be the solution for your question. It basically means, for your data-table of concern, include the columns - 'modified_by', modified_date' in addition to 'created_by', 'created_date' columns. So whenever someone edits a record for the first time - 'modified_by' and 'modified_date' columns will be different from 'created_by' and 'created_date' columns.
And in your application, you can develop a screen (or email alert) which is accessible only for admin or higher level users, to display the modified records in reverse chronological order.
Note: The above audit trial method, only maintains the latest changes in database. If you want to maintain the history of edits, then you can establish the same by maintaining the audit trial information in a separate dedicated set of data-tables.