private void downloadWork() { List <Node> nodes = RemoteWorker.getBookContent(law.lawId); int startIndex = law.downloadNodeCount.HasValue ? (int)law.downloadNodeCount + 1 : 1; for (int i = startIndex; i <= nodes.Count; i++) { if (bgw.CancellationPending) { //暂停时记录已下载的章节数量,用于下次登录程序后继续下载;记录下载进度,用于下次登录后显示进度 law.downloadNodeCount = i - 1; law.downloadPercent = (int)(Math.Round(((float)law.downloadNodeCount / (float)nodes.Count), 2) * 100); db.saveLaw(law); return; } else { bgw.ReportProgress(i); downLoadValue = (int)(Math.Round(((float)i / (float)nodes.Count), 2) * 100); RemoteWorker.getNodeDetail(nodes[i - 1].Id); } } bgw.ReportProgress(100); //下载完成后,改变law的islocal状态为1,并将下载进度设置为100 law.downloadPercent = 100; law.downloadNodeCount = nodes.Count; law.isLocal = "1"; db.saveLaw(law); //下载完成后,法规列表、阅读历史列表显示为“从本地库移除” ((LibraryList)parentForm).setLawStateText(typeof(LawListItem), law, "移除"); ((LibraryList)parentForm).setLawStateText(typeof(ViewHistoryListItem), law, "移除"); }
private void checkUserPreload() { User user = db.getUserById(Global.user.Id); if (user != null) { if (user.Preload != "1") { List <string> lawIds = RemoteWorker.getPreloadLaw();//获取预下载的法规id列表 lawIds = new List <string>() { }; //todo 预下载接口还未完成,可用后删除此行代码 foreach (string lawId in lawIds) { List <Node> nodes = RemoteWorker.getBookContent(lawId);//依次下载法规及内容,下载完成后,更新法规的下载状态 if (RemoteWorker.getNodeDetail(nodes.Select(n => n.Id).ToList(), downloadImage:true)) { Law law = db.getLawById(lawId); law.isLocal = "1"; law.downloadPercent = 100; law.downloadDate = DateTime.Now.ToString("yyyy-MM-dd"); law.downloadNodeCount = nodes.Count; db.saveLaw(law); } } Global.user.Preload = "1"; } } }
private void LawView_Load(object sender, EventArgs e) { //mh = new Utity.MouseHook(); //mh.SetHook(); //mh.MouseMoveEvent += Mh_MouseMoveEvent; //this.Text += "-"+law.title + " " + law.version; lbl_title.Text = law.title + " " + law.version; lbl_welcome.Text += Global.user.Xm; if (law != null) { //如果在线,且未下载到本地,则从远程获取章节信息,并入库 if (Global.online && "0" == law.isLocal) { List <Node> nodes = RemoteWorker.getBookContent(law.lawId); //获取法规整体章节结构 RemoteWorker.getNodeDetail(nodes.Select(n => n.Id).ToList()); //再获取每个章节的内容 } nodes = db.getNodeByLawId(law.lawId); //绑定关系 tags = NodeWorker.buildRelationFromNode(nodes); bindTagsToDGW(); //绑定树结构 string content = NodeWorker.buildFromNodeContext(NodeTree, nodes); //绑定法规内容 wb.DocumentText = content; SetAutoWrap(true); if (Global.online)// && string.IsNullOrEmpty(law.isLocal)) { //远程获取评论 RemoteWorker.getOpinionList(law.lawId); //加载评论 loadComment(); } //加载文档信息 lawInfo1.law = law; lawInfo1.parentForm = this.parentForm; lawInfo1.fillLawVersion(laws); lawInfo1.fillLawInfo(); lawInfo1.bindState = true; //写入阅读历史 ViewHistory history = new ViewHistory() { Id = law.lawId, LawID = law.lawId, UserID = Global.user.Id, ViewDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }; if (db.saveHistory(history)) { ((LibraryList)parentForm).addHistory(history); } } }
/// <summary> /// 刷新法规 /// </summary> /// <param name="laws"></param> /// <returns></returns> public bool refreshLaw(List <Law> laws, out int autoUpdateCount) { using (SqliteContext context = new SqliteContext()) { try { int updateLawCount = 0; foreach (Law law in laws.OrderBy(l => l.lawId)) { var currentLaw = context.Law.FirstOrDefault(l => l.lawId == law.lawId && l.userId == Global.user.Id); if (currentLaw == null)//如果没有就新增 { law.userId = Global.user.Id; //如果是更新版本的法规(且法规旧版本已下载至本地),将更新信息保存至自动更新历史记录表,同时自动下载新版本法规内容 var oldDownloadedLaw = context.Law.FirstOrDefault(l => l.lastversion == law.lastversion && l.isLocal == "1" && l.userId == Global.user.Id); if (oldDownloadedLaw != null) { List <Node> nodes = RemoteWorker.getBookContent(law.lawId); RemoteWorker.getNodeDetail(nodes.Select(n => n.Id).ToList()); law.isLocal = "1"; law.downloadPercent = 100; law.downloadNodeCount = nodes.Count; law.downloadDate = DateTime.Now.ToString("yyyy-MM-dd"); UpdateHistory updateHistory = new UpdateHistory(); updateHistory.LawId = law.lawId; updateHistory.LawTitle = law.title; updateHistory.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); updateHistory.UserId = Global.user.Id; updateHistory.Version = law.version; updateHistory.Id = Guid.NewGuid().ToString(); addUpdateHistory(updateHistory); updateLawCount++; } else { //如果是更新版本的法规(且法规旧版本未下载至本地),只更新法规列表界面的版本 var oldUndownloadLaw = context.Law.FirstOrDefault(l => l.lastversion == law.lastversion && l.userId == Global.user.Id); if (oldUndownloadLaw != null) { updateLawCount++; } } context.Law.Add(law); } else//如果有就更新基本信息,但不更新是否下载到本地、下载时间、下载进度、用户id等本地信息。 { currentLaw.name = law.name; currentLaw.buhao = law.buhao; currentLaw.digest = law.digest; currentLaw.effectiveDate = law.effectiveDate; currentLaw.expiryDate = law.expiryDate; currentLaw.keyword = law.keyword; currentLaw.lastversion = law.lastversion; currentLaw.linghao = law.linghao; currentLaw.siju = law.siju; currentLaw.status = law.status; currentLaw.title = law.title; currentLaw.userLabel = law.userLabel; currentLaw.version = law.version; currentLaw.weijie = law.weijie; currentLaw.xiudingling = law.xiudingling; currentLaw.yewu = law.yewu; currentLaw.yilai = law.yilai; currentLaw.zefa = law.zefa; } context.SaveChanges(); } //context.SaveChanges(); autoUpdateCount = updateLawCount; MessageBox.Show("新版法规自动更新完成,本次共更新了" + updateLawCount.ToString() + "个法规的新版本"); return(true); } catch (Exception ex) { autoUpdateCount = -1; return(false); } } }