private void stationQueryBtn_Click(object sender, EventArgs e) { try { string cityCodeFilter = "*"; if (cityComboBox.SelectedItem != null) { Area areaCityObj = (Area)(cityComboBox.SelectedItem); cityCodeFilter = areaCityObj.AreaCode; } if (cityCodeFilter == "*" || String.IsNullOrEmpty(cityCodeFilter)) { if (proviceComboBox.SelectedItem != null) { Area areaProviceObj = (Area)(proviceComboBox.SelectedItem); cityCodeFilter = areaProviceObj.AreaCode.Substring(0, 2); } } DataTable dt = asr.AirStationInfoQuery(cityCodeFilter); if (dt != null) { dataGridView1.DataSource = dt; } } catch (Exception ex) { load_lb.Visible = false; //日志处理 Loghelper.WriteErrorLog("查询空气质量站点数据失败", ex); lr.AddLogInfo(ex.ToString(), "查询空气质量站点数据失败", "", "Error"); //throw e; } }
private void FrDataConfig_Load(object sender, EventArgs e) { try { DataTable proviceTable = ar.AreaInfoQuery("*", "1"); Area areaDefail = new Area(); areaDefail.AreaCode = "*"; areaDefail.AreaName = "请选择"; proviceComboBox.Items.Add(areaDefail); if (proviceTable != null && proviceTable.Rows.Count > 0) { List <Dictionary <string, string> > list = Utility.DataTableToList(proviceTable); for (int i = 0; i < list.Count; i++) { Area area = Utility.ParseDictionaryToModel <Area>(list[i]); proviceComboBox.Items.Add(area); proviceComboBox.DisplayMember = "AreaName"; } } stationQueryBtn_Click(null, null); } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("初始化空气质量站点页面失败", ex); lr.AddLogInfo(ex.ToString(), "初始化空气质量站点页面失败", "", "Error"); //throw e; } }
/// <summary> /// 查询数据表中最新数据时间 /// </summary> /// <returns></returns> public bool IsCompeletCollect(string tableName, string stationCode, DateTime monitorTime) { bool result = false; try { this.dbHelper = new DBHelper(tempSQLCoonectStr); StringBuilder sb = new StringBuilder(); sb.AppendFormat("select * from {0} where 1=1 and SITE_CODE = '{1}' and MONITOR_TIME = '{2}' ", tableName, stationCode, monitorTime.ToString("yyyy-MM-dd HH:mm:ss.fff")); string sql = SQLUtils.genarateSQL(sb.ToString(), this.dbHelper.sqlConnectionType); DataSet datasetTemp = dbHelper.DataAdapter(CommandType.Text, sql); if (datasetTemp != null) { DataTable dt = datasetTemp.Tables[0]; if (dt != null && dt.Rows.Count > 0) { result = true; } } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("查询数据表中最新数据时间失败", e); lr.AddLogInfo(e.ToString(), "查询数据表中最新数据时间失败", tableName, "Error"); //throw e; } return(result); }
/// <summary> /// /// </summary> /// <param name="areaCode"></param> /// <param name="csId"></param> /// <param name="dt"></param> /// <returns></returns> public static List <JObject> DataTableConvertList(string areaCode, string csId, DataTable dt) { List <JObject> list = new List <JObject>(); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { try { JObject item = new JObject(); item["DataID"] = dr["DID"].ToString(); item["AreaCode"] = areaCode; item["CsId"] = csId; item["DeviceInnerID"] = dr["SID"].ToString(); item["DacTime"] = Convert.ToDateTime(dr["DataTime"]); item["V1"] = (dr["R1"] == null ? null : dr["R1"].ToString()); item["V2"] = (dr["R2"] == null ? null : dr["R2"].ToString()); list.Add(item); } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("基康应力应变数据转换失败", e); lr.AddLogInfo(e.ToString(), areaCode, "基康应力应变数据转换失败", "Error"); //throw e; } } } return(list); }
/// <summary> /// 查询空气质量站点对应区域数据 /// </summary> /// <param name="cityCode"></param> /// <returns></returns> public DataTable AirAreaInfoQuery(string cityCode = "*") { DataTable dt = new DataTable(); string cityCodeFilter = ""; if (!string.IsNullOrEmpty(cityCode) && cityCode != "*") { cityCodeFilter = " and \"CityCode\" like '" + cityCode + "%'"; } try { StringBuilder sb = new StringBuilder(); sb.AppendFormat("select distinct(CityCode),Area from \"t_air_station\" where 1=1 {0} " + " order by \"CityCode\" asc", cityCodeFilter); SQLiteConnection conn = SQLiteHelper.GetConnection(dataBaseName); DataSet datasetTemp = SQLiteHelper.ExecuteDataSet(conn, sb.ToString(), null); if (datasetTemp != null) { dt = datasetTemp.Tables[0]; } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("查询空气质量站点对应区域数据失败", e); lr.AddLogInfo(e.ToString(), "查询空气质量站点对应区域数据失败", "t_area", "Error"); //throw e; } return(dt); }
private void proviceComboBox_SelectedIndexChanged(object sender, EventArgs e) { try { cityComboBox.Items.Clear(); Area areaDefail = new Area(); areaDefail.AreaCode = "*"; areaDefail.AreaName = "请选择"; cityComboBox.Items.Add(areaDefail); if (proviceComboBox.SelectedItem != null) { Area areaObj = (Area)(proviceComboBox.SelectedItem); DataTable cityTable = ar.AreaInfoQuery(areaObj.AreaCode.Substring(0, 2), "2"); if (cityTable != null && cityTable.Rows.Count > 0) { List <Dictionary <string, string> > list = Utility.DataTableToList(cityTable); for (int i = 0; i < list.Count; i++) { Area area = Utility.ParseDictionaryToModel <Area>(list[i]); cityComboBox.Items.Add(area); cityComboBox.DisplayMember = "AreaName"; } } } } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("查询级联城市失败", ex); lr.AddLogInfo(ex.ToString(), "查询级联城市失败", "", "Error"); //throw e; } }
/// <summary> /// 删除配置信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public bool DeleteDataConfigInfo(string id) { bool result = false; try { StringBuilder sb = new StringBuilder(); sb.AppendFormat("delete from \"t_data_config\" where 1=1 and Id ={0}", id); SQLiteConnection conn = SQLiteHelper.GetConnection(dataBaseName); int count = SQLiteHelper.ExecuteNonQuery(conn, sb.ToString(), null); if (count > 0) { result = true; } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("删除配置信息失败", e); lr.AddLogInfo(e.ToString(), "删除配置信息失败", "t_data_config", "Error"); //throw e; } return(result); }
//设置菜单对应内容面板显示 private void setTabContentShow(Form form) { try { if (groupBoxRightMenu.Controls != null) { for (int i = 0; i < groupBoxRightMenu.Controls.Count; i++) { if (groupBoxRightMenu.Controls[i] == form) { groupBoxRightMenu.Controls[i].Show(); } else { groupBoxRightMenu.Controls[i].Hide(); } } } } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
/// <summary> /// 删除空气质量站点数据 /// </summary> /// <returns></returns> public bool DeleteAirStationInfo() { bool result = false; try { StringBuilder sb = new StringBuilder(); sb.AppendFormat("delete from \"t_air_station\" where 1=1 "); SQLiteConnection conn = SQLiteHelper.GetConnection(dataBaseName); int count = SQLiteHelper.ExecuteNonQuery(conn, sb.ToString(), null); if (count > 0) { result = true; } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("删除空气质量站点数据失败", e); lr.AddLogInfo(e.ToString(), "删除空气质量站点数据失败", "t_air_station", "Error"); //throw e; } return(result); }
/// <summary> /// 查询日志信息 /// </summary> /// <param name="startTimeStr"></param> /// <param name="endTimeStr"></param> /// <returns></returns> public DataTable LogInfoQuery(string startTimeStr = "*", string endTimeStr = "*") { DataTable dt = new DataTable(); try { StringBuilder sb = new StringBuilder(); sb.AppendFormat("select * from \"t_log_info\" where 1=1 and CreateTime between '{0}' and '{1}' " + " order by \"CreateTime\" desc", DateTime.Parse(startTimeStr).ToString("yyyy-MM-dd 00:00:00.000"), Convert.ToDateTime(endTimeStr).ToString("yyyy-MM-dd 23:59:59.999")); SQLiteConnection conn = SQLiteHelper.GetConnection(dataBaseName); DataSet datasetTemp = SQLiteHelper.ExecuteDataSet(conn, sb.ToString(), null); if (datasetTemp != null) { dt = datasetTemp.Tables[0]; } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("查询日志信息失败", e); //throw e; } return(dt); }
/// <summary> /// 查询配置信息 /// </summary> /// <param name="areaCode"></param> /// <param name="csCode"></param> /// <returns></returns> public ConnectionStringSettings ConnnectConfigQuery(string areaCode, string csCode) { ConnectionStringSettings conn = null; try { DataTable dt = DataConfigInfoQuery(areaCode, csCode); if (dt != null && dt.Rows.Count > 0) { string bzkSQLServerDbServerIP = dt.Rows[0]["DBIPAddress"].ToString(); string bzkSQLServerDbServerPort = dt.Rows[0]["DBPort"].ToString(); string bzkSQLServerDbServerUserId = dt.Rows[0]["DBUserName"].ToString(); string bzkSQLServerDbServerUserPassword = dt.Rows[0]["DBPassword"].ToString(); string bzkSQLServerProviderName = dt.Rows[0]["DBType"].ToString(); string bzkSQLServerDbName = dt.Rows[0]["DBName"].ToString(); DBHelper dbHelper = new DBHelper(); //conn = dbHelper.GetCustomSQLServerConnection(bzkSQLServerDbServerIP, bzkSQLServerDbServerPort, bzkSQLServerDbServerUserId, bzkSQLServerDbServerUserPassword, bzkSQLServerProviderName, bzkSQLServerDbName); } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("查询配置信息失败", e); //throw e; } return(conn); }
public Fr_Main() { InitializeComponent(); try { Form[] forms = { frDataSourceConfig, frDataConfig, frDataCollect, frLookLog, frAboutAs }; for (int i = 0; i < forms.Length; i++) { forms[i].TopLevel = false; forms[i].Dock = DockStyle.Fill;//把子窗体设置为控件 forms[i].Hide(); forms[i].FormBorderStyle = FormBorderStyle.None; groupBoxRightMenu.Controls.Add(forms[i]); } dataSourceConfigBtn_Click(null, null); } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
//切换菜单时修改菜单样式 private void setMenuStyle(string selectedBtnName) { try { switch (selectedBtnName) { case "dataSourceConfigBtn": dataSourceConfigBtn.BackColor = Color.FromArgb(191, 205, 219); dataConfigBtn.BackColor = Color.FromArgb(240, 240, 240); dataCollectBtn.BackColor = Color.FromArgb(240, 240, 240); lookLogBtn.BackColor = Color.FromArgb(240, 240, 240); aboutUsBtn.BackColor = Color.FromArgb(240, 240, 240); break; case "dataConfigBtn": dataSourceConfigBtn.BackColor = Color.FromArgb(240, 240, 240); dataConfigBtn.BackColor = Color.FromArgb(191, 205, 219); dataCollectBtn.BackColor = Color.FromArgb(240, 240, 240); lookLogBtn.BackColor = Color.FromArgb(240, 240, 240); aboutUsBtn.BackColor = Color.FromArgb(240, 240, 240); break; case "dataCollectBtn": dataSourceConfigBtn.BackColor = Color.FromArgb(240, 240, 240); dataCollectBtn.BackColor = Color.FromArgb(191, 205, 219); dataConfigBtn.BackColor = Color.FromArgb(240, 240, 240); lookLogBtn.BackColor = Color.FromArgb(240, 240, 240); aboutUsBtn.BackColor = Color.FromArgb(240, 240, 240); break; case "lookLogBtn": dataSourceConfigBtn.BackColor = Color.FromArgb(240, 240, 240); lookLogBtn.BackColor = Color.FromArgb(191, 205, 219); dataConfigBtn.BackColor = Color.FromArgb(240, 240, 240); dataCollectBtn.BackColor = Color.FromArgb(240, 240, 240); aboutUsBtn.BackColor = Color.FromArgb(240, 240, 240); break; case "aboutUsBtn": dataSourceConfigBtn.BackColor = Color.FromArgb(240, 240, 240); aboutUsBtn.BackColor = Color.FromArgb(191, 205, 219); dataConfigBtn.BackColor = Color.FromArgb(240, 240, 240); dataCollectBtn.BackColor = Color.FromArgb(240, 240, 240); lookLogBtn.BackColor = Color.FromArgb(240, 240, 240); break; } } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
//计时器 private void timer1_Tick(object sender, EventArgs e) { try { toolStripStatusLabel1.Text = "当前系统时间:" + System.DateTime.Now.ToString(); } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
private void Fr_Main_Load(object sender, EventArgs e) { try { timer1.Start(); } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
private void airStationLoadBtn_Click(object sender, EventArgs e) { try { airStationLoadTask(); } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("同步空气质量站点数据失败", ex); lr.AddLogInfo(ex.ToString(), "同步空气质量站点数据失败", "提示", "Error"); //throw e; } }
//切换到同步基础 private void dataConfigBtn_Click(object sender, EventArgs e) { try { setMenuStyle("dataConfigBtn"); setTabContentShow(frDataConfig); } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
private void cancleDataConfigBtn_Click(object sender, EventArgs e) { try { this.Dispose(); this.Close(); } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
/// <summary> /// 查询统计信息 /// </summary> /// <returns></returns> public JObject GetCollectInfo() { string startTimeStr = DateTime.Now.ToString("yyyy-MM-dd 00:00:00.000"); string endTimeStr = DateTime.Now.ToString("yyyy-MM-dd 23:59:59.999"); JObject objItem = new JObject(); objItem["allTotal"] = 0; objItem["todayTotal"] = 0; objItem["lastTime"] = '-'; try { StringBuilder sb = new StringBuilder(); sb.AppendFormat("select * from ( " + "(select sum(CollectTotal) as allTotal,max(CollectTime) as lastTime from t_collect_static) a " + "left join " + "(select sum(CollectTotal) as todayTotal from t_collect_static where CollectTime between '{0}' and '{1}') b " + "on 1 = 1 " + ")" , startTimeStr, endTimeStr); SQLiteConnection conn = SQLiteHelper.GetConnection(dataBaseName); DataSet datasetTemp = SQLiteHelper.ExecuteDataSet(conn, sb.ToString(), null); if (datasetTemp != null) { DataTable dt = datasetTemp.Tables[0]; if (dt != null && dt.Rows.Count > 0) { objItem["allTotal"] = (string.IsNullOrEmpty(dt.Rows[0]["allTotal"].ToString()) ? "0" : dt.Rows[0]["allTotal"].ToString()); objItem["todayTotal"] = (string.IsNullOrEmpty(dt.Rows[0]["todayTotal"].ToString()) ? "0" : dt.Rows[0]["todayTotal"].ToString()); objItem["lastTime"] = (dt.Rows[0]["lastTime"] == null || string.IsNullOrEmpty(dt.Rows[0]["lastTime"].ToString()) ? "-" : Convert.ToDateTime(dt.Rows[0]["lastTime"]).ToString("yyyy-MM-dd HH:mm:ss.fff")); } } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("查询统计信息失败", e); lr.AddLogInfo(e.ToString(), "查询统计信息失败", "t_collect_static", "Error"); //throw e; } return(objItem); }
/// <summary> /// 查询配置信息 /// </summary> /// <param name="dbIP"></param> /// <param name="dbPort"></param> /// <returns></returns> public DataTable DataConfigInfoQuery(string dbIP = "*", string dbPort = "*", string dbType = "*") { DataTable dt = new DataTable(); string dbIPFilter = ""; if (!string.IsNullOrEmpty(dbIP) && dbIP != "*") { dbIPFilter = " and \"DBIPAddress\" in(" + Utility.ConvertFieldValue(dbIP) + ")"; } string dbPortFilter = ""; if (!string.IsNullOrEmpty(dbPort) && dbPort != "*") { dbPortFilter = " and \"DBPort\" in(" + Utility.ConvertFieldValue(dbPort) + ")"; } string dbTypeFilter = ""; if (!string.IsNullOrEmpty(dbType) && dbType != "*") { dbTypeFilter = " and \"DBType\" in(" + Utility.ConvertFieldValue(dbType) + ")"; } try { StringBuilder sb = new StringBuilder(); sb.AppendFormat("select * from \"t_data_config\" where 1=1 {0} {1} {2}" + " order by \"CreateTime\" desc", dbIPFilter, dbPortFilter, dbTypeFilter); SQLiteConnection conn = SQLiteHelper.GetConnection(dataBaseName); DataSet datasetTemp = SQLiteHelper.ExecuteDataSet(conn, sb.ToString(), null); if (datasetTemp != null) { dt = datasetTemp.Tables[0]; } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("查询配置信息失败", e); lr.AddLogInfo(e.ToString(), "查询配置信息失败", "t_data_config", "Error"); //throw e; } return(dt); }
private void 显示ToolStripMenuItem_Click(object sender, EventArgs e) { try { //还原窗体显示 WindowState = FormWindowState.Normal; //激活窗体并给予它焦点 this.Activate(); //任务栏区显示图标 this.ShowInTaskbar = true; //托盘区图标隐藏 notifyIcon1.Visible = false; } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
private void Fr_Main_FormClosing(object sender, FormClosingEventArgs e) { try { if (this.WindowState != FormWindowState.Minimized) { e.Cancel = true;//不关闭程序 //最小化到托盘的时候显示图标提示信息,提示用户并未关闭程序 this.WindowState = FormWindowState.Minimized; notifyIcon1.ShowBalloonTip(2000, "", "最小到托盘", ToolTipIcon.None); } } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
private void Fr_Main_SizeChanged(object sender, EventArgs e) { try { // 判断是否选择的是最小化按钮 if (WindowState == FormWindowState.Minimized) { //隐藏任务栏区图标 this.ShowInTaskbar = false; //图标显示在托盘区 notifyIcon1.Visible = true; } } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
private void FrDataConfigAdd_Load(object sender, EventArgs e) { try { Dictionary <string, string> dir = DBType.GetDBTypes(); foreach (var item in dir) { DataBaseType dataBaseType = new DataBaseType(); dataBaseType.dataBaseName = item.Key; dataBaseType.dataBsseValue = item.Value; dBTypeComboBox.Items.Add(dataBaseType); dBTypeComboBox.DisplayMember = "dataBaseName"; } } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
/// <summary> /// 执行 /// </summary> /// <param name="context"></param> public void Execute(IJobExecutionContext context) { Task.Run(() => { try { JobDataMap dataMap = context.JobDetail.JobDataMap; string key = dataMap.GetString("key");//获取参数 //1.绑定需要执行的操作方法 //var act = new Action(FrDataCollect.frDataCollect.collectHourDataTool); //act.BeginInvoke(ar => act.EndInvoke(ar), null); //参数null可以作为回调函数的返回参数 _ = FrDataCollect.frDataCollect.collectHourDataTool(); } catch (Exception e) { Loghelper.WriteErrorLog("定时任务调用窗体函数采集数据失败", e); lr.AddLogInfo(e.ToString(), "定时任务调用窗体函数采集数据失败", "定时任务调用窗体函数采集数据失败", "Error"); //throw e; } }); }
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { try { if (MessageBox.Show("是否确认退出程序,退出后将停止采集?", "退出", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { // 关闭所有的线程 this.Dispose(); this.Close(); if (frDataCollect != null) { frDataCollect.ClearJobTrigger(); } } } catch (Exception ex) { //日志处理 Loghelper.WriteErrorLog("捕获异常信息", ex); lr.AddLogInfo(ex.ToString(), "捕获异常信息", "捕获异常信息", "Error"); } }
/// <summary> /// 查询区域信息 /// </summary> /// <param name="areaCode"></param> /// <param name="level"></param> /// <returns></returns> public DataTable AreaInfoQuery(string areaCode = "*", string level = "*") { DataTable dt = new DataTable(); string areaCodeFilter = ""; if (!string.IsNullOrEmpty(areaCode) && areaCode != "*") { areaCodeFilter = " and \"AreaCode\" like '" + areaCode + "%'"; } string levelFilter = ""; if (!string.IsNullOrEmpty(level) && level != "*") { levelFilter = " and \"Level\" in(" + Utility.ConvertFieldValue(level) + ")"; } try { StringBuilder sb = new StringBuilder(); sb.AppendFormat("select * from \"t_area\" where 1=1 {0} {1} " + " order by \"AreaCode\" asc", areaCodeFilter, levelFilter); SQLiteConnection conn = SQLiteHelper.GetConnection(dataBaseName); DataSet datasetTemp = SQLiteHelper.ExecuteDataSet(conn, sb.ToString(), null); if (datasetTemp != null) { dt = datasetTemp.Tables[0]; } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("查询区域信息失败", e); lr.AddLogInfo(e.ToString(), "查询区域信息失败", "t_area", "Error"); //throw e; } return(dt); }
public async Task airStationLoadTask() { try { load_lb.Visible = true; string cityCode = "*"; string cityName = "全国"; if (cityComboBox.SelectedItem != null) { Area areaCityObj = (Area)(cityComboBox.SelectedItem); cityCode = areaCityObj.AreaCode; cityName = areaCityObj.AreaName; } if (proviceComboBox.SelectedItem != null && (cityCode == "*" || String.IsNullOrEmpty(cityCode))) { Area areaProviceObj = (Area)(proviceComboBox.SelectedItem); cityCode = areaProviceObj.AreaCode.Substring(0, 2); cityName = areaProviceObj.AreaName; } //创建domain客户端 EnvCnemcPublishDomainContext publishCtx = new EnvCnemcPublishDomainContext(XAP_URL); //获取所有检测站,业务上通过citycode与城市对应 IEnumerable <StationConfig> stations = await publishCtx.Load(publishCtx.GetStationConfigsQuery()).ResultAsync(); List <JObject> list = new List <JObject>(); if (stations != null) { for (int i = 0; i < stations.Count(); i++) { StationConfig sc = stations.ElementAt(i); if (cityCode == "*" || sc.CityCode.ToString().StartsWith(cityCode)) { JObject jo = new JObject(); jo["UniqueCode"] = sc.UniqueCode; jo["Area"] = sc.Area; jo["CityCode"] = sc.CityCode; jo["StationCode"] = sc.StationCode; jo["Latitude"] = sc.Latitude; jo["Longitude"] = sc.Longitude; jo["PositionName"] = sc.PositionName; list.Add(jo); } } } if (list.Count > 0) { if (asr.DeleteAirStationInfo()) { _ = Task.Run(() => { bool result = asr.AddAirStationInfo(list); load_lb.Visible = false; if (result) { stationQueryBtn_Click(null, null); MessageBox.Show(cityName + list.Count + "个空气质量站点同步成功!", " 提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(cityName + "空气质量站点同步失败!", " 提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); } } else { load_lb.Visible = false; MessageBox.Show(cityName + "没有空气质量站点要同步", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception e) { load_lb.Visible = false; //日志处理 Loghelper.WriteErrorLog("同步空气质量站点数据失败", e); lr.AddLogInfo(e.ToString(), "同步空气质量站点数据失败", "", "Error"); //throw e; } }
/// <summary> /// 设备采集数据录入 /// </summary> /// <param name="tableName"></param> /// <param name="jdatas"></param> /// <returns></returns> public bool AddDataInfo(string tableName, List <JObject> jdatas) { try { StringBuilder sb = new StringBuilder(); for (int k = 0; k < jdatas.Count; k++) { StringBuilder fieldname = new StringBuilder(); StringBuilder fieldvalue = new StringBuilder(); //获得对象的所有字段名 var itemProperties = (jdatas[k]).Properties().ToList(); for (int i = 0; i < itemProperties.Count; i++) { //var v = item.Name + ":" + item.Value; switch (itemProperties[i].Value.Type) { case JTokenType.Integer: fieldvalue.AppendFormat(itemProperties[i].Value.ToString()); break; case JTokenType.Float: fieldvalue.AppendFormat(itemProperties[i].Value.ToString()); break; case JTokenType.String: fieldvalue.AppendFormat("'" + itemProperties[i].Value.ToString() + "'"); break; case JTokenType.Date: fieldvalue.AppendFormat("'{0}'", Convert.ToDateTime(itemProperties[i].Value).ToString("yyyy-MM-dd HH:mm:ss.fff")); break; case JTokenType.Null: //fieldvalue.AppendFormat(null); break; default: fieldvalue.AppendFormat("'" + itemProperties[i].Value.ToString() + "'"); break; } if (itemProperties[i].Value.Type != JTokenType.Null) { //fieldname.AppendFormat("\"" + itemProperties[i].Name + "\""); fieldname.AppendFormat(itemProperties[i].Name); if (i < itemProperties.Count - 1) { fieldname.AppendFormat(","); fieldvalue.AppendFormat(","); } } } sb.AppendFormat("insert into {0} ({1}) values ({2});", tableName, fieldname.ToString(), fieldvalue.ToString()); } this.dbHelper = new DBHelper(tempSQLCoonectStr); string sql = SQLUtils.genarateSQL(sb.ToString(), this.dbHelper.sqlConnectionType); int count = dbHelper.ExecuteNonQuery(CommandType.Text, sql); if (count > 0) { return(true); } else { return(false); } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("设备采集数据录入失败", e); lr.AddLogInfo(e.ToString(), "设备采集数据录入失败", tableName, "Error"); //throw e; } return(false); }
/// <summary> /// 新增配置数据源 /// </summary> /// <param name="jdata"></param> /// <returns></returns> public bool AddDataConfigInfo(JObject jdata) { string tableName = "t_data_config"; if (jdata != null) { try { jdata["CreateTime"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); StringBuilder sb = new StringBuilder(); dynamic json = jdata; StringBuilder fieldname = new StringBuilder(); StringBuilder fieldvalue = new StringBuilder(); //获得对象的所有字段名 var itemProperties = ((JObject)jdata).Properties().ToList(); for (int i = 0; i < itemProperties.Count; i++) { //var v = item.Name + ":" + item.Value; switch (itemProperties[i].Value.Type) { case JTokenType.Integer: fieldvalue.AppendFormat(itemProperties[i].Value.ToString()); break; case JTokenType.Float: fieldvalue.AppendFormat(itemProperties[i].Value.ToString()); break; case JTokenType.String: fieldvalue.AppendFormat("'" + itemProperties[i].Value.ToString() + "'"); break; case JTokenType.Date: fieldvalue.AppendFormat("'{0}'", Convert.ToDateTime(itemProperties[i].Value).ToString("yyyy-MM-dd HH:mm:ss.fff")); break; case JTokenType.Boolean: break; case JTokenType.Array: break; } fieldname.AppendFormat("\"" + itemProperties[i].Name + "\""); if (i < itemProperties.Count - 1) { fieldname.AppendFormat(","); fieldvalue.AppendFormat(","); } } sb.AppendFormat("insert into \"{0}\" ({1}) values ({2});", tableName, fieldname.ToString(), fieldvalue.ToString()); //string sql = SQLUtils.genarateSQL(sb.ToString(), SQLConnectionType.PostgreSQL); SQLiteConnection conn = SQLiteHelper.GetConnection(dataBaseName); int count = SQLiteHelper.ExecuteNonQuery(conn, sb.ToString(), null); if (count > 0) { return(true); } else { return(false); } } catch (Exception e) { //日志处理 Loghelper.WriteErrorLog("新增配置数据源失败", e); //throw e; } } return(false); }