//父节点与B系统有关的数量递归+1 private void sysABCountInc(string id) { if (sysAnodes.ContainsKey(id)) { SysABNode anode = sysAnodes[id]; anode.sysBCount += 1; sysABCountInc(anode.TopId); } }
private void readSysADb(object sender, DoWorkEventArgs e) { sysAnodes.Clear(); try { string sysADbName = e.Argument.ToString(); openDB(sysADbName); //查询总数量 int allcount = 0; cmd.CommandText = "select count(sysid) from tree_calc"; SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { allcount = reader.GetInt32(0); } reader.Close(); //开始查询所有数据 cmd.CommandText = "select sysid, topid from tree_calc"; SQLiteDataReader reader1 = cmd.ExecuteReader(); int count = 0, step = 0; while (reader1.Read()) { SysABNode node = new SysABNode() { SysId = reader1.GetString(0), TopId = reader1.GetString(1) }; sysAnodes.Add(node.SysId, node); if (100 * count / allcount > step) { step = 100 * count / allcount; bgworker.ReportProgress(step); } count++; } bgworker.ReportProgress(100, "第二步读取数据库数据完成!"); reader1.Close(); } catch (Exception ex) { bgworker.ReportProgress(0, "第二步出错:" + ex.Message + ex.StackTrace); hasError = true; } finally { conn.Close(); } }
//第三步,计算A与B系统的关系-------------------------------------------------------------- private void CalcA_B(object sender, DoWorkEventArgs e) { int step = 0; for (int i = 0; i < sysBids.Count; i++) { if (sysAnodes.ContainsKey(sysBids[i])) { SysABNode anode = sysAnodes[sysBids[i]]; anode.sysBId = 1; anode.sysBCount = 1; sysABCountInc(anode.TopId); } if (100 * i / sysBids.Count > step) { step = 100 * i / sysBids.Count; bgworker.ReportProgress(step); } } bgworker.ReportProgress(100, "第三步AB关系计算分析完成!"); }