MVC C # JavaScript Ligerui Oracle to achieve user registration, login verification, landing _c# tutorials

Source: Internet
Author: User
Tags reflection log4net

first, log in to the database, create the table User00 in the database, and insert the data .

The fields of the table are:

Id (number), name (name), Grid (level), Score (integral), Password (password), age (Ages), Code (invitation code). (where number is AutoNumber)

Some of the commands are as follows:

SELECT * from User00; /* Query user00*/
INSERT INTO User00 values (' One ', ' excellent ', 10000, ' 123 ', 24);/* Insert a row of data */
update User00 set grid= ' excellent ' where id=001; /* Update existing data *
/DELETE from User00/* Delete all data in
table/S/alter tables USER00 rename code to code; * Change field name/
update User00 ET Code =null; /* Delete all data in a column/
ALTER TABLE User00 add age number;/* USER00 insert a column *
/ALTER TABLE User00 Modify age varchar2 (4); * Change a Field type *
/delete from User00 where Score is null;//delete all lines with null password * * *

Second, new MVC Project KAOHE00, add a controller home.

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Using Model;
Using Log4net;
Using System.Reflection;
Using Bll;
Namespace Kaohe00. Models
{public
class Homecontroller:controller
{////
database Database
private static bll.test00 test00 = new bll.test00 ("Data source=yww; User id=test00; password=test00; "); Connect database
//Get:/home/public
actionresult Index ()///Show action method for home page
{return
View ();
}
Public Jsonresult Showinfo ()//Send data from tables in the database to the foreground method
{
var list = test00. GetList (); Return
Json (new {Rows = list, total = list. Count}, Jsonrequestbehavior.allowget);
Public ActionResult Register ()//Registered action method
{return
View ();
}
}

Third, add a view for the home index, display the information of the homepage, and put the database table User00 data into the table in the home view.

1, Home View Code:

 @{viewbag.title = "Index";} <script src= "~/content/jquery/jquery-1.9.0.min.js" & gt;</script> <script src= "~/content/script/common.js" ></script> <script src= "~/content/ Ligerui/ligerui.all.js "></script> <link href=" ~/content/ligerui/skins/aqua/css/ligerui-all.css "rel="
Stylesheet "/>  
 

2. Home View Interface:

Four, realize the login function

1, add a login controller.

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Namespace Kaohe00. Controllers
{public
class Logincontroller:controller {////Get
:/login/
//Database
private static bll.test00 test00 = new bll.test00 ("Data source=yww; User id=test00; password=test00; "); Connection database public
actionresult Index ()
{return
View ();
}
Public Jsonresult logintest (string Id, String Password)//Logon authentication action method
{
var succ = test00. Logintest (Id, Password);
Return Json (New {Succ = SUCC});}}

2.1. Add a view for login's index

View Code:

@{viewbag.title = "Index";} <script src= "~/content/jquery/jquery-1.9.0.min.js" ></script> <script src= "~/content/script/common.js" ></script> <script src= "~/content/ligerui/ligerui.all.js" ></script > <link href= "~/content/ligerui/skins/aqua/css/ligerui-all.css" rel= "stylesheet"/>  

2.2, login view of the interface:

Five, the realization registration function

1. Add a Register controller register

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using SYSTEM.WEB.MVC;
Using Model;
Using Log4net;
Using System.Reflection;
Namespace Kaohe00. Controllers
{public
class Registercontroller:controller
{
//database
private static bll.test00 test00 = new bll.test00 ("Data source=yww; User id=test00; password=test00; ");
//Get:/register/public
actionresult Index ()
{return
View ();
}
Public Jsonresult Register (User00 user00)
{ 
var succ=test00. AddNew (user00) >0?1:0;
Return Json (New {Succ = Succ}, Jsonrequestbehavior.allowget);}}

2.1. Add a view for index of Register Controller register

@{viewbag.title = "Index";} <script src= "~/content/jquery/jquery-1.9.0.min.js" ></script> <script src= "~/content/script/common.js" ></script> <script src= "~/content/ligerui/ligerui.all.js" ></script > <link href= "~/content/ligerui/skins/aqua/css/ligerui-all.css" rel= "stylesheet"/> <script src= "Scripts" /jquery.validate.js "type=" Text/javascript "></script>  

2.2 Registering the view's interface


Establish model entity class for database table, establish a class file named User00.

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace Model
{
///<summary>
///</summary> public
class User00
{
public int Id {get; set;}
public string Name {get; set;}
public string Grid {get; set;}
public int Score {get; set;}
public string Password {get; set;}
public int Age {get; set;}
public int Code {get; set;}}}

Some code, such as the BLL namespace and class Test00, that appear earlier, refer to another library.

1. Catalogue

2, where the file Test00 code:

Using Blocks.data;
Using Blocks.Data.CustomType;
Using Blocks.Data.DbProviders.Oracle; Using Kaohe00.
mappings;
Using Model;
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text; Namespace Bll {public class Test00 {///<summary>///databases///</summary> private database Oracle = NULL; pub
Lic Test00 (String connectionString) {this.oracle = new Database (new Oracledbprovider (connectionString)); This.oracle.Mappings (typeof (User00mapping).
Assembly); The public list<user00> getlist ()///defines the GetList function, its function: To obtain a type is the User00 class list equivalent to the array {var list = this.oracle.select< User00> ().
ToList ();
return list;  public int AddNew (User00 user00) {return This.oracle.Insert (user00);} public bool Logintest (string id,string Password) function function: To determine whether the value of the foreground wear is in the database {//var search = this.oracle.select<user00> ();//var list = search. Where (t => t.id = = Int. 
Parse (Id)) && T.password = = Password; var search = this.oracle.select<user00> (). Where (t =>t.id = Int.
Parse (Id) && T.password = = Password); var list = search. ToList (); The list corresponds to an array of if (list).
Count > 0)//??!! {//var user = list.
A ();
return true;
else {return false;}} }
}

3, one of the kaohe00. Code for the User00Mapping.cs file in the mappings file:

Using Blocks.Data.Mapping;
Using Model;
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace Kaohe00. Mappings
{public
class user00mapping:classmap<user00>
{public
user00mapping () 
{
Map (t => t.id). AutoNumber ();
Map (t => t.name);}}

Eight, set the path: defaults:new {controller = "Login", action = "Index", id = urlparameter.optional}, make first execute Login.

Nine, view the effect:

1, click the password error after login:

Or

2, enter the correct number password, access to the Home Page view interface

3, click Register to enter the Register view interface

4, in the registration interface input content, registration failure and success of the situation:

Or

After registering successfully Click OK, go to Homepage View interface

You can see the newly added information in the Home View interface

All right, about MVC. C # JavaScript Ligerui Oracle to achieve user registration, login verification, landing content for everyone to introduce here, I hope to help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.