Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the ASP.NET MVC4+BootStrap fix button

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use the ASP.NET MVC4+BootStrap fix button". In the daily operation, I believe many people have doubts about how to use the ASP.NET MVC4+BootStrap fix button. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the ASP.NET MVC4+BootStrap fix button". Next, please follow the editor to study!

Fix button. Let's take a look at the js code

$("# btnfix") .click (function () {$.ajax ({url: "/ Home/SolrDataFix?pam=" + new Date () .toTimeString (), type: "POST", datatype: "Html", beforeSend: function () {$("# divfix") .show () }, complete: function () {$("# divfix") .hide ();}, success: function (data) {if (data.IsSuccess) {alert ("Fixed successfully!") } else {alert (data.ErrorMsg);}, error: function () {alert ("Fix failed!");}});})

After we complete the fix, we will get a data in json format, and we will pop up a prompt based on whether it is successful or not.

Next, let's look at the controller.

Public JsonResult SolrDataFix () {int suc = GRLCBiz.GetInstance (). FixSolrData (); if (suc = = 1) {return Json (new {IsSuccess = true}, JsonRequestBehavior.AllowGet);} return Json (new {IsSuccess = false, ErrorMsg = "Fix failed!"}, JsonRequestBehavior.AllowGet);}

Here, we mainly look at the logic of the Biz layer. In fact, I talked about multithreading when I talked about Compare before, so it is necessary to use multithreading when fix. However, this time we are going to use Task from .net4 or above. Look at the code.

Public int FixSolrData () {if (this.differenceUserEntityList = = null) return-1; this.movePosition = 0; int threadCount = 0; int totalCount = differenceUserEntityList.Count; threadCount = totalCount% ConstValues.CONN_ComparePerThread = 0? TotalCount / ConstValues.CONN_ComparePerThread: totalCount / ConstValues.CONN_ComparePerThread + 1; if (threadCount > ConstValues.CONN_FixThreadCount) {threadCount = ConstValues.CONN_FixThreadCount;} taskList = new List (); for (int I = 0; I

< threadCount; i++) { Task task = Task.Factory.StartNew(() =>

{return SolrDataFixByThread (I);}); taskList.Add (task);} Task.WaitAll (taskList.ToArray ()); foreach (var task in taskList) {if (task.Result =-1) return-1; break } return 1;}

Here is also to calculate the number of threads, and then we cycle to open Task, execute the task, what is the task, that is, the SolrDataFixByThread method. This code also waits for all threads to finish, and I loop through the results and find that if one of the threads fails, I return-1. OK, let's take a look at the SolrDataFixByThread method.

Private int SolrDataFixByThread (int threadIndex) {try {string [] copyUserDBIDList = null; while (this.movePosition

< this.differenceUserEntityList.Count) { lock (this.differenceUserEntityList) { List userIDList = differenceUserEntityList.Select(d =>

D.UserNo.Trim (). ToList (); if (this.movePosition > = this.differenceUserEntityList.Count) {break;} if (this.movePosition {userDBEntity.UserID = userDBEntity.UserID?? String.Empty; userDBEntity.UserName = userDBEntity.UserName? String.Empty; return new UserSolrEntity () {UserNo = userDBEntity.UserID, Age = userDBEntity.Age, IsMarried = userDBEntity.Married = = "1", Name = userDBEntity.UserName.Trim ()};} .ToList () Return SolrHelper.GetInstance () .AddEntityList (userSolrEntityList.ToList ();}

The first sentence, BuildUserIDXml, is as follows

Private string BuildUserIDXml (string [] userIDList) {XmlDocument xmlDocument = new XmlDocument (); XmlNode xmlRoot = xmlDocument.CreateElement ("UserIDList"); foreach (var userID in userIDList) {XmlElement xmlElement = xmlDocument.CreateElement ("UserID"); xmlElement.InnerText = userID; xmlRoot.AppendChild (xmlElement) } return xmlRoot.OuterXml;}

Construct a very simple data in xml format. Then we pass it into the method GetUserEntityListByIDs of the DAL layer

Public List GetUserEntityListByIDs (string userIDXml) {string sqlScript = string.Empty; try {sqlScript = DBScriptManager.GetScript (this.GetType (), "GetUserInfoByIDs"); SqlParameter [] sqlParameters = {new SqlParameter ("@ UserIDXml", SqlDbType.Xml)} SqlParameters [0] .value = userIDXml; DataSet ds = SqlHelper.ExecuteDataset (ConstValues.CON_DBConnection, CommandType.Text, sqlScript, sqlParameters); if (ds! = null & & ds.Tables.Count > 0) {return ds.Tables [0] .ToEntityList ();} return new List () } catch (Exception ex) {LogHelper.WriteExceptionLog (MethodBase.GetCurrentMethod (), ex); return null;}}

There is nothing to say. Note that this parameter is of type xml. In SqlServer, when we want to pass a batch of data for update, we often pass in an entity List for update, and we can pass SP in the way of xml for batch processing. OK, let's take a look at this script

WITH UserIDList AS (SELECT U.C.value (N' (text ()) [1]', 'CHAR (25)') AS UserID FROM @ UserIDXml.nodes (Numeric UserIDList / UserID') AS U (C)) SELECT A.UseNo, ISNULL (B.Namegamine') AS Name, ISNULL (B.AgeMagin0) AS Age, ISNULL (B.Temper) ') AS Married FROM Bonus.dbo. [User] A WITH (NOLOCK) INNER JOIN Bonus.dbo.UerInfo B WITH (NOLOCK) ON A.UseNo = B.UseNo WHERE EXISTS (SELECT TOP 1 1 FROM UserIDList C WHERE C.UserID = A.UseNo)

The first sentence parses the data into a temporary table UserIDList. Note that this temporary table can only be used in the following statements and can only be used once and then destroyed. Ok, through this script, we get the data to be synchronized to Solr and start to synchronize

After the synchronization is complete, let's take a look at the Solr data. Firefox in linux has no style.

Let's browse through windows.

After OK,Fix part of the data, the comparison looks like the following

At this point, the study on "how to use the ASP.NET MVC4+BootStrap fix button" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report