這篇文章主要介紹“ASP.NET MVC4+BootStrap fix按鈕怎么使用”,在日常操作中,相信很多人在ASP.NET MVC4+BootStrap fix按鈕怎么使用問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”ASP.NET MVC4+BootStrap fix按鈕怎么使用”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
為桓臺(tái)等地區(qū)用戶(hù)提供了全套網(wǎng)頁(yè)設(shè)計(jì)制作服務(wù),及桓臺(tái)網(wǎng)站建設(shè)行業(yè)解決方案。主營(yíng)業(yè)務(wù)為成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè)、桓臺(tái)網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專(zhuān)業(yè)、用心的態(tài)度為用戶(hù)提供真誠(chéng)的服務(wù)。我們深信只要達(dá)到每一位用戶(hù)的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
fix按鈕。我們看一下js代碼
$("#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失敗!"); } }); });
我們fix完成之后會(huì)得到一個(gè)json格式的數(shù)據(jù),我們根據(jù)是否成功彈出提示。
接下來(lái)我們看看控制器
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); }
在這里,主要是看Biz層的邏輯。其實(shí)之前我講過(guò)Compare的時(shí)候用多線程,那么fix的時(shí)候也必然要使用多線程。不過(guò),這次我們要使用的是.net4以上版本中的Task,看代碼
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; }
這里也是先計(jì)算線程數(shù),然后我們循環(huán)開(kāi)啟Task,執(zhí)行任務(wù),任務(wù)是什么呢,就是SolrDataFixByThread方法。這段代碼也是等待所有線程結(jié)束以后,我去循環(huán)結(jié)果,發(fā)現(xiàn)如果有某一個(gè)線程執(zhí)行失敗,我就返回-1。OK,我們看一下SolrDataFixByThread這個(gè)方法。
private int SolrDataFixByThread(int threadIndex) { try { string[] copyUserDBIDList = null; while (this.movePosition < this.differenceUserEntityList.Count) { lock (this.differenceUserEntityList) { ListuserIDList = differenceUserEntityList.Select(d => d.UserNo.Trim()).ToList(); if (this.movePosition >= this.differenceUserEntityList.Count) { break; } if (this.movePosition <= this.userEntityList.Count - ConstValues.CONN_ComparePerThread) { copyUserDBIDList = new string[ConstValues.CONN_ComparePerThread]; userIDList.CopyTo(this.movePosition, copyUserDBIDList, 0, ConstValues.CONN_ComparePerThread); } else { copyUserDBIDList = new string[userEntityList.Count - this.movePosition]; userIDList.CopyTo(this.movePosition, copyUserDBIDList, 0, copyUserDBIDList.Length); } this.movePosition += ConstValues.CONN_ComparePerThread; } return this.SolrDataFixStart(copyUserDBIDList, threadIndex); } return 1; } catch (Exception ex) { LogHelper.WriteExceptionLog(MethodBase.GetCurrentMethod(), ex); return -1; } }
和Compare方法大同小異,在此就不多說(shuō)了。我們看SolrDataFixStart方法
private int SolrDataFixStart(string[] userIDList, int threadIndex) { string userIDXml = this.BuildUserIDXml(userIDList); ListuserDBEntityList = GRLCDAL.GetInstance().GetUserEntityListByIDs(userIDXml); List userSolrEntityList = userDBEntityList.Select((userDBEntity, userSolrEntity) => { 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()); }
第一句,BuildUserIDXml,如下
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; }
構(gòu)造了一個(gè)很簡(jiǎn)單的xml格式的數(shù)據(jù)。然后我們將它傳入DAL層的方法GetUserEntityListByIDs
public ListGetUserEntityListByIDs(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; } }
沒(méi)什么可說(shuō)的,大家注意,這里這個(gè)參數(shù)是xml類(lèi)型的,在SqlServer中,當(dāng)我們要傳遞一批數(shù)據(jù)進(jìn)行更新時(shí),往往是傳入一個(gè)實(shí)體List進(jìn)行更新,就可以采用xml的方式傳入SP,進(jìn)行批量處理。OK,我們看一下這個(gè)腳本
;WITH UserIDList AS ( SELECT U.C.value(N'(text())[1]','CHAR(25)') AS UserID FROM @UserIDXml.nodes(N'UserIDList/UserID') AS U(C) ) SELECT A.UseNo, ISNULL(B.Name,'') AS Name, ISNULL(B.Age,0) 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 )
第一句先解析出數(shù)據(jù)放入一個(gè)臨時(shí)表UserIDList,大家注意這個(gè)臨時(shí)表只能在緊跟著的后面的語(yǔ)句中使用,而且只能使用一次就銷(xiāo)毀了。ok,通過(guò)這個(gè)腳本,我們就拿到了要同步到Solr的數(shù)據(jù),開(kāi)始同步
同步完成之后,我們看一下Solr數(shù)據(jù),linux中的火狐瀏覽器沒(méi)有樣式
我們還是通過(guò)windows瀏覽
OK,Fix一部分?jǐn)?shù)據(jù)之后,對(duì)比變成下面的樣子
到此,關(guān)于“ASP.NET MVC4+BootStrap fix按鈕怎么使用”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!