New data


开发工具与关键技术:vs和jquery

作者:戴怡斌 

撰写时间:2019年5月2日

Let's look at a new example of the data, the data will be used to add a database, the new data will be stored in a database.

So when do the new database should be created in which a data or references to additional existing data
Here Insert Picture Description
after after opening the database, create a right to see the data after the database has this name, you've created, there will be a database, click on the map small point on the open, find the table with the new table name right on it, just the name, citing the additional not here to enumerate.

The official start of the new data. Creating more than that, in this model, which is the right to add Models, click New Item.

This time will pop up a window, find the data in this column, the corresponding data appears after clicking on the file,
Here Insert Picture Description
then double-click the ADO.NET Entity model point, then click the new connection, to find their own database, server name is the log in your own database name, then use SQL authentication, they have to fill in a username and password, click OK in, check in is after clicking Next, check the table, click Done it.

After creating a controller, views, view came here, to write css style, css references and writing style will js, you can write some code less

<link href="~/Plugins/bootstrap-4.1.3-dist/css/bootstrap.min.css" rel="stylesheet" />

<link href="~/Plugins/layui/css/layui.css" rel="stylesheet" />

<link href="~/Content/css/SetExaminee.css" rel="stylesheet" />

There js css style reference style finish

<script src="~/Plugins/jquery-3.2.1.min.js"></script>

<script src="~/Plugins/layui/layui.all.js"></script>

<script src="~/Plugins/bootstrap-4.1.3-dist/js/bootstrap.min.js"></script>

<script src="~/content/js/jquery.form.js"></script>

<script src="~/content/js/customfuntion.js"></script>

Define four variables used to render the table.

var tabGame;//layui的表格

var blInsert = true;//是否是新增操作

var layerIndex = 0;

var layer, layuiTable;//保存layui模块以便全局使用

Began to form after the expiry of rendering, rendering table will query data, query data necessary to use class selectors, there is not much to say, after you create, write queries.

var listGame = (from tb in
myModel.YX_GameSKL select tb).ToList();

This is another way to write, meaning is the same. Class query this table capacity assigned to listGame

listGame = listGame.OrderByDescending(m => m.GameID)

OrderByDescending: mean descending order, contrary OrderBy.

The meaning behind all return data, returns a list.

return Json(layuiTableData, JsonRequestBehavior.AllowGet);

This means that an acceptance of returned data, a data reception must be returned before they can.
Here Insert Picture Description
Because only a single-table queries, so there is no contingency tables, queries complete data table after rendering is complete, renderings.
Here Insert Picture Description
Picture upload is limited, you can only see part of the operation is the custom, then, to set custom property values.

Finally, he said the new, came to the view here, to write data to accept the return of a code.

In general, there will be added modal form, I, too, have to set the button to add a click event. There are open modal window will be closed, so it is to write a close button click event.

Close button easy for you to set up a close button click event, οnclick = "
layerClose", the name inside double quotes to keep you define a method name to be consistent, the Save button is the same.

function layerClose() {layer.close(layerIndex)};

layerIndex outset, defined the variables.

Images which have been written to explain here is not to explain.
Here Insert Picture Description
After opening the add-modal form, enter the data you want to enter, then that is the key, ring up, to test
the Save button, the controller have to go there to write you want to save new data to the database inside.
Here Insert Picture Description
Because there are regulations, so the picture is not too large, is writing new judge, judge name can not be the same, can not be empty ah, etc., according to their preferences on the line judge.

The final step is to determine a value greater than 0 to save the new success, and vice versa.

if (myModel.SaveChanges() > 0){};

And finally back side view, writing new method save button.

First define the variables get the value of a dollar sign inside,

var Type = $("#IGameType").val();

var Name = $("#IGameName").val();

var Crowd = $("#ISuitableCrowd").val();

var Time = $("#IPromulgateTime").val();

After you get to judge these four values ​​can not be an empty string, and then in the form of key-value pairs, modGame: this is my name written in the new control method.

if (Name != ""
&& Name != "" && Crowd != ""
&& Time != "") {$.get("modGame",{
GameType: Type, GameName: Name, SuitableCrowd: Crowd, PromulgateTime: Time},

function (data) {if
(data.State == true) {layer.alert(data.Text); $("#ModGameDY").modal('hide');
tabGame.reload();} });

$ ( "# ModGameDY") modal ( 'hide'):. Close modal form, tabGame.reload (): refresh the table means. If the data transfer back data is equal to true then added successfully,

Guess you like

Origin blog.csdn.net/weixin_44561520/article/details/89971403