Retrieving from database - c#

I have a pre registering system with these tables:
StudentInfo
Courses
Departments
SystemAdmin
RegisteredCoursesCompletely
RegisteredCoursesIncomplete
After creating a login using a stored procedure I need to show the courses that are related to a particular dep id. I did it. After that I needed students to be able to choose every course and then add it to a table and this is where the problems began...
I have two kinds of buttons. One of them is Registered Completely it means user never can go back and changes the courses (I did it) but the second one is Registered Incompletely it means user can go back and see what he/she chose and then uncheck it or check something else.
---> I want to do this in this way if he/she go back I want to show them all courses that related to them with courses that they chose before I mean the checkbox that consisted of data that user checked in the first time. Also show courses that not have been checked yet. All of them in a one grid view.
Please help me. I do everything that my lecture needs but this part that i try to solve it is a little tricky. I used to session and then save the index of the grid view that user checked and then insert it to database but you know more than 20 units user can choose and how do it please explain it with complete code.

in Registered Incompletely scenario you need to save selected courses, user and flag with Registered Incompletely. Then any time same user logged in or go back you can load all the courses and mark the selected courses based on previous saved data. if user is Registered Completely then you can save Registered Completely flag and user details in the database.
Edit:
students and registration complete status need to saved on database, here you can have Boolean value for that. true for complete, false for incomplete. if you have several pages to select courses, then in each page when you move next, save current courses selection in the database. it can be used when you want.

Related

Inserting data from a asp.net web application to SQL Server

I am currently trying to create a project in ASP.NET to create a stock input web application for a cafe which allows users to input stock data from web. I want to know how to save data from browser to SQL Server.
Screenshot of my current table design / ERD
The Item table will hold all information about each item. Stock_Take_Item table will hold the quantity of each item for a stock take, and Stock_Take table will hold the date of the stock take.
I want to be able to present the user with three columns, One for item description (which will already contain the item descriptions in), the second column for Bar Quantity and able the user to input this value and the third Column for Storage Quantity and also allow the user to input this value.
Once a user has filled out the columns for the stock take, will then press a submit button which will trigger c# code to insert these values into the SQL Database.
I hope this isn't too long winded and someone can give me a good recommendation on how to do so. I fully understand my tables may be wrong, and am open to changing them.
This is not actually a question of the specific problem. you rather need to read a very basic tutorial of ASP.net application.
For your convenience, I suggest you to read This Basic Example which exactly does what you need and just the table name and field names differ. I suggest you read this up first and then come here for very specific questions.

ASP.NET 2.0 C# Admin page can decide which products are to be displayed?

My website that sells products one page is called dvd.aspx which, using a sproc, displays all the dvds in my database with the "type=dvd". I have some admin pages in an admin folder where i can add new product, edit existing products but i need to let the admin decide which items to display, would anyone have any advice on how to go about this, do i need to create a page in admin folder for this or maybe edit code behind dvd.aspx page?
Any kind of advice is welcome,
Thank you
Create new column in you table called somehing like "ToShow" and make it a bit type, edit your dvd.aspx to show items with type=dvd and ToShow=true.
Create admin page, add GridView with the option to change ToShow property. That way admin can select items to show.
Just a friendly advice,move to .net 4.0 and you can use some Object-relational mapper like Linq to Sql,NHibernate or Entity Framework, it would make your life a lot easier!
A flag on the product which indicates if it should be displayed. The admin can then adjust the flag to determine if it should be selected by your sproc.

How to store history answer data in sql database?

I have a system whereby it can set the open and close dates allowing user to go in and submit answer for survey. The system also wants to delete the most current records from the database.
Example:
Person A:
1st survey: submitted on JAN/2011
2nd survey: submitted on MAR/2012
3rd, 4th...
How can i make sure that data are stored securely and able to retrieve past records and still able to delete latest?
I am thinking of storing latest data on one database and the history data on another database where it could be permanent. But then if records continue to be submitted, will it affect the search if there are more and more data stored? Any suggestion please? Heard about sql08 auditing? does it work?
Why would you want to store them in separate databases, and why would the history be any different than the latest? Just store all their answers for all time.
For the most simple example, if it's a single table for a survey, just store their user id, a unique survey id, and the date that it was submitted. When you want to get the most recent, get the Top 1 sorted by the submit date in descending order.

Setting up user permissions for reading and writing document files in IIS7

I want to make a very simple CMS for my sites. So what I am thinking is this a user logs in and a list of their pages shows up. Now they change their ends and save it. My C# code would then write over the file/section.
So I don't think it would be to bad to do this however I am not sure about how it works with read and write premission and how to set it up.
Like I want the user to only be able to read and write to their files they own.
So if User A has Page1.html and Page2.html they can only read those files and write to those files they can touch User B's page3.html and Page4.html
So how would I setup this up?
Thanks
When you create your list of files, you will be reading that list from a database repository. Include in that code conditions that allow only those records for which the user has permission.
The most straightforward way to do this is to create a table with two columns: UserID and DocumentID. A presence of a record in the table indicates that the user has permission to that particular document. Add records to this table that give the user permissions to the appropriate documents.
Then, when you read the documents from the database, you can join this table to the documents table via the DocumentID, and filter the table by UserID. This will return only those records for which the user has permission. You can then use that set of records as the basis for the list of documents that you display to the user.
You could employ a cms the SharePoint way. You begin with a base file on the network. If a change to it is made then the page is stored in a database. each subsequent change is a db change and the application renders the last entry in the table for that page.
this does two things. first, you can see revisions and re-instate them. you can see a complete history of the page, who made the changes and when.
it also allows you to lock pages within the database and assign roles/users against the pages. you can then apply a decoration to the controller which checks rights and either renders the page or displays a access denied page and then log the attempted access to the page.
i know this sounds complex but can you foresee a time when after you've gone live with your cms that the client is going to want more from it? you need to implement a solution that's adaptable to needs.
if it's worth writing then it's worth writing well.

Rolling My Own ASP.NET Registration Wizard

I imagine this is a pretty hard question to answer without sitting down and looking at all the source code, but I figured I'd post it anyway and see if you all had any conceptual thoughts on a process we're using in my company.
The project I'm working on currently is a self-registration page for our end users. Previously, we used 3 separate ASP.NET wizard controls for each of our different registration processes. It was consistantly stated by our customers that the process was very confusing, and they never knew which of the three different processes they should be completing. So after being asked to compile the three apps into one, I quickly found that the registration wizard controls are not very extensible. The new process needed to be very dynamic, so the static, one path, wizards were not fulfilling the needs.
So in an attempt to make a more dynamic process, I rolled my own registration app that relies on session state to walk a user through registration. The way I have it set up currently is using binary flag values for possible steps in the registration. I then have a integer value in SessionState that I update after a user completes a step.
Example:
const int accountNumberStep = 1;
const int userPassStep = 2;
const int usernameReclaimStep = 4;
/* code snipped */
// Code at the end of step Username/Password selection
// at the end of Username/Password selection step, update session state to record that step was finished
SessionState("stepsCompleted") = (int)SessionState("stepsCompleted") | userPassStep;
/* code snipped */
// Code at the beginning of each step to verify previous step was completed
if (!((int)SessionState("stepsCompleted") & userPassStep == userPassStep))
{
RedirectToPreviousPage(previousStep:=userPassStep);
}
Another major piece of this (this is where the dynamic piece comes into play) is using a session variable to keep track of the type of registration they are going through. In other words, they might have three different types of registration they can go through:
Normal Registration
Account Update Registration
Obtain Disabled User Account Registration
The registration type the user is completing is determined as they progress through the registration. For example, after a user types in there account number, I determine that they are not a new user, so they will be either an update, or a re-enable. This path is stored in the registration type variable in session state.
The final major piece of the app tracks text box values, radio box selection, etc. This is all stored in the SessionState as well, so if at any point in the process, the user wishes to back up a step or two, they will not lose the previous values they entered. These values are also used in the final step of the registration process in which the customer is actually registered on the back end database.
As you can see, all of this is vary similar to what an ASP.NET wizard control does. With the exception of the registration type variable. This allows me to branch the registration into different paths at any given point in the process.
Anyway, sorry again if this is confusing. I'm mainly hoping someone will come by that has done something similar and might be able to give me some advice.
Thanks in advance for your help.
CJAM
The wizard control is based on the MultiView control, which basically provides a means of showing one (and only one) view at a time. The only difference is that you are required to control navigation manually with the MultiView, therefore allowing you non-linear progression through the steps.
With the MultiView, the values of all controls in all the views will be stored in the ViewState, so there is no need to store them in the Session. Buttons within each view can post back, and based on the values of other controls, you can show a specific view.
Check out the ASP.NET Quickstart on MultiView and View controls

Categories

Resources