private List <string> GetUIShowStringList(CEntitySoilData entity) { // CEntitySoilStation station = CDBSoilDataMgr.Instance.GetSoilStationInfoByStationId(entity.StationID); //var stationEntity = CDBDataMgr.Instance.GetStationById(station.StationID); CEntitySoilStation stationEntity = CDBSoilDataMgr.Instance.GetSoilStationInfoByStationId(entity.StationID); //var stationEntity = CDBDataMgr.Instance.GetStationById(station.StationID); List <string> result = new List <string>(); result.Add(stationEntity.StationID); result.Add(stationEntity.StationName); result.Add(CEnumHelper.StationTypeToUIStr(stationEntity.StationType)); result.Add(entity.DataTime.ToString()); result.Add(CEnumHelper.MessageTypeToUIStr(entity.MessageType)); result.Add(CEnumHelper.ChannelTypeToUIStr(entity.ChannelType)); result.Add(entity.Voltage10.HasValue ? entity.Voltage10.Value.ToString() : CS_NullUIStr); result.Add(entity.Moisture10.HasValue ? entity.Moisture10.ToString() : CS_NullUIStr); result.Add(entity.Voltage20.HasValue ? entity.Voltage20.ToString() : CS_NullUIStr); result.Add(entity.Moisture20.HasValue ? entity.Moisture20.ToString() : CS_NullUIStr); result.Add(entity.Voltage30.HasValue ? entity.Voltage30.ToString() : CS_NullUIStr); result.Add(entity.Moisture30.HasValue ? entity.Moisture30.ToString() : CS_NullUIStr); result.Add(entity.Voltage40.HasValue ? entity.Voltage40.ToString() : CS_NullUIStr); result.Add(entity.Moisture40.HasValue ? entity.Moisture40.ToString() : CS_NullUIStr); result.Add(entity.Voltage60.HasValue ? entity.Voltage60.ToString() : CS_NullUIStr); result.Add(entity.Moisture60.HasValue ? entity.Moisture60.ToString() : CS_NullUIStr); return(result); }
/// <summary> /// 获取所有查询的测站 /// </summary> /// <returns></returns> //public List<CEntityStation> GetAllSelectedStation() //{ // List<CEntityStation> listResults = new List<CEntityStation>(); // base.m_mutexDataTable.WaitOne(); // for (int i = 0; i < m_dataTable.Rows.Count; ++i) // { // // 获取编辑过的每一行 // string strChecked = m_dataTable.Rows[i][CS_Select].ToString(); // if (strChecked == "True") // { // string stationId = m_dataTable.Rows[i][CS_StationID].ToString(); // CEntityStation station = CDBDataMgr.Instance.GetStationById(stationId); // if (null != station) // { // listResults.Add(station); // } // //应该都会存在的 // } // else // { // // 没有选中 // } // } // base.m_mutexDataTable.ReleaseMutex(); // return listResults; //} public List <CEntitySoilStation> GetAllSelectedStation() { List <CEntitySoilStation> listResults = new List <CEntitySoilStation>(); base.m_mutexDataTable.WaitOne(); for (int i = 0; i < m_dataTable.Rows.Count; ++i) { // 获取编辑过的每一行 string strChecked = m_dataTable.Rows[i][CS_Select].ToString(); if (strChecked == "True") { string stationId = m_dataTable.Rows[i][CS_StationID].ToString(); CEntitySoilStation station = CDBSoilDataMgr.Instance.GetSoilStationInfoByStationId(stationId); if (null != station) { listResults.Add(station); } //应该都会存在的 } else { // 没有选中 } } base.m_mutexDataTable.ReleaseMutex(); return(listResults); }
private CEntityStation GetStationInfoByDeviceNum(string deviceNum) { CEntityStation result = null; if (String.IsNullOrEmpty(deviceNum)) { return(result); } var soilStationLists = GetAllSoilStation(); CEntitySoilStation soilStation = null; //foreach (var item in soilStationLists) //{ // if (deviceNum == item.StrDeviceNumber) // { // soilStation = item; // break; // } //} if (null != soilStation && !String.IsNullOrEmpty(soilStation.StationID)) { result = CDBDataMgr.Instance.GetStationById(soilStation.StationID); } return(result); }
//public static void sendMyTru(String stationid) //{ // CEntityStation entity = new CEntityStation(); // // entity.StationID = "6018"; // entity = CDBDataMgr.Instance.GetStationById(stationid); // // entity.StationID = stationid; // // entity.GPRS = "60006018"; // Form1 f1 = new Form1(); // // entity.GPRS = f1.getGPRSback(stationid); // if (entity != null) // { // CPortDataMgr.Instance.SendHex(entity); // } //} public static void sendMyTru(String stationid) { CEntityStation entity = new CEntityStation(); // entity.StationID = "6018"; entity = CDBDataMgr.Instance.GetStationById(stationid); // entity.StationID = stationid; // entity.GPRS = "60006018"; Form1 f1 = new Form1(); // entity.GPRS = f1.getGPRSback(stationid); if (entity != null) { CPortDataMgr.Instance.SendHex(entity); } else { CEntitySoilStation soilEntity = new CEntitySoilStation(); soilEntity = CDBSoilDataMgr.Instance.GetSoilStationInfoByStationId(stationid); if (soilEntity != null) { CPortDataMgr.Instance.SendSoilHex(soilEntity); } } }
/// <summary> /// 更新实时数据 /// </summary> /// <param name="entity"></param> /// <returns></returns> public bool UpdateRTD(CEntitySoilData entity) { // 根据ID进行分中心分发 bool result = (m_dgvAllPage.DataGrid as CDataGridViewSoilRTD).UpdateRTD(entity); // 获取每个站点分中心的ID // CEntityStation station = CDBDataMgr.Instance.GetStationById(entity.StationID); CEntitySoilStation soilstation = CDBSoilDataMgr.Instance.GetSoilStationInfoByStationId(entity.StationID); if (null != soilstation && m_mapSubCenterPage.ContainsKey(soilstation.SubCenterID.Value)) { result = result && (m_mapSubCenterPage[soilstation.SubCenterID.Value].DataGrid as CDataGridViewSoilRTD).UpdateRTD(entity); } return(result); }
//处理 void form2_MyEvent(CEntitySoilStation station) { // m_dgvSoilStatioin.m_listAddedSoilStation.Add(station); // m_dgvSoilStatioin.m_proxySoilStation.AddNewRow(station); m_dgvSoilStatioin.m_listAddedSoilStation.Add(station); m_dgvSoilStatioin.m_proxySoilStation.AddSoilStationRange(m_dgvSoilStatioin.m_listAddedSoilStation); //m_dgvStatioin.Revert(); // 重新加载 CDBSoilDataMgr.Instance.ReloadSoilStation(); CDBSoilDataMgr.Instance.UpdateAllSoilStation(); m_dgvSoilStatioin.Revert(); m_dgvSoilStatioin.UpdateDataToUI(); //this.listBox1.Items.RemoveAt(index); //this.listBox1.Items.Insert(index, text); }
/// <summary> /// 站点和数据协议的对应 /// 1.如果是gprs信道,则关联gprs号和数据协议的对应 /// 2.如果是gsm信道,则关联gsm号码和数据协议的对应 /// 3.如果是beidou信道,则关联beidou号码和数据协议的对应 /// </summary> /// <param name="channnel"></param> private void initStations() { m_listStations = m_proxyStation.QueryAll(); m_listSoillStations = m_proxySoliStation.QueryAllSoilStation(); //水雨情、墒情中gprs号码 gsm号码 北斗号码都是不重复的 //1.初始化水情信息对应 for (int i = 0; i < m_listStations.Count; i++) { CEntityStation station = new CEntityStation(); station = m_listStations[i]; if (station.GPRS != null && station.GPRS.Trim().Length > 0) { stationGprsMap[station.GPRS.Trim()] = station.Datapotocol; hexGprsMap[station.GPRS.Trim()] = "Hex"; // 或者ASCII } if (station.GSM != null && station.GSM.Trim().Length > 0) { stationGsmMap[station.GSM.Trim()] = station.Datapotocol; hexGsmMap[station.GPRS.Trim()] = "Hex"; // 或者ASCII } if (station.BDSatellite != null && station.BDSatellite.Trim().Length > 0) { stationBeidouMap[station.BDSatellite.Trim()] = station.Datapotocol; hexBeidouMap[station.BDSatellite.Trim()] = "Hex"; // 或者ASCII } } //2.初始化墒情信息对应 for (int i = 0; i < m_listSoillStations.Count; i++) { CEntitySoilStation soilStation = new CEntitySoilStation(); soilStation = m_listSoillStations[i]; if (soilStation.GPRS != null && soilStation.GPRS.Trim().Length > 0) { stationGprsMap[soilStation.GPRS.Trim()] = soilStation.Datapotocol; hexGprsMap[soilStation.GPRS.Trim()] = "Hex"; // 或者ASCII } if (soilStation.GSM != null && soilStation.GSM.Trim().Length > 0) { stationGsmMap[soilStation.GSM.Trim()] = soilStation.Datapotocol; hexGsmMap[soilStation.GSM.Trim()] = "Hex"; // 或者ASCII } if (soilStation.BDSatellite != null && soilStation.BDSatellite.Trim().Length > 0) { stationBeidouMap[soilStation.GPRS.Trim()] = soilStation.Datapotocol; hexBeidouMap[soilStation.BDSatellite.Trim()] = "Hex"; // 或者ASCII } } }
/// <summary> /// 添加实时数据 /// </summary> /// <param name="entity"></param> public void AddRTD(CEntitySoilData entity) { // 根据ID进行分中心分发 (m_dgvAllPage.DataGrid as CDataGridViewSoilRTD).AddRTD(entity); // 获取每个站点分中心的ID // CEntityStation station = CDBDataMgr.Instance.GetStationById(entity.StationID); CEntitySoilStation soilstation = CDBSoilDataMgr.Instance.GetSoilStationInfoByStationId(entity.StationID); if (null != soilstation && m_mapSubCenterPage.ContainsKey(soilstation.SubCenterID.Value)) { (m_mapSubCenterPage[soilstation.SubCenterID.Value].DataGrid as CDataGridViewSoilRTD).AddRTD(entity); } //(m_dgvAllPage.DataGrid as CDataGridViewSoilRTD).RecalculateHeaderSize(); //计算表头宽度 }
public List <CEntitySoilStation> getAllGprs_1() { List <CEntitySoilStation> results = new List <CEntitySoilStation>(); string sql = "select distinct Gprs,stationid from " + CT_TableName + ";"; SqlDataAdapter adapter = new SqlDataAdapter(sql, CDBManager.GetInstacne().GetConnection()); DataTable dataTableTmp = new DataTable(); adapter.Fill(dataTableTmp); for (int rowid = 0; rowid < dataTableTmp.Rows.Count; ++rowid) { CEntitySoilStation result = new CEntitySoilStation(); string gprs = dataTableTmp.Rows[rowid][0].ToString(); string stationid = dataTableTmp.Rows[rowid][1].ToString(); result.GPRS = gprs; result.StationID = stationid; results.Add(result); } return(results); }
private void btn_Save_Click(object sender, EventArgs e) { try { // 完成添加 CEntitySoilStation soilstation = GenerateSoilStationFromUI(); if (null == soilstation) { return; } CDBSoilDataMgr.Instance.m_mapStaionSoilInfo.Add(soilstation.StationID, soilstation); AddSoilStationEvent(soilstation); this.Hide(); MessageBox.Show("测站添加完成! ", "提示 ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } catch (Exception ex) { MessageBox.Show("测站添加失败! ", "提示 ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }
// 根据设定的条件查询数据表 private void btnQuery_Click(object sender, EventArgs e) { // 获取站点ID // 获取起始日期 // 获取结束日期 // 判断输入是否合法 string stationId = ""; Object stationObject = (cmbStation as CStationComboBox_1).GetStation_1(); // CEntityStation station = (cmbStation as CStationComboBox).GetStation(); CEntityStation station = new CEntityStation(); CEntitySoilStation soilstation = new CEntitySoilStation(); if (stationObject is CEntityStation) { station = (CEntityStation)stationObject; } else { soilstation = (CEntitySoilStation)stationObject; } if (null == station || null == soilstation) { MessageBox.Show("请选择正确的站点后再进行查询"); return; } // 判断开始时间是否小于结束时间 if (dtpTimeStart.Value >= dptTimeEnd.Value) { MessageBox.Show("开始时间必须小于结束时间"); return; } if (null != station.StationID) { stationId = station.StationID; } else { stationId = soilstation.StationID; } m_statusLable.Text = "正在查询..."; this.Enabled = false; bool TimeSelect = false; if (cmb_TimeSelect.Text.Equals(CS_CMB_TimeData)) { TimeSelect = true; } if (cmbQueryInfo.Text.Equals(CS_CMB_Rain)) { #region 雨量 if (m_dgvRain.IsModifiedUnSaved()) { DialogResult result = MessageBox.Show("当前所做修改尚未保存,强行查询会导致修改丢失,是否保存?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (DialogResult.Yes == result) { // 保存当前修改 if (DoSave()) { // 保存成功以后, 继续查询 } else { // 保存失败,不查询 return; } } else if (DialogResult.No == result) { //return; //直接退出 } else if (DialogResult.Cancel == result) { this.Close(); return;// 退出查询 } } if (m_dgvRain.SetFilter(stationId, dtpTimeStart.Value, dptTimeEnd.Value, TimeSelect)) { // 如果查询成功 m_chartRain.SetFilter(stationId, dtpTimeStart.Value, dptTimeEnd.Value, cmb_RainShape.SelectedIndex, TimeSelect); } m_dgvRain.UpdateDataToUI(); #endregion 雨量 } else if (cmbQueryInfo.Text.Equals(CS_CMB_Water)) { #region 水位 if (m_dgvWater.IsModifiedUnSaved()) { DialogResult result = MessageBox.Show("当前所做修改尚未保存,强行查询会导致修改丢失,是否保存?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (DialogResult.Yes == result) { // 保存当前修改 if (DoSave()) { // 保存成功以后, 继续查询 } else { // 保存失败,不查询 return; } } else if (DialogResult.No == result) { //直接退出 } else if (DialogResult.Cancel == result) { this.Close(); return;// 退出查询 } } if (m_dgvWater.SetFilter(stationId, dtpTimeStart.Value, dptTimeEnd.Value, TimeSelect)) { if (cmb_RainShape.SelectedIndex == 0) { m_chartWaterFlow.SetFilter(stationId, dtpTimeStart.Value, dptTimeEnd.Value, TimeSelect); } if (cmb_RainShape.SelectedIndex == 1) { m_charSoilData.SetFilter(stationId, dtpTimeStart.Value, dptTimeEnd.Value); } } m_dgvWater.UpdateDataToUI(); #endregion 水位 } else if (cmbQueryInfo.Text.Equals(CS_CMB_Voltage)) { #region 电压 // 查询电压 if (m_dgvVoltage.IsModifiedUnSaved()) { DialogResult result = MessageBox.Show("当前所做修改尚未保存,强行查询会导致修改丢失,是否保存?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (DialogResult.Yes == result) { // 保存当前修改 if (DoSave()) { // 保存成功以后, 继续查询 } else { // 保存失败,不查询 return; } } else if (DialogResult.No == result) { //直接退出 } else if (DialogResult.Cancel == result) { this.Close(); return;// 退出查询 } } bool updateData = false; if (m_dgvVoltage.SetFilter(stationId, dtpTimeStart.Value, dptTimeEnd.Value, TimeSelect)) { updateData = m_chartVoltage.SetFilter(stationId, dtpTimeStart.Value, dptTimeEnd.Value, TimeSelect); } //if (updateData == true) //{ m_dgvVoltage.UpdateDataToUI(); //} #endregion 电压 } else if (cmbQueryInfo.Text.Equals(CS_CMB_SoilData)) { #region 墒情数据 if (m_dgvSoilData.SetFilter(stationId, dtpTimeStart.Value, dptTimeEnd.Value)) { m_charSoilData.SetFilter(stationId, dtpTimeStart.Value, dptTimeEnd.Value); } m_dgvSoilData.UpdateDataToUI(); #endregion 墒情数据 } this.Enabled = true; m_statusLable.Text = "查询已成功完成"; }
private string GetDisplaySoilStationName(CEntitySoilStation station) { return(string.Format("({0,-4}|{1})", station.StationID, station.StationName)); }
private bool DealWithLineData(string str, int lineNumber, ref string strErroInfo, ref List <string> gprs) { decimal a10, b10, c10, d10, m10, n10, a20, b20, c20, d20, m20, n20, a30, b30, c30, d30, m30, n30, a40, b40, c40, d40, m40, n40, a60, b60, c60, d60, m60, n60, voltagemin; string[] results = str.Split(','); if (43 == results.Length) { try { string stationid = results[0]; int subcenterid = CDBDataMgr.Instance.GetSubCenterByName(results[3]).SubCenterID; string cname = results[1]; // ESoilStationType stationtype = CEnumHelper.UIStrToStationType(results[3]); CEntitySoilStation soilStation = new CEntitySoilStation(); soilStation.StationID = stationid; soilStation.SubCenterID = subcenterid; soilStation.StationName = cname; soilStation.StationType = CEnumHelper.UIStrToStationType(results[2]); if (results[12] != "") { a10 = decimal.Parse(results[12]); soilStation.A10 = a10; } if (results[13] != "") { b10 = decimal.Parse(results[13]); soilStation.B10 = b10; } if (results[14] != "") { c10 = decimal.Parse(results[14]); soilStation.C10 = c10; } if (results[15] != "") { d10 = decimal.Parse(results[15]); soilStation.D10 = d10; } if (results[16] != "") { m10 = decimal.Parse(results[16]); soilStation.M10 = m10; } if (results[17] != "") { n10 = decimal.Parse(results[17]); soilStation.N10 = n10; } if (results[18] != "") { a20 = decimal.Parse(results[18]); soilStation.A20 = a20; } if (results[19] != "") { b20 = decimal.Parse(results[19]); soilStation.B20 = b20; } if (results[20] != "") { c20 = decimal.Parse(results[20]); soilStation.C20 = c20; } if (results[21] != "") { d20 = decimal.Parse(results[21]); soilStation.D20 = d20; } if (results[22] != "") { m20 = decimal.Parse(results[22]); soilStation.M20 = m20; } if (results[23] != "") { n20 = decimal.Parse(results[23]); soilStation.N20 = n20; } if (results[24] != "") { a30 = decimal.Parse(results[24]); soilStation.A30 = a30; } if (results[25] != "") { b30 = decimal.Parse(results[25]); soilStation.B30 = b30; } if (results[26] != "") { c30 = decimal.Parse(results[26]); soilStation.C30 = c30; } if (results[27] != "") { d30 = decimal.Parse(results[27]); soilStation.D30 = d30; } if (results[28] != "") { m30 = decimal.Parse(results[28]); soilStation.M30 = m30; } if (results[29] != "") { n30 = decimal.Parse(results[29]); soilStation.N30 = n30; } if (results[30] != "") { a40 = decimal.Parse(results[30]); soilStation.A40 = a40; } if (results[31] != "") { b40 = decimal.Parse(results[31]); soilStation.B40 = b40; } if (results[32] != "") { c40 = decimal.Parse(results[32]); soilStation.C40 = c40; } if (results[33] != "") { d40 = decimal.Parse(results[33]); soilStation.D40 = d40; } if (results[34] != "") { m40 = decimal.Parse(results[34]); soilStation.M40 = m40; } if (results[35] != "") { n40 = decimal.Parse(results[35]); soilStation.N40 = n40; } if (results[36] != "") { a60 = decimal.Parse(results[36]); soilStation.A60 = a60; } if (results[37] != "") { b60 = decimal.Parse(results[37]); soilStation.B60 = b60; } if (results[38] != "") { c60 = decimal.Parse(results[38]); soilStation.C60 = c60; } if (results[39] != "") { d60 = decimal.Parse(results[39]); soilStation.D60 = d60; } if (results[40] != "") { m60 = decimal.Parse(results[40]); soilStation.M60 = m60; } if (results[41] != "") { n60 = decimal.Parse(results[41]); soilStation.N60 = n60; } if (results[42] != "") { voltagemin = decimal.Parse(results[42]); soilStation.VoltageMin = voltagemin; } soilStation.GSM = results[4]; if (results[5] != "" && gprs.Contains(results[5])) { strErroInfo = string.Format("行:{0} 数据格式错误", lineNumber); return(false); } else { soilStation.GPRS = results[5]; gprs.Add(results[5]); } soilStation.BDSatellite = results[6]; soilStation.BDMemberSatellite = results[7]; if (results[8] == "SX-GPRS" || results[8] == "GSM" || results[8] == "Beidou-Normal" || results[8] == "Beidou-500") { soilStation.Maintran = results[8]; } else { strErroInfo = string.Format("行:{0} 数据格式错误,主信道不能为空", lineNumber); return(false); } //判定subtran不能为空 if (results[9] == "SX-GPRS" || results[9] == "GSM" || results[9] == "Beidou-Normal" || results[9] == "Beidou-500" || results[9] == "无") { soilStation.Subtran = results[9]; } else { strErroInfo = string.Format("行:{0} 数据格式错误,备用信道不能为空", lineNumber); return(false); } if (results[10] == "LN") { soilStation.Datapotocol = results[10]; } else { strErroInfo = string.Format("行:{0} 数据格式错误,数据协议出错", lineNumber); return(false); } if (results[11] == "1" || results[11] == "4" || results[11] == "8" || results[11] == "12" || results[11] == "24" || results[11] == "48") { soilStation.Reportinterval = results[11]; } else { strErroInfo = string.Format("行:{0} 数据格式错误,报讯断次不能为空", lineNumber); return(false); } m_listImport.Add(soilStation); return(true); } catch (Exception e) { Debug.WriteLine(e.ToString()); strErroInfo = string.Format("行:{0} 数据格式错误", lineNumber); return(false); } } else { strErroInfo = string.Format("行:{0} 数据格式错误", lineNumber); return(false); } // return false; }
/// <summary> /// 查询所有的墒情站点信息 /// </summary> /// <returns></returns> public List <CEntitySoilStation> QueryAllSoilStation() { string sql = " select * from " + CT_TableName; SqlDataAdapter adapter = new SqlDataAdapter(sql, CDBManager.GetInstacne().GetConnection()); DataTable dataTableTmp = new DataTable(); adapter.Fill(dataTableTmp); // 构建结果集 List <CEntitySoilStation> results = new List <CEntitySoilStation>(); for (int rowid = 0; rowid < dataTableTmp.Rows.Count; ++rowid) { CEntitySoilStation soilStation = new CEntitySoilStation(); soilStation.StationID = dataTableTmp.Rows[rowid][CN_StationId].ToString(); soilStation.SubCenterID = int.Parse(dataTableTmp.Rows[rowid][CN_SubCenterID].ToString()); soilStation.StationName = dataTableTmp.Rows[rowid][CN_StationName].ToString(); soilStation.StationType = CEnumHelper.DBStrToStationType(dataTableTmp.Rows[rowid][CN_StationType].ToString()); // soilStation.StrDeviceNumber = dataTableTmp.Rows[rowid][CN_DeviceNumber].ToString(); soilStation.A10 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_A10]); soilStation.B10 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_B10]); soilStation.C10 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_C10]); soilStation.D10 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_D10]); soilStation.M10 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_M10]); soilStation.N10 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_N10]); soilStation.A20 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_A20]); soilStation.B20 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_B20]); soilStation.C20 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_C20]); soilStation.D20 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_D20]); soilStation.M20 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_M20]); soilStation.N20 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_N20]); soilStation.A30 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_A30]); soilStation.B30 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_B30]); soilStation.C30 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_C30]); soilStation.D30 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_D30]); soilStation.M30 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_M30]); soilStation.N30 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_N30]); soilStation.A40 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_A40]); soilStation.B40 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_B40]); soilStation.C40 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_C40]); soilStation.D40 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_D40]); soilStation.M40 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_M40]); soilStation.N40 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_N40]); soilStation.A60 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_A60]); soilStation.B60 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_B60]); soilStation.C60 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_C60]); soilStation.D60 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_D60]); soilStation.M60 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_M60]); soilStation.N60 = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_N60]); soilStation.VoltageMin = GetCellDecimalValue(dataTableTmp.Rows[rowid][CN_Voltagemin]); soilStation.GSM = dataTableTmp.Rows[rowid][CN_GSM].ToString(); soilStation.GPRS = dataTableTmp.Rows[rowid][CN_GPRS].ToString(); soilStation.BDSatellite = dataTableTmp.Rows[rowid][CN_BDSatellite].ToString(); soilStation.BDMemberSatellite = dataTableTmp.Rows[rowid][CN_BDMember].ToString(); soilStation.Maintran = dataTableTmp.Rows[rowid][CN_Maintran].ToString(); soilStation.Subtran = dataTableTmp.Rows[rowid][CN_Subtran].ToString(); soilStation.Datapotocol = dataTableTmp.Rows[rowid][CN_Dataprotocol].ToString(); soilStation.Reportinterval = dataTableTmp.Rows[rowid][CN_Reportinterval].ToString(); results.Add(soilStation); } return(results); }
private void button1_Click(object sender, EventArgs e) { if (!HasUserOnLine()) { return; } // var listStation = this.m_dgvStorageWater.GetAllSelectedStation(); //List<CEntityStation> listOnlineStationSelected = new List<CEntityStation>(); //List<string> result = new List<string>(); //result=ListOnlineStation int tag = 0; if (this.radioButton1.Checked) { tag = 1; //for (int k = 0; k < ListOnlineStation1.Count; k++) //{ // result.Add(ListOnlineStation1[k].StationID); //} } else if (this.radioButton2.Checked) { tag = 2; //for (int k = 0; k < ListOnlineStation2.Count; k++) //{ // result.Add(ListOnlineStation2[k].StationID); //} } else if (this.radioButton3.Checked) { tag = 3; //for (int k = 0; k < ListOnlineStation3.Count; k++) //{ // result.Add(ListOnlineStation3[k].StationID); //} } else if (this.radioButton4.Checked) { tag = 4; //for (int k = 0; k < ListOnlineStation4.Count; k++) //{ // result.Add(ListOnlineStation4[k].StationID); //} } List <CEntityStation> listStation = new List <CEntityStation>(); List <CEntitySoilStation> listSoilStation = new List <CEntitySoilStation>(); switch (tag) { case 1: listStation = this.m_dgvStorageWater.GetAllSelectedStation(); break; case 2: listStation = this.m_dgvRealityWater.GetAllSelectedStation(); break; case 3: listStation = this.m_dgvRainManage.GetAllSelectedStation(); break; case 4: listSoilStation = this.m_dgvSoilDataManage.GetAllSelectedStation(); break; } if (tag == 1 || tag == 2 || tag == 3) { if (0 == listStation.Count) { MessageBox.Show("请选择站点!"); return; } } else if (tag == 4) { if (0 == listSoilStation.Count) { MessageBox.Show("请选择站点!"); return; } } this.btn_StartAdjust.Enabled = false; //for (int j = 0; j < listStation.Count; j++) //{ // if (result.Contains(listStation[j].StationID)) // { // listOnlineStationSelected.Add(listStation[j]); // } //} if (tag == 1) { AddLog1("--读取存储水位--"); for (int i = 0; i < listStation.Count; i++) { m_currentStation = listStation[i]; string sendMsg = CPortDataMgr.Instance.GroupStorageWaterFirst(m_currentStation); AddLog1(sendMsg); } System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer() { Interval = 1000 }; int m = 0; timer.Tick += (s1, e1) => { if (m > 0) { timer.Stop(); m_currentStation = null; // this.btn_StartAdjust.Enabled = true; return; } for (int i = 0; i < listStation.Count; i++) { m_currentStation = listStation[i]; string sendMsg = CPortDataMgr.Instance.GroupStorageWaterFirst(m_currentStation); AddLog1(sendMsg); } m = 1; }; timer.Start(); } else if (tag == 2) { AddLog1("--读取实测水位--"); for (int i = 0; i < listStation.Count; i++) { m_currentStation = listStation[i]; string sendMsg = CPortDataMgr.Instance.GroupRealityWaterFirst(m_currentStation); AddLog1(sendMsg); } System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer() { Interval = 1000 }; int m = 0; timer.Tick += (s1, e1) => { if (m > 0) { timer.Stop(); m_currentStation = null; // this.btn_StartAdjust.Enabled = true; return; } for (int i = 0; i < listStation.Count; i++) { m_currentStation = listStation[i]; string sendMsg = CPortDataMgr.Instance.GroupRealityWaterFirst(m_currentStation); AddLog1(sendMsg); } m = 1; }; timer.Start(); } else if (tag == 3) { AddLog1("--读取雨量--"); for (int i = 0; i < listStation.Count; i++) { m_currentStation = listStation[i]; string sendMsg = CPortDataMgr.Instance.GroupRainWaterFirst(m_currentStation); AddLog1(sendMsg); } System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer() { Interval = 1000 }; int m = 0; timer.Tick += (s1, e1) => { if (m > 0) { timer.Stop(); m_currentStation = null; // this.btn_StartAdjust.Enabled = true; return; } for (int i = 0; i < listStation.Count; i++) { m_currentStation = listStation[i]; string sendMsg = CPortDataMgr.Instance.GroupRainWaterFirst(m_currentStation); AddLog1(sendMsg); } m = 1; }; timer.Start(); } else if (tag == 4) { AddLog1("--读取墒情--"); for (int i = 0; i < listSoilStation.Count; i++) { m_currentSoilStation = listSoilStation[i]; string sendMsg = CPortDataMgr.Instance.GroupSoilWaterFirst_1(m_currentSoilStation); AddLog1(sendMsg); } System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer() { Interval = 1000 }; int m = 0; timer.Tick += (s1, e1) => { if (m > 0) { timer.Stop(); m_currentStation = null; // this.btn_StartAdjust.Enabled = true; return; } for (int i = 0; i < listSoilStation.Count; i++) { m_currentSoilStation = listSoilStation[i]; string sendMsg = CPortDataMgr.Instance.GroupSoilWaterFirst_1(m_currentSoilStation); AddLog1(sendMsg); } m = 1; }; timer.Start(); } //int i = 0; // String str = "$00010G 12\n"; // string sendMsg = CPortDataMgr.Instance.SendAdjustClock(m_currentStation); // int i=0; // System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer() //{ // Interval = 5000 //}; //AddLog1("系统正在获取,请耐心等待!"); //timer.Tick += (s1, e1) => //{ // // if (i >= listStation.Count) // if (i >= listOnlineStationSelected.Count) // { // timer.Stop(); // m_currentStation = null; // this.btn_StartAdjust.Enabled = true; // return; // } // m_currentStation = listOnlineStationSelected[i]; // // Debug.WriteLine(" i = " + i + " Name = " + m_currentStation.StationName); // if(tag == 1){ // string sendMsg = CPortDataMgr.Instance.GroupStorageWater(m_currentStation); // AddLog1(sendMsg); // } // if (tag == 2) // { // string sendMsg = CPortDataMgr.Instance.GroupRealityWater(m_currentStation); // AddLog1(sendMsg); // } // if (tag == 3) // { // string sendMsg = CPortDataMgr.Instance.GroupRainWater(m_currentStation); // AddLog1(sendMsg); // } // if (tag == 4) // { // string sendMsg = CPortDataMgr.Instance.GroupSoilWater(m_currentStation); // AddLog1(sendMsg); // } // i++; //}; //timer.Start(); }
/// <summary> /// 处理数据的任务入口 /// </summary> /// <param name="args"></param> private void DealSoilData(CSingleSoilDataArgs args) { CEntitySoilData data = new CEntitySoilData(); // if (null == CDBDataMgr.Instance.GetStationById(args.StrStationId)) if (null == GetSoilStationInfoByStationId(args.StrStationId)) { // 也就是收到未知站点的数据 CSystemInfoMgr.Instance.AddInfo(string.Format("收到未知站点{0}墒情数据", args.StrStationId)); return; } // 判断当前数据库配置中是否有站点的墒情配置 CEntitySoilStation _soilStation = GetSoilStationInfoByStationId(args.StrStationId); if (null == _soilStation) { CSystemInfoMgr.Instance.AddInfo(string.Format("站点{0}未配置墒情参数,数据丢弃", args.StrStationId)); return; } data.StationID = args.StrStationId; // data.StrDeviceNumber = _soilStation.StrDeviceNumber; data.DataTime = args.DataTime; data.DVoltage = decimal.Parse(args.Voltage.ToString()); data.ChannelType = args.EChannelType; data.MessageType = args.EMessageType; data.reciveTime = DateTime.Now; data.state = 1; // 计算10cm出的含水率 data.Voltage10 = args.D10Value; data.Moisture10 = CalMoisture(args.D10Value, _soilStation.A10, _soilStation.B10, _soilStation.C10, _soilStation.D10, _soilStation.M10, _soilStation.N10); //data.Moisture10 = CalMoisture(args.D10Value, _soilStation.A10, _soilStation.B10, _soilStation.C10, _soilStation.D10); // 计算20cm处的含水率 data.Voltage20 = args.D20Value; data.Moisture20 = CalMoisture(args.D20Value, _soilStation.A20, _soilStation.B20, _soilStation.C20, _soilStation.D20, _soilStation.M20, _soilStation.N20); //// 计算30cm处的含水率 //data.Voltage30 = args.D30Value; //data.Moisture30 = CalMoisture(args.D30Value, _soilStation.A30, _soilStation.B30, _soilStation.C30, _soilStation.D30); // 计算40cm处的含水率 data.Voltage40 = args.D40Value; data.Moisture40 = CalMoisture(args.D40Value, _soilStation.A40, _soilStation.B40, _soilStation.C40, _soilStation.D40, _soilStation.M40, _soilStation.N40); //// 计算60cm处的含水率 //data.Voltage60 = args.D60Value; //data.Moisture60 = CalMoisture(args.D60Value, _soilStation.A60, _soilStation.B60, _soilStation.C60, _soilStation.D60); // 写入数据库 m_proxySoilData.AddNewRow(data); //if (RecvedRTDSoilData != null) //{ // // 发消息通知界面 // RecvedRTDSoilData.Invoke(this, new CEventSingleArgs<CEntitySoilData>(data)); //} // 更新内存最新数据,便于写入文件 if (m_mapStataionLastData.ContainsKey(args.StrStationId)) { m_mapStataionLastData[args.StrStationId] = data; } else { // 新建一个,进行更新 m_mapStataionLastData.Add(args.StrStationId, data); } }
private CEntitySoilStation GenerateSoilStationFromUI() { try { if (!AssertInputData()) { return(null); } // 读取界面数据,并构建一个站点实体类 CEntitySoilStation soilStation = new CEntitySoilStation(); soilStation.StationID = textBox_StationID.Text.Trim(); //去掉空格 soilStation.StationName = textBox_StationName.Text.Trim(); soilStation.SubCenterID = CDBDataMgr.Instance.GetSubCenterByName(cmb_SubCenter.Text).SubCenterID; soilStation.StationType = CEnumHelper.UIStrToStationType(cmb_StationType.Text); // soilStation.StrDeviceNumber=textBox_deviceNumber.Text.Trim(); soilStation.VoltageMin = CStringFromatHelper.ConvertToNullableDecimal(textBox_Voltage.Text.ToString()); soilStation.A10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10a.Text.ToString()); soilStation.A20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20a.Text.ToString()); soilStation.A30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30a.Text.ToString()); soilStation.A40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40a.Text.ToString()); soilStation.A60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60a.Text.ToString()); soilStation.B10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10b.Text.ToString()); soilStation.B20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20b.Text.ToString()); soilStation.B30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30b.Text.ToString()); soilStation.B40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40b.Text.ToString()); soilStation.B60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60b.Text.ToString()); soilStation.C10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10c.Text.ToString()); soilStation.C20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20c.Text.ToString()); soilStation.C30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30c.Text.ToString()); soilStation.C40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40c.Text.ToString()); soilStation.C60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60c.Text.ToString()); soilStation.D10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10d.Text.ToString()); soilStation.D20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20d.Text.ToString()); soilStation.D30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30d.Text.ToString()); soilStation.D40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40d.Text.ToString()); soilStation.D60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60d.Text.ToString()); soilStation.M10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10m.Text.ToString()); soilStation.M20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20m.Text.ToString()); soilStation.M30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30m.Text.ToString()); soilStation.M40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40m.Text.ToString()); soilStation.M60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60m.Text.ToString()); soilStation.N10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10n.Text.ToString()); soilStation.N20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20n.Text.ToString()); soilStation.N30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30n.Text.ToString()); soilStation.N40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40n.Text.ToString()); soilStation.N60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60n.Text.ToString()); if (!textBox_GSM.Text.Trim().Equals("")) { string gsmNum = textBox_GSM.Text.Trim(); // if (!CStringUtil.IsDigitStrWithSpecifyLength(gsmNum, 11)) // { // MessageBox.Show("GSM号码参数不合法,长度必须为11位,必须全部是数字!"); if (!CStringUtil.IsDigit(gsmNum)) { MessageBox.Show("GSM号码参数不合法,必须全部是数字!"); return(null); } // 设置了GSM号码 soilStation.GSM = gsmNum; } if (!textBox_GPRS.Text.Trim().Equals("")) { //GPRS号码 string gprsNum = textBox_GPRS.Text.Trim(); if (!CStringUtil.IsDigit(gprsNum)) { MessageBox.Show("GPRS号码参数不合法,必须全部是数字!"); return(null); } soilStation.GPRS = gprsNum; } if (!textBox_Beidou.Text.Trim().Equals("")) { string bdNum = textBox_Beidou.Text.Trim(); if (!CStringUtil.IsDigit(bdNum)) { MessageBox.Show("北斗卫星终端号码参数不合法,必须全部是数字!"); return(null); } // 北斗卫星号码 soilStation.BDSatellite = bdNum; } if (!textBox_BeidouMember.Text.Trim().Equals("")) { string bdNum = textBox_BeidouMember.Text.Trim(); if (!CStringUtil.IsDigit(bdNum)) { MessageBox.Show("北斗卫星成员号码参数不合法,必须全部是数字!"); return(null); } // 北斗卫星号码 soilStation.BDMemberSatellite = bdNum; } soilStation.Maintran = comb_MainRoad.Text; soilStation.Subtran = comb_PrepareRoad.Text; soilStation.Datapotocol = comb_DataProtocol.Text; soilStation.Reportinterval = comb_Paragraph.Text; return(soilStation); } catch (Exception ex) { return(null); } }
/// <summary> /// 异步添加一个数据记录 /// </summary> /// <param name="entity"></param> public bool AddNewRow(CEntitySoilStation entity) { // 记录超过1000条,或者时间超过1分钟,就将当前的数据写入数据库 bool result = true; m_mutexDataTable.WaitOne(); //等待互斥量 DataRow row = m_tableDataAdded.NewRow(); row[CN_StationId] = entity.StationID; row[CN_SubCenterID] = entity.SubCenterID; row[CN_StationName] = entity.StationName; row[CN_StationType] = (Int32)entity.StationType; // row[CN_DeviceNumber] = entity.StrDeviceNumber; row[CN_A10] = entity.A10; row[CN_B10] = entity.B10; row[CN_C10] = entity.C10; row[CN_D10] = entity.D10; row[CN_M10] = entity.M10; row[CN_N10] = entity.N10; row[CN_A20] = entity.A20; row[CN_B20] = entity.B20; row[CN_C20] = entity.C20; row[CN_D20] = entity.D20; row[CN_M20] = entity.M20; row[CN_N20] = entity.N20; row[CN_A30] = entity.A30; row[CN_B30] = entity.B30; row[CN_C30] = entity.C30; row[CN_D30] = entity.D30; row[CN_M30] = entity.M30; row[CN_N30] = entity.N30; row[CN_A40] = entity.A40; row[CN_B40] = entity.B40; row[CN_C40] = entity.C40; row[CN_D40] = entity.D40; row[CN_M40] = entity.M40; row[CN_N40] = entity.N40; row[CN_A60] = entity.A60; row[CN_B60] = entity.B60; row[CN_C60] = entity.C60; row[CN_D60] = entity.D60; row[CN_M60] = entity.M60; row[CN_N60] = entity.N60; row[CN_Voltagemin] = entity.VoltageMin; row[CN_GSM] = entity.GSM; row[CN_GPRS] = entity.GPRS; row[CN_BDSatellite] = entity.BDSatellite; row[CN_BDMember] = entity.BDMemberSatellite; row[CN_Maintran] = entity.Maintran; row[CN_Subtran] = entity.Subtran; row[CN_Dataprotocol] = entity.Datapotocol; row[CN_Reportinterval] = entity.Reportinterval; m_tableDataAdded.Rows.Add(row); if (m_tableDataAdded.Rows.Count >= CDBParams.GetInstance().AddBufferMax) { // 如果超过最大值,写入数据库 m_mutexDataTable.ReleaseMutex(); result = result && AddDataToDB(); m_mutexDataTable.WaitOne(); } m_mutexDataTable.ReleaseMutex(); result = result && AddDataToDB(); return(result); }
// 设置显示的雨量记录 public void SetSoilData(List <CEntitySoilData> listSoilData) { // 清空所有数据,是否一定要这样?好像可以考虑其它方式 base.m_dataTable.Rows.Clear(); // 判断状态值 List <string[]> newRows = new List <string[]>(); List <EDataState> states = new List <EDataState>(); if (!m_bIsEditable) { // 只读模式 for (int i = 0; i < listSoilData.Count; ++i) { EDataState state = EDataState.ENormal; //默认所有数据都是正常的 string strStationID = ""; string strStationName = ""; // CEntityStation station = CDBDataMgr.Instance.GetStationById(listSoilData[i].StationID); CEntitySoilStation station = CDBSoilDataMgr.Instance.GetSoilStationInfoByStationId(listSoilData[i].StationID); if (null != station) { strStationID = station.StationID; strStationName = station.StationName; } string[] newRow = new string[] { strStationID, strStationName, listSoilData[i].DataTime.ToString(CS_TimeFormat), /*采集时间*/ listSoilData[i].DVoltage.ToString(), /*电压值*/ CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage10), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture10), CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage20), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture20), CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage30), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture30), CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage40), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture40), CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage60), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture60), CEnumHelper.ChannelTypeToUIStr(listSoilData[i].ChannelType), /*通讯方式*/ CEnumHelper.MessageTypeToUIStr(listSoilData[i].MessageType), /*报文类型*/ listSoilData[i].reciveTime.ToString() }; newRows.Add(newRow); states.Add(state); } } else { // 编辑模式 for (int i = 0; i < listSoilData.Count; ++i) { EDataState state = EDataState.ENormal; //默认所有数据都是正常的 string strStationID = ""; string strStationName = ""; // CEntityStation station = CDBDataMgr.Instance.GetStationById(listSoilData[i].StationID); CEntitySoilStation station = CDBSoilDataMgr.Instance.GetSoilStationInfoByStationId(listSoilData[i].StationID); if (null != station) { strStationID = station.StationID; strStationName = station.StationName; } string[] newRow = new string[] { "False", /*未选中*/ strStationID, strStationName, listSoilData[i].DataTime.ToString(CS_TimeFormat), /*采集时间*/ listSoilData[i].DVoltage.ToString(), /*电压值*/ CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage10), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture10), CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage20), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture20), CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage30), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture30), CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage40), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture40), CStringFromatHelper.ToUIString2Number(listSoilData[i].Voltage60), CStringFromatHelper.ToUIString3Number(listSoilData[i].Moisture60), CEnumHelper.ChannelTypeToUIStr(listSoilData[i].ChannelType), /*通讯方式*/ CEnumHelper.MessageTypeToUIStr(listSoilData[i].MessageType), /*报文类型*/ listSoilData[i].reciveTime.ToString() }; newRows.Add(newRow); states.Add(state); } } // 添加到集合的数据表中 base.AddRowRange(newRows, states); }
private void btn_Query_Click(object sender, EventArgs e) { // 获取站点ID // 获取起始日期 // 获取结束日期 // 判断输入是否合法 string stationId = ""; Object stationObject = (cmbStation as CStationComboBox_1).GetStation_1(); CEntityStation station = new CEntityStation(); CEntitySoilStation soilstation = new CEntitySoilStation(); if (stationObject is CEntityStation) { station = (CEntityStation)stationObject; } else { soilstation = (CEntitySoilStation)stationObject; } if (null == station || null == soilstation) { MessageBox.Show("请选择正确的站点后再进行查询"); return; } // 判断开始时间是否小于结束时间 if (dateTimeStart.Value >= dateTimeEnd.Value) { MessageBox.Show("开始时间必须小于结束时间"); return; } if (null != station.StationID) { stationId = station.StationID; } else { stationId = soilstation.StationID; } DateTime start = this.dateTimeStart.Value; DateTime end = this.dateTimeEnd.Value; m_statusLable.Text = "正在查询..."; this.Enabled = false; bool TimeSelect = false; try { if (cmb_TimeSelect.Text.Equals(CS_CMB_TimeData)) { TimeSelect = true; } if (ts_query.Text.Equals("雨量")) { //List<CEntityTSRain> results = m_proxyTSRain.QueryForAll(stationid, start, end); m_dgvTSRain.SetFilter(stationId, start, end, TimeSelect); } if (ts_query.Text.Equals("水位")) { m_dgvTSWater.SetFilter(stationId, start, end, TimeSelect); } if (ts_query.Text.Equals("电压")) { m_dgvTSVoltage.SetFilter(stationId, start, end, TimeSelect); } } catch (SqlException ex) { Debug.WriteLine(ex); MessageBox.Show("数据库配置错误!"); } this.Enabled = true; m_statusLable.Text = "查询已成功完成"; }
/// <summary> /// 获取更新过的数据,包括增加的用户记录 /// </summary> private void GetUpdatedData() { try { // 标记为删除的就不需要添加的修改或者添加的分中心中了 List <int> listEditRows = new List <int>(); foreach (int item in base.m_listEditedRows) { if (!m_listMaskedDeletedRows.Contains(item)) { listEditRows.Add(item); } } // 将去重后的项赋给编辑项 base.m_listEditedRows = listEditRows; for (int i = 0; i < base.m_listEditedRows.Count; ++i) { CEntitySoilStation soilStation = new CEntitySoilStation(); soilStation.StationID = base.Rows[m_listEditedRows[i]].Cells[CS_StationId].Value.ToString(); soilStation.SubCenterID = CDBDataMgr.Instance.GetSubCenterByName(base.Rows[m_listEditedRows[i]].Cells[CS_StationSubcenter].Value.ToString()).SubCenterID; // soilStation.SubCenterID = Int32.Parse(base.Rows[m_listEditedRows[i]].Cells[CS_StationSubcenter].Value.ToString()); soilStation.StationName = base.Rows[m_listEditedRows[i]].Cells[CS_StationName].Value.ToString(); soilStation.VoltageMin = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_VoltageMin].Value.ToString()); soilStation.StationType = CEnumHelper.UIStrToStationType(base.Rows[m_listEditedRows[i]].Cells[CS_StationType].Value.ToString()); // soilStation.StrDeviceNumber = base.Rows[m_listEditedRows[i]].Cells[CS_DeviceNumber].Value.ToString(); soilStation.A10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A10].Value.ToString()); soilStation.A20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A20].Value.ToString()); soilStation.A30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A30].Value.ToString()); soilStation.A40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A40].Value.ToString()); soilStation.A60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A60].Value.ToString()); soilStation.B10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B10].Value.ToString()); soilStation.B20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B20].Value.ToString()); soilStation.B30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B30].Value.ToString()); soilStation.B40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B40].Value.ToString()); soilStation.B60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B60].Value.ToString()); soilStation.C10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C10].Value.ToString()); soilStation.C20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C20].Value.ToString()); soilStation.C30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C30].Value.ToString()); soilStation.C40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C40].Value.ToString()); soilStation.C60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C60].Value.ToString()); soilStation.D10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D10].Value.ToString()); soilStation.D20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D20].Value.ToString()); soilStation.D30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D30].Value.ToString()); soilStation.D40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D40].Value.ToString()); soilStation.D60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D60].Value.ToString()); soilStation.M10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M10].Value.ToString()); soilStation.M20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M20].Value.ToString()); soilStation.M30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M30].Value.ToString()); soilStation.M40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M40].Value.ToString()); soilStation.M60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M60].Value.ToString()); soilStation.N10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N10].Value.ToString()); soilStation.N20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N20].Value.ToString()); soilStation.N30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N30].Value.ToString()); soilStation.N40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N40].Value.ToString()); soilStation.N60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N60].Value.ToString()); soilStation.GSM = base.Rows[m_listEditedRows[i]].Cells[CS_Gsm].Value.ToString(); soilStation.GPRS = base.Rows[m_listEditedRows[i]].Cells[CS_Gprs].Value.ToString(); soilStation.BDSatellite = base.Rows[m_listEditedRows[i]].Cells[CS_BDsatellite].Value.ToString(); soilStation.BDMemberSatellite = base.Rows[m_listEditedRows[i]].Cells[CS_BDmember].Value.ToString(); soilStation.Maintran = base.Rows[m_listEditedRows[i]].Cells[CS_Maintran].Value.ToString(); soilStation.Subtran = base.Rows[m_listEditedRows[i]].Cells[CS_Subtran].Value.ToString(); soilStation.Datapotocol = base.Rows[m_listEditedRows[i]].Cells[CS_Dataprotocol].Value.ToString(); soilStation.Reportinterval = base.Rows[m_listEditedRows[i]].Cells[CS_Reportinterval].Value.ToString(); String preSoilStation = base.Rows[m_listEditedRows[i]].Cells[CS_StationId].Value.ToString(); if (preSoilStation == CS_PreStationId_None) { // 添加的新墒情站配置 m_listAddedSoilStation.Add(soilStation); } else { // 如果墒情站的测站id没有改变,那么是更新,如果发生了改变,那么需要先删除,然后添加新的 if (preSoilStation == soilStation.StationID) { m_listUpdatedSoilStation.Add(soilStation); } else { // 先删除之前的 m_listDeletedStation.Add(preSoilStation); m_listAddedSoilStation.Add(soilStation); //然后再添加新的墒情站 } } } m_listEditedRows.Clear(); //清空此次记录 } catch (Exception ex) { this.Hide(); MessageBox.Show("请在同一界面完成修改"); this.Show(); } }