ASP.NET MVC small practice

Development tools and key technologies: VS backend

Author: Chen Chi Fan

Write time: 2019.5.1

Employees simply add basic information management data

Ideas: Data Query - Constructive Solid class receives - render method - Reset forms - the implementation of new - modifying data extraction - reset form - submit asynchronous data - delete - closed loading layer

Modal popup box:

First of all instances of the entity model, query data, get the number of rows to get the data show, flashbacks sorting, indexing beginning , acquiring several, data rendering method, query source:

public ActionResult SelectemployeeAll(LayuiTablePage layuiTablePage)

{

Gets the number of head office:

int EmployeeCount = (from tbemployee in Models.PW_Employee select tbemployee).Count();

Acquiring display data:

List<PW_Employee> employeeData =

(from tbEmployee in Models.PW_Employee

the OrderBy tbEmployee.employeeID Descending // Sort flashback                 

select tbEmployee)

 .Skip (layuiTablePage.GetStartIndex ()) // beginning index

 .Take (layuiTablePage.limit) .ToList (); // get the total number of

Entity classes have constructed receiving List

LayuiTableData<PW_Employee> layuiTableData = new LayuiTableData<PW_Employee>();

layuiTableData.count = EmployeeCount;

layuiTableData.data = employeeData;

return Json(layuiTableData, JsonRequestBehavior.AllowGet);}

Then add data manipulation:

First: the page is determined to transmit data empty,

Second: whether the data exists,

Third: the implementation of the new operation.

Controller source:

public ActionResult Insertemployee(PW_Employee sysemployee){

ReturnJson returnJson = new ReturnJson();

try{

if (!string.IsNullOrEmpty(sysemployee.employeeNum) && !string.IsNullOrEmpty(sysemployee.employeeName))

{

int oldCount = (from tbemployee in Models.PW_Employee

where tbemployee.employeeName == sysemployee.employeeName

|| tbemployee.employeeNum == sysemployee.employeeNum

select tbemployee).Count();

if (oldCount == 0){

Models.PW_Employee.Add(sysemployee);

Add operation: determining whether before repeating, if repeated, the returned data is abnormal;

There transmitted by determining whether data is empty, if the data transmission over the blank,

Data is returned abnormal.

if (Models.SaveChanges() > 0){

returnJson.State = true;

= returnJson.Text " Save successful!" ;}

else{

returnJson.State = false;

= returnJson.Text " save failed" ;}

}

else{

returnJson.State = false;

= returnJson.Text " and before repeating" ;}

}

else{

returnJson.State = false;

= returnJson.Text " data transmitted by the null" ;}

}

catch (Exception e){

Console.WriteLine(e);

returnJson.State = false;

= returnJson.Text " data error" ;}

return Json(returnJson, JsonRequestBehavior.AllowGet);}

The class name is consistent with the above id, or do not correspond, as well as upload path controller naming keep consistent, otherwise the wrong path, there will be mistakes. Construction mode form, reset form, the data is stored, the new data is also stored the database. Index Source:

Open new frame mode:

function openInsert() {

Reset the form:

$('#formEmployee input[type="reset"]').click();

Open frame mode:

$("#modalEmployee").modal('show');}

Save New

function savaInsert(){

Obtaining input data input

var employeeName = $("#employeeName").val();

var employeeNum = $("#employeeNum").val();//判断

if (employeeName != '' && employeeName != undefined

&& employeeNum != '' && employeeNum != undefined){

The need for new data to be acquired, acquisition path, the data will get assigned. Need to be verified, still need to be verified, such as:

Telephone number (telephone) need regular expressions to verify the phone number will appear unlikely characters, English letters and so on.

Verify that the phone number format: ? ^ (\ (\ D {3, 4} -) | \ d {3.4} -) \ d {7, 8} $.

$.post("/Main/Insertemployee", { employeeName: employeeName, employeeNum: employeeNum , telephone: telephone, address: address }, function (returnJson) {

IF (== returnJson.State to true ) { // Close the modal box                              $ ( "#modalEmployee" ) .modal ( 'hide' ); // table refreshed

employee = layuiTable.reload('employee');}

layer.alert(returnJson.Text);}, "json")}

the else { // Tips

layer.alert ( ' Please complete' , {title: ' prompt' , icon: 0});}

}

Conclusion: New First step: acquiring new data,

Step Two: Give entity assignment, the implementation of new,

The final step: Save new. Of course, modify and add different,

The first step modified: Check whether there is a conflict with other,

Step Two: To modify data extract,

The third step: Modify the assignment, last modified assignment.

Note: You need to verify the place, still need verification, such as: telephone number.      

Guess you like

Origin blog.csdn.net/qq_44554890/article/details/89735366