private void GetServerConfigInfo(object sender, EventArgs e) { string url = tb_uri.Text; if (string.IsNullOrEmpty(url) && string.IsNullOrWhiteSpace(url)) { MessageBox.Show("请输入【服务器地址】"); return; } string configId = tb_conf_id.Text; if (string.IsNullOrEmpty(configId) && string.IsNullOrWhiteSpace(configId)) { MessageBox.Show("请输入【配置Id】"); return; } string queryparam = "type=400&sid=" + configId; try { string res = Tools.HttpPostInfo(url + "wmdatas2", queryparam); if (!string.IsNullOrWhiteSpace(res)) { ResultInfo rInfo = JsonConvert.DeserializeObject <ResultInfo>(res); if (rInfo.Data != null) { string conf = rInfo.Data["conf"]; configM = JsonConvert.DeserializeObject <DBConfigM>(conf); string dbconf = configM.Dbconf; if (string.IsNullOrWhiteSpace(dbconf)) { MessageBox.Show("服务端没有数据库配置信息!"); return; } iniFile.IniWriteValue(ICL.DB_LAB, ICL.DB_DBLINK, configM.Dbconf); iniFile.IniWriteValue(ICL.SERV_LAB, ICL.SERV_SCONF, Tools.EncodeBase64("UTF-8", JsonConvert.SerializeObject(configM))); iniFile.IniWriteValue(ICL.SERV_LAB, ICL.SERV_URI, url); iniFile.IniWriteValue(ICL.SERV_LAB, ICL.SERV_SID, configId); CURR_URI = url; CURR_DBConf = configM.Dbconf; DBTools.DBLink = CURR_DBConf; bool bok = checkConfDB(); if (bok) { DBTools.insertOrUpDate(configM.Sid, configM.Bgtime); } checkBakDB(); checkLogDB(); tb_conf_id.Enabled = false; tb_uri.Enabled = false; } else { MessageBox.Show("没有获取到配置信息"); } } else { MessageBox.Show("没有获取到配置信息"); } } catch (Exception ex) { logger.Error(ex, "访问服务器失败"); MessageBox.Show(ex.Message); } }
private void UpLoadWeightData(object sender, ElapsedEventArgs e) { if (canRun) { canRun = false; try { string bgtime = DBTools.GetSearchBgTime(configM.Sid); DateTime d1 = DateTime.Now; int jgmin = -configM.Inter; d1 = d1.AddMinutes(jgmin); if (string.IsNullOrEmpty(bgtime)) { bgtime = configM.Bgtime; } string edtime = d1.ToString(ICL.DATE_FMT_L); //开始同步数据 SyncDataToBakTable(edtime); //同步数据结束 string s1 = string.Format(rsql, bgtime, edtime); string log = "{0}-->开始执行任务,查询区间{1}===={2}"; log = string.Format(log, Tools.Now(), bgtime, edtime); updateTabsLogs(log); logger.Info("任务开始执行:" + s1);//执行sql查询 List <JObject> list = null; try { list = DBTools.Query(s1); int size = 0; if (list != null && list.Count > 0) { List <DBParams> listup = new List <DBParams>(); foreach (JObject obj in list) { DBParams param = JsonConvert.DeserializeObject <DBParams>(obj.ToString()); if (!DBTools.checkRecordUped(param.Bdid)) { size++; if (string.IsNullOrEmpty(param.Sbid)) { param.Sbid = cURR_DBID; } if (string.IsNullOrEmpty(param.Scm)) { param.Scm = cURR_SCM; } if (string.IsNullOrEmpty(param.Sopr)) { param.Sopr = cURR_OPR; } listup.Add(param); } if (listup.Count >= 10) { string sup = JsonConvert.SerializeObject(listup); logger.Info("开始执行上传:" + sup); sup = Tools.EncodeBase64("UTF-8", sup); sup = Tools.EscapeExprSpecialWord(sup); Tools.HttpPostInfo(url + "wmdatas2", "type=210&json=" + sup); logger.Info("小组执行完成:" + sup); logger.Info("开始写小组日志:"); DBTools.WriteSysUpLog(listup); listup.Clear(); Thread.Sleep(5); } } if (listup.Count > 0) { string sup = JsonConvert.SerializeObject(listup); logger.Info("开始执行尾数上传:" + sup); sup = Tools.EncodeBase64("UTF-8", sup); sup = Tools.EscapeExprSpecialWord(sup); Tools.HttpPostInfo(url + "wmdatas2", "type=210&json=" + sup); logger.Info("尾数执行完成:" + sup); logger.Info("开始写尾数日志:"); DBTools.WriteSysUpLog(listup); listup.Clear(); } logger.Info(string.Format("本次执行完成,上传总条数【{0}】", size)); } else { logger.Info("没有查询到数据;"); } DBTools.insertOrUpDate(configM.Sid, edtime); updateTabsLogs(string.Format(Tools.Now() + "-->任务执行完成【{0}】", size)); } catch (Exception ex) { logger.Error("错误SQL:" + s1); logger.Error(ex, "执行查询出错"); updateTabsLogs(Tools.Now() + "-->任务执行报错:" + ex.Message); } } catch (Exception ex) { logger.Error(ex, "上传出错!"); } finally { canRun = true; } } }