Danh mục

Practical Database Programming With Visual C#.NET- P6

Số trang: 50      Loại file: pdf      Dung lượng: 831.61 KB      Lượt xem: 13      Lượt tải: 0    
tailieu_vip

Hỗ trợ phí lưu trữ khi tải xuống: 14,000 VND Tải xuống file đầy đủ (50 trang) 0
Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu practical database programming with visual c#.net- p6, công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Practical Database Programming With Visual C#.NET- P6 5.7 Bind Data to Associated Controls in LogIn Form 273this new object and select the pass_word column by clicking on it. The data binding isdone. Some readers may have noted that when we call the FillByUserNamePassWord()method, we fill the LogIn form with four columns; user_name, pass_word, faculty_id, andstudent_id from the LogIn table. In fact, we only fill two textbox controls on the form,txtUserName and txtPassWord, with two associated columns in the LogIn table, user_name and pass_word. We only need to know if we can find the matched username andpassword entered by the user from the LogIn table. If both matched items can be foundfrom the LogIn table, the login is successful and we can continue to the next step. Twobound controls on the form, txtUserName and txtPassWord, will be filled with the identi-cal values stored in the LogIn table. It looks like this does not make sense. In fact, wedo not want to retrieve any column from the LogIn table. Instead, we only want to findthe matched items of username and password from the LogIn table. If we can findmatched username and password, we do not care whether we fill the faculty_id andstudent_id or not. If no matched items can be found, this means that the login has failedand a warning message should be displayed. Before we can go ahead with our coding, one we need to point out the displayingstyle of the password in the textbox control txtPassWord. Generally, the password letterswill be represented by a sequence of stars (*) when users enter them as the project isrunning. To make this happen in our project, we need to set the PasswordChar propertyof the textbox control txtPassWord to a star (*). To check the matched username and password entered by the user from the data source, one can use Return a Single Value to Query Data for LogIn table. But here in order to simplify this check, we use the Fill() method to fill four columns in a mapped data table in the DataSet. Then we can check whether this Fill() is successful. If it is, the matched data items have been found. Otherwise no matched data items are found. Now it is the time for us to develop codes that are related to the objects we createdin the previous steps such as the BindingSource and TableAdapter to complete thedynamic query. The operation sequences of the LogIn form are as follows: 1. When the project runs, the user needs to enter the username and password to two textbox controls, txtUserName and txtPassWord. 2. Then the user will click on the LogIn button on the form to execute the LogIn button click method. 3. The LogIn button click method will first create some local variables or objects that will be used for the data query and a new object for the next form. 4. Then the method will call the FillByUserNamePassWord() method to fill the LogIn form. 5. If this Fill is successful, which means that the matched data items for username and pass- word have been found from the LogIn table, the next window form, SelectionForm, will be displayed for the next step. 6. Otherwise, a warning message is displayed.274 Chapter 5 Data Selection Query with Visual C#.NET As we discussed in Section 5.5.1, these new created design tools, cSE_DEPTDataSet,logInTableAdapter, and logInBindingSource, are not the classes but the instances ofdesign tools. Therefore we can directly use these instances to develop our code. Keepingthis in mind, now let’s begin to develop the codes for the LogIn form.5.8 DEVELOP CODES TO QUERY DATA USING FILL() METHODSelect the LogIn.cs from the Solution Explorer window and click on the View Designerbutton to open its graphical user interface. Double click on the LogIn button to open itsClick method. First, we need to create a local object selForm, which is an instance of theSelectionForm class and then enter the codes shown in Figure 5.38 into this method. Let’s take a closer look at this piece of code to see how it works. A. A new namespace is created by the Visual C#, and the name of this namespace is equal to the name of our project, SelectWizard. By using the namespace technology, it is much easier to distinguish the different variables, methods, delegates, and events that have the same name but are located at different spaces. B. This line indicates that our LogIn form class is derived from the system class Form. C. The constructor of our LogIn form class contains a built-in method, InitializeComponent(). This method is used to initialize all new created instances and variables in this form. Starting Visual C# 2008, this method is moved to the LogIn.Designer.cs file. SelectWizard.LogInForm cmdLogIn_Cl ...

Tài liệu được xem nhiều: