Exemple #1
0
        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);
        }
        private void EH_MI_ExportToExcel_Click(object sender, EventArgs e)
        {
            // 弹出对话框,并导出到Excel文件
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "Excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
            if (DialogResult.OK == dlg.ShowDialog())
            {
                // 保存到Excel表格中
                DataTable dataTable = new DataTable();
                //   dataTable.Columns.Add(CS_VoltageID, typeof(Int64));
                dataTable.Columns.Add(CS_StationID);
                dataTable.Columns.Add(CS_StationName, typeof(string));
                dataTable.Columns.Add(CS_Voltage, typeof(string));
                dataTable.Columns.Add(CS_TimeCollected, typeof(DateTime));
                dataTable.Columns.Add(CS_TimeReceived, typeof(DateTime));
                dataTable.Columns.Add(CS_MsgType, typeof(string));
                dataTable.Columns.Add(CS_ChannelType, typeof(string));
                // 逐页读取数据
                for (int i = 0; i < m_iTotalPage; ++i)
                {
                    List <CEntityVoltage> tmpVoltages = m_proxyVoltage.GetPageData(i + 1);
                    foreach (CEntityVoltage voltage in tmpVoltages)
                    {
                        // 赋值到dataTable中去
                        DataRow row = dataTable.NewRow();
                        // row[CS_VoltageID] = voltage.VoltageID;
                        row[CS_StationID]     = voltage.StationID;
                        row[CS_StationName]   = CDBDataMgr.Instance.GetStationById(voltage.StationID).StationName;
                        row[CS_Voltage]       = voltage.Voltage;
                        row[CS_TimeCollected] = voltage.TimeCollect;
                        row[CS_TimeReceived]  = voltage.TimeRecieved;
                        row[CS_MsgType]       = CEnumHelper.MessageTypeToUIStr(voltage.MessageType);
                        row[CS_ChannelType]   = CEnumHelper.ChannelTypeToUIStr(voltage.ChannelType);
                        dataTable.Rows.Add(row);
                    }
                }
                // 显示提示框
                CMessageBox box = new CMessageBox()
                {
                    MessageInfo = "正在导出表格,请稍候"
                };
                box.ShowDialog(this);
                if (CExcelExport.ExportToExcelWrapper(dataTable, dlg.FileName, "电压表"))
                {
                    //box.Invoke((Action)delegate { box.Close(); });
                    box.CloseDialog();
                    MessageBox.Show(string.Format("导出成功,保存在文件\"{0}\"中", dlg.FileName));
                }
                else
                {
                    //box.Invoke((Action)delegate { box.Close(); });
                    box.CloseDialog();
                    MessageBox.Show("导出失败");
                }
            }//end of if dialog okay
        }
Exemple #3
0
        // 设置显示的雨量记录
        public void SetWaters(List <CEntityWaterSpeed> listWaterSpeed)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            base.m_dataTable.Rows.Clear();
            // 判断状态值
            List <string[]>   newRows = new List <string[]>();
            List <EDataState> states  = new List <EDataState>();

            if (!m_bIsEditable)
            {
                string[] newRow;
                // 只读模式
                for (int i = 0; i < listWaterSpeed.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listWaterSpeed[i].STCD);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    newRow = new string[]
                    {
                        strStationId,
                        strStationName,                                                /*站名*/
                        listWaterSpeed[i].DT.ToString(CS_TimeFormat),                  /*采集时间*/
                        listWaterSpeed[i].W1.ToString(),                               /*水位*/
                        listWaterSpeed[i].AvgV1.ToString(),                            /*水位*/
                        listWaterSpeed[i].AvgV2.ToString(),                            /*水位*/
                        listWaterSpeed[i].AvgV3.ToString(),                            /*水位*/
                        listWaterSpeed[i].AvgV4.ToString(),                            /*水位*/
                        listWaterSpeed[i].Q.ToString(),                                /*流量*/
                        listWaterSpeed[i].rawQ.ToString(),                             /*流量*/
                        state_1,
                        listWaterSpeed[i].RevtDT.ToString(CS_TimeFormat),              /*接收时间*/
                        CEnumHelper.ChannelTypeToUIStr(listWaterSpeed[i].ChannelType), /*通讯方式*/
                        CEnumHelper.MessageTypeToUIStr(listWaterSpeed[i].MessageType), /*报文类型*/
                    };



                    newRows.Add(newRow);
                    states.Add(state);
                }
                // 添加到集合的数据表中
                base.AddRowRange(newRows, states);
            }
            else
            {
                // 添加到集合的数据表中
                base.AddRowRange(newRows, states);
            }
        }
Exemple #4
0
        private void InitUI()
        {
            this.SuspendLayout();
            //
            // cmb_StationType
            //
            this.groupBox1.Controls.Remove(this.cmb_StationId);
            this.cmb_StationId = new CStationComboBox();
            this.cmb_StationId.FormattingEnabled = true;
            this.cmb_StationId.Location          = new System.Drawing.Point(88, 20);
            this.cmb_StationId.Name     = "cmb_StationId";
            this.cmb_StationId.Size     = new System.Drawing.Size(148, 20);
            this.cmb_StationId.TabIndex = 1;
            (this.cmb_StationId as CStationComboBox).StationSelected += new EventHandler <CEventSingleArgs <CEntityStation> >(EHStationChanged);
            this.groupBox1.Controls.Add(this.cmb_StationId);

            // 接受时间和采集时间
            dtp_CollectTime.Value  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, 0, 0);
            dtp_TimeReceived.Value = DateTime.Now;

            // 数据协议
            cmb_DataType.Items.Add(CEnumHelper.MessageTypeToUIStr(EMessageType.ETimed));
            cmb_DataType.Items.Add(CEnumHelper.MessageTypeToUIStr(EMessageType.EAdditional));

            // 信道协议
            //cmb_ChannelType.Items.Add(CEnumHelper.ChannelTypeToUIStr(EChannelType.None));
            //cmb_ChannelType.Items.Add(CEnumHelper.ChannelTypeToUIStr(EChannelType.GPRS));
            //cmb_ChannelType.Items.Add(CEnumHelper.ChannelTypeToUIStr(EChannelType.GSM));
            //cmb_ChannelType.Items.Add(CEnumHelper.ChannelTypeToUIStr(EChannelType.BeiDou));
            //cmb_ChannelType.Items.Add(CEnumHelper.ChannelTypeToUIStr(EChannelType.PSTN));
            cmb_ChannelType.Items.Add(CEnumHelper.ChannelTypeToUIStr(EChannelType.None));
            cmb_ChannelType.SelectedIndex = 0;
            cmb_ChannelType.Enabled       = false; //只能为无

            // 数值都是不可编辑的
            number_Voltage.Enabled = false; //电压

            number_PeriodRain.Enabled = false;
            number_DayRain.Enabled    = false;
            number_TotalRain.Enabled  = false;

            number_WaterStage.Enabled = false;
            number_WaterFlow.Enabled  = false;

            cmb_AddDataType.Visible = false;    // 不可见,已经废弃

            // 绑定消息
            chk_Rain.CheckedChanged    += new EventHandler(EHRainChecked);
            chk_Water.CheckedChanged   += new EventHandler(EHWaterChecked);
            chk_Voltage.CheckedChanged += new EventHandler(EHVoltageChecked);

            // 初始化焦点切换
            FormHelper.InitControlFocusLoop(this);

            this.ResumeLayout(false);
        }
        public void SetWaters(List <CEntityTSWater> listWater)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            base.m_dataTable.Rows.Clear();
            // 判断状态值
            List <string[]>   newRows = new List <string[]>();
            List <EDataState> states  = new List <EDataState>();

            for (int i = 0; i < listWater.Count; ++i)
            {
                EDataState state;
                double     rate = 0.5;
                state = GetState(rate);
                string         strStationName = "";
                string         strStationId   = "";
                CEntityStation station        = CDBDataMgr.Instance.GetStationById(listWater[i].StationID);
                if (null != station)
                {
                    strStationName = station.StationName;
                    strStationId   = station.StationID;
                }

                string[] newRow = new string[]
                {
                    strStationId,
                    strStationName,                                           /*站名*/
                    listWater[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                    listWater[i].WaterStage.ToString(),                       /*水位*/
                    listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                    CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                    CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)  /*报文类型*/
                };
                newRows.Add(newRow);
                states.Add(state);
            }
            base.ClearAllRows();
            base.AddRowRange(newRows, states);
            base.UpdateDataToUI();
        }
        // 设置显示的雨量记录
        public void SetWaters(List <CEntityWater> listWater)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            base.m_dataTable.Rows.Clear();
            // 判断状态值
            List <string[]>   newRows = new List <string[]>();
            List <EDataState> states  = new List <EDataState>();

            if (!m_bIsEditable)
            {
                string[] newRow;
                // 只读模式
                for (int i = 0; i < listWater.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listWater[i].StationID);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    if (listWater[i].state == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    //水位可以小于0,流量不行
                    //if (listWater[i].WaterFlow < 0 && listWater[i].WaterStage !=-9999)
                    //{
                    //    newRow = new string[]
                    //        {
                    //            strStationId,
                    //            strStationName,/*站名*/
                    //            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                    //            listWater[i].WaterStage.ToString(), /*水位*/
                    //             "--",
                    //            listWater[i].TimeRecieved.ToString(CS_TimeFormat), /*接收时间*/
                    //            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                    //            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType) /*报文类型*/
                    //        };
                    //}
                    if (listWater[i].WaterStage == -9999 && listWater[i].WaterFlow > 0)
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                                             /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat),                           /*采集时间*/
                            "--",                                                                       /*水位*/
                            listWater[i].WaterFlow.HasValue?listWater[i].WaterFlow.Value.ToString():"", /*流量*/
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),                          /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType),                   /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)                    /*报文类型*/
                        };
                    }
                    else if (listWater[i].WaterStage != -9999 && listWater[i].WaterFlow < 0)
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                   /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                            listWater[i].WaterStage.ToString(),               /*水位*/
                            "--",
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)  /*报文类型*/
                        };
                    }
                    else if (listWater[i].WaterStage == -9999 && listWater[i].WaterFlow < 0)
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                   /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                            "--",
                            "--",
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)  /*报文类型*/
                        };
                    }
                    else
                    {
                        newRow = new string[]
                        {
                            m_strStaionId,
                            strStationName,                                           /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                            listWater[i].WaterStage.ToString(),                       /*水位*/
                            listWater[i].WaterFlow.ToString(),                        /*流量*/
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType), /*报文类型*/
                            //        listWater[i].WaterID.ToString() /*水量ID*/
                        };
                    }
                    newRows.Add(newRow);
                    states.Add(state);
                }
                // 添加到集合的数据表中
                base.AddRowRange(newRows, states);
            }
            else
            {
                string[] newRow;
                // 编辑模式,需要将更新的数据和删除的数据,与当前数据进行合并
                for (int i = 0; i < listWater.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listWater[i].StationID);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                    }
                    if (listWater[i].state == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    //    string[] newRow = new string[]
                    //    {
                    //        "False", /*未选中*/
                    //        m_strStaionId,
                    //        strStationName,/*站名*/
                    //        listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                    //        listWater[i].WaterStage.ToString(), /*水位*/
                    //        listWater[i].WaterFlow.ToString(), /*流量*/
                    //        listWater[i].TimeRecieved.ToString(CS_TimeFormat), /*接收时间*/
                    //        CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                    //        CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType), /*报文类型*/
                    ////        listWater[i].WaterID.ToString() /*水量ID*/
                    //    };

                    if (listWater[i].WaterStage == -9999 && listWater[i].WaterFlow > 0)
                    {
                        newRow = new string[]
                        {
                            "False",                                                                    /*未选中*/
                            m_strStaionId,
                            strStationName,                                                             /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat),                           /*采集时间*/
                            "",                                                                         /*水位*/
                            listWater[i].WaterFlow.HasValue?listWater[i].WaterFlow.Value.ToString():"", /*流量*/
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),                          /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType),                   /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)                    /*报文类型*/
                        };
                    }
                    else if (listWater[i].WaterStage != -9999 && listWater[i].WaterFlow < 0)
                    {
                        newRow = new string[]
                        {
                            "False",                                          /*未选中*/
                            m_strStaionId,
                            strStationName,                                   /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                            listWater[i].WaterStage.ToString(),               /*水位*/
                            "",
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)  /*报文类型*/
                        };
                    }
                    else if (listWater[i].WaterStage == -9999 && listWater[i].WaterFlow < 0)
                    {
                        newRow = new string[]
                        {
                            "False",                                          /*未选中*/
                            m_strStaionId,
                            strStationName,                                   /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat), /*采集时间*/
                            "",
                            "",
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType)  /*报文类型*/
                        };
                    }
                    else
                    {
                        newRow = new string[]
                        {
                            "False",                                                  /*未选中*/
                            m_strStaionId,
                            strStationName,                                           /*站名*/
                            listWater[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                            listWater[i].WaterStage.ToString(),                       /*水位*/
                            listWater[i].WaterFlow.ToString(),                        /*流量*/
                            state_1,
                            listWater[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listWater[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listWater[i].MessageType), /*报文类型*/
                            //        listWater[i].WaterID.ToString() /*水量ID*/
                        };
                    }
                    newRows.Add(newRow);
                    states.Add(state);
                }
                // 添加到集合的数据表中
                base.AddRowRange(newRows, states);
            }
        }
        // 设置显示的电压记录
        public void SetVoltage(List <CEntityVoltage> listVoltage)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            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 < listVoltage.Count; ++i)
                {
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listVoltage[i].StationID);
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    if (station != null)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    EDataState state = EDataState.ENormal; //默认所有数据都是正常的
                    string[]   newRow;
                    if (listVoltage[i].state == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    if (listVoltage[i].Voltage < 0)
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                             /*站名*/
                            listVoltage[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                            "--",                                                       /*电压值*/
                            state_1,
                            listVoltage[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listVoltage[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listVoltage[i].MessageType)  /*报文类型*/
                        };
                    }
                    else
                    {
                        newRow = new string[]
                        {
                            strStationId,
                            strStationName,                                             /*站名*/
                            listVoltage[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                            listVoltage[i].Voltage.ToString(),                          /*电压值*/
                            state_1,
                            listVoltage[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                            CEnumHelper.ChannelTypeToUIStr(listVoltage[i].ChannelType), /*通讯方式*/
                            CEnumHelper.MessageTypeToUIStr(listVoltage[i].MessageType)  /*报文类型*/
                        };
                    }
                    newRows.Add(newRow);
                    states.Add(state);
                }
            }
            else
            {
                // 编辑模式,需要将更新的数据和删除的数据,与当前数据进行合并
                for (int i = 0; i < listVoltage.Count; ++i)
                {
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listVoltage[i].StationID);
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    if (station != null)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    EDataState state = EDataState.ENormal; //默认所有数据都是正常的
                    if (listVoltage[i].state == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    string[] newRow = new string[]
                    {
                        "False",                                                    /*未选中*/
                        strStationId,
                        strStationName,                                             /*站名*/
                        listVoltage[i].TimeCollect.ToString(CS_TimeFormat),         /*采集时间*/
                        listVoltage[i].Voltage.ToString(),                          /*电压值*/
                        state_1,
                        listVoltage[i].TimeRecieved.ToString(CS_TimeFormat),        /*接收时间*/
                        CEnumHelper.ChannelTypeToUIStr(listVoltage[i].ChannelType), /*通讯方式*/
                        CEnumHelper.MessageTypeToUIStr(listVoltage[i].MessageType), /*报文类型*/
                        //     listVoltage[i].VoltageID.ToString() /*电压ID,不可见,隐藏列*/
                    };
                    newRows.Add(newRow);
                    states.Add(state);
                }
            }
            // 添加到集合的数据表中
            base.AddRowRange(newRows, states);
        }
        // 设置显示的雨量记录
        public void SetRain(List <CEntityRain> listRain)
        {
            // 清空所有数据,是否一定要这样?好像可以考虑其它方式
            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 < listRain.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listRain[i].StationID);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }

                    if (listRain[i].BState == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    else if (listRain[i].BState == 2)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EWarning;//黄色显示
                        state_1 = CS_DataState_Warning;
                    }
                    string[] newRow = new string[]
                    {
                        strStationId,
                        strStationName,
                        listRain[i].TimeCollect.ToString(CS_TimeFormat),                          /*采集时间*/
                        listRain[i].TotalRain.ToString(),                                         /*累计雨量*/
                        (listRain[i].DifferneceRain < 0?0:listRain[i].DifferneceRain).ToString(), /*差值雨量*/
                        (listRain[i].PeriodRain < 0?0:listRain[i].PeriodRain).ToString(),         /*时段雨量*/
                        (listRain[i].DayRain < 0?0:listRain[i].DayRain).ToString(),               /*日雨量,貌似只有8点钟才有,注意*/
                        state_1,
                        listRain[i].TimeRecieved.ToString(CS_TimeFormat),                         /*接收时间*/
                        CEnumHelper.ChannelTypeToUIStr(listRain[i].ChannelType),                  /*通讯方式*/
                        CEnumHelper.MessageTypeToUIStr(listRain[i].MessageType)                   /*报文类型*/
                    };

                    newRows.Add(newRow);
                    states.Add(state);
                }
            }
            else
            {
                // 编辑模式,需要将更新的数据和删除的数据,与当前数据进行合并,不弄这个
                for (int i = 0; i < listRain.Count; ++i)
                {
                    EDataState     state          = EDataState.ENormal; //默认所有数据都是正常的
                    string         strStationName = "";
                    string         strStationId   = "";
                    string         state_1        = CS_DataState_Normal;
                    CEntityStation station        = CDBDataMgr.Instance.GetStationById(listRain[i].StationID);
                    if (null != station)
                    {
                        strStationName = station.StationName;
                        strStationId   = station.StationID;
                    }
                    if (listRain[i].BState == 0)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EError;//红色显示
                        state_1 = CS_DataState_AbNormal;
                    }
                    else if (listRain[i].BState == 2)
                    {
                        // 不正常
                        state   = CExDataGridView.EDataState.EWarning;//黄色显示
                        state_1 = CS_DataState_Warning;
                    }
                    string[] newRow = new string[]
                    {
                        "False",                                                                  /*未选中*/
                        strStationId,
                        strStationName,                                                           /*站名*/
                        listRain[i].TimeCollect.ToString(CS_TimeFormat),                          /*采集时间*/
                        listRain[i].TotalRain.ToString(),                                         /*累计雨量*/
                        (listRain[i].DifferneceRain < 0?0:listRain[i].DifferneceRain).ToString(), /*差值雨量*/
                        (listRain[i].PeriodRain < 0?0:listRain[i].PeriodRain).ToString(),         /*时段雨量*/
                        (listRain[i].DayRain < 0?0:listRain[i].DayRain).ToString(),               /*日雨量,貌似只有8点钟才有,注意*/
                        state_1,
                        listRain[i].TimeRecieved.ToString(CS_TimeFormat),                         /*接收时间*/
                        CEnumHelper.ChannelTypeToUIStr(listRain[i].ChannelType),                  /*通讯方式*/
                        CEnumHelper.MessageTypeToUIStr(listRain[i].MessageType),                  /*报文类型*/
                        //    listRain[i].RainID.ToString() /*雨量ID*/
                    };

                    newRows.Add(newRow);
                    states.Add(state);
                }
            }
            // 添加到集合的数据表中
            base.AddRowRange(newRows, states);
        }
 private void EH_MI_ExportToExcel_Click(object sender, EventArgs e)
 {
     try
     {
         // 弹出对话框,并导出到Excel文件
         SaveFileDialog dlg = new SaveFileDialog();
         dlg.Filter = "Excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
         if (DialogResult.OK == dlg.ShowDialog())
         {
             // 保存到Excel表格中
             DataTable dataTable = new DataTable();
             //CS_StationID,CS_StationName
             //  dataTable.Columns.Add(CS_RainID, typeof(Int64));
             dataTable.Columns.Add(CS_StationID);
             dataTable.Columns.Add(CS_StationName, typeof(string));
             dataTable.Columns.Add(CS_TotalRain, typeof(string));
             dataTable.Columns.Add(CS_DifferenceRain, typeof(string));
             dataTable.Columns.Add(CS_DayRain, typeof(string));
             // dataTable.Columns.Add(CS_PeriodRain, typeof(Decimal));
             dataTable.Columns.Add(CS_PeriodRain, typeof(string));
             dataTable.Columns.Add(CS_DataState, typeof(string));
             dataTable.Columns.Add(CS_TimeCollected, typeof(DateTime));
             dataTable.Columns.Add(CS_TimeReceived, typeof(DateTime));
             dataTable.Columns.Add(CS_MsgType, typeof(string));
             dataTable.Columns.Add(CS_ChannelType, typeof(string));
             // 逐页读取数据
             for (int i = 0; i < m_iTotalPage; ++i)
             {
                 List <CEntityRain> tmpRains = m_proxyRain.GetPageData(i + 1);
                 foreach (CEntityRain rain in tmpRains)
                 {
                     // 赋值到dataTable中去
                     DataRow row = dataTable.NewRow();
                     //  row[CS_RainID] = rain.RainID;
                     row[CS_StationID]     = rain.StationID;
                     row[CS_StationName]   = CDBDataMgr.Instance.GetStationById(rain.StationID).StationName;
                     row[CS_DayRain]       = rain.DayRain;
                     row[CS_TotalRain]     = rain.TotalRain;
                     row[CS_DayRain]       = rain.DayRain;
                     row[CS_PeriodRain]    = rain.PeriodRain;
                     row[CS_DataState]     = rain.BState == 1 ? "正常" : "不正常";
                     row[CS_TimeCollected] = rain.TimeCollect;
                     row[CS_TimeReceived]  = rain.TimeRecieved;
                     row[CS_MsgType]       = CEnumHelper.MessageTypeToUIStr(rain.MessageType);
                     row[CS_ChannelType]   = CEnumHelper.ChannelTypeToUIStr(rain.ChannelType);
                     dataTable.Rows.Add(row);
                 }
             }
             // 显示提示框
             CMessageBox box = new CMessageBox()
             {
                 MessageInfo = "正在导出表格,请稍候"
             };
             box.ShowDialog(this);
             if (CExcelExport.ExportToExcelWrapper(dataTable, dlg.FileName, "雨量表"))
             {
                 //box.Invoke((Action)delegate { box.Close(); });
                 box.CloseDialog();
                 MessageBox.Show(string.Format("导出成功,保存在文件\"{0}\"中", dlg.FileName));
             }
             else
             {
                 //box.Invoke((Action)delegate { box.Close(); });
                 box.CloseDialog();
                 MessageBox.Show("导出失败");
             }
         }//end of if dialog okay
     }
     catch (Exception ex)
     {
         MessageBox.Show("导出失败" + ex.ToString());
     }
 }
Exemple #10
0
        private List <string> GetUIShowStringList(CEntityRealTime entity)
        {
            List <string> result = new List <string>();
            TimeSpan      span   = entity.TimeReceived - entity.TimeDeviceGained;

            //表格头部信息
            //this.Header = new string[]
            //{
            //    CS_StationName, CS_StationId, CS_StationType, CS_TimeCollected, CS_DelayTime,
            //    CS_TodayRain, CS_LastdayRain,CS_PeriodRain, CS_WaterLevel,CS_V1,CS_V2,CS_V3,CS_V4, CS_WaterFlowActual,CS_WaterFlowFindInTable,
            //    CS_Volatage,CS_Port, CS_MsgType, CS_ChannelType
            //};

            result.Add(entity.StrStationName);                                                   //站名
            result.Add(entity.StrStationID.ToString());                                          //站号
            result.Add(CEnumHelper.StationTypeToUIStr(entity.EIStationType));                    //站类
            result.Add(entity.TimeDeviceGained.ToString());                                      //数据时间
            result.Add(string.Format("{0}m{1}s", span.Hours * 60 + span.Minutes, span.Seconds)); //延迟时间
            //if (entity.DDayRainFall.HasValue)
            //{
            //    result.Add(entity.DDayRainFall.Value.ToString("0.00"));/*今日雨量,计算*/
            //}
            //else
            //{
            //    result.Add(CS_NullUIStr);
            //}
            result.Add(CS_NullUIStr);//今日雨量
            //if (entity.LastDayRainFall.HasValue)
            //{
            //    result.Add(entity.LastDayRainFall.Value.ToString("0.00"));/*昨日雨量,计算*/
            //}
            //else
            //{
            //    result.Add(CS_NullUIStr);
            //}
            result.Add(CS_NullUIStr);//昨日雨量
            //if (entity.DPeriodRain.HasValue)
            //{
            //    if (entity.DPeriodRain.Value >= 0)
            //    {
            //        result.Add(entity.DPeriodRain.Value.ToString("0.00"));/*时段雨量,计算*/
            //    }
            //    else
            //    {
            //        result.Add("0.00");
            //    }
            //}
            //else
            //{
            //    result.Add(CS_NullUIStr);
            //}
            result.Add(CS_NullUIStr);//时段雨量

            //水位
            if (entity.DWaterYield.HasValue)
            {
                if (entity.DDayRainFall != (decimal) - 20000)
                {
                    result.Add(entity.DWaterYield.Value.ToString("0.00"));/*水位*/
                }
                else
                {
                    result.Add(CS_NullUIStr);
                }
            }
            else
            {
                result.Add(CS_NullUIStr);
            }



            //流速1
            if (entity.DV1.HasValue)
            {
                result.Add(entity.DV1.Value.ToString("0.000"));
            }
            else
            {
                result.Add(CS_NullUIStr);
            }

            //流速2
            if (entity.DV2.HasValue)
            {
                result.Add(entity.DV2.Value.ToString("0.000"));
            }
            else
            {
                result.Add(CS_NullUIStr);
            }

            //流速3
            if (entity.DV3.HasValue)
            {
                result.Add(entity.DV3.Value.ToString("0.000"));
            }
            else
            {
                result.Add(CS_NullUIStr);
            }

            //流速4
            if (entity.DV4.HasValue)
            {
                result.Add(entity.DV4.Value.ToString("0.000"));
            }
            else
            {
                result.Add(CS_NullUIStr);
            }

            //实测流量
            if (entity.DWaterFlowActual.HasValue)
            {
                result.Add(entity.DWaterFlowActual.Value.ToString("0.00"));/*实测流量*/
            }
            else
            {
                result.Add(CS_NullUIStr);
            }


            if (entity.DWaterFlowFindInTable.HasValue)
            {
                result.Add(entity.DWaterFlowFindInTable.Value.ToString("0.00"));/*相应流量*/
            }
            else
            {
                result.Add(CS_NullUIStr);/*相应流量*/
            }
            //result.Add(CS_NullUIStr); //相应流量

            result.Add(entity.Dvoltage.ToString());/*电压*/
            result.Add(entity.StrPort);
            result.Add(CEnumHelper.MessageTypeToUIStr(entity.EIMessageType));
            result.Add(CEnumHelper.ChannelTypeToUIStr(entity.EIChannelType));
            return(result);
        }
        private List <string> GetUIShowStringList(CEntityRealTime entity)
        {
            List <string> result = new List <string>();
            TimeSpan      span   = entity.TimeReceived - entity.TimeDeviceGained;

            result.Add(entity.StrStationName);
            result.Add(entity.StrStationID.ToString());
            result.Add(CEnumHelper.StationTypeToUIStr(entity.EIStationType));
            result.Add(entity.TimeDeviceGained.ToString());
            result.Add(string.Format("{0}m{1}s", span.Hours * 60 + span.Minutes, span.Seconds));
            if (entity.DDayRainFall.HasValue)
            {
                result.Add(entity.DDayRainFall.Value.ToString("0.00"));/*今日雨量,计算*/
            }
            else
            {
                result.Add(CS_NullUIStr);
            }
            if (entity.LastDayRainFall.HasValue)
            {
                result.Add(entity.LastDayRainFall.Value.ToString("0.00"));/*昨日雨量,计算*/
            }
            else
            {
                result.Add(CS_NullUIStr);
            }
            if (entity.DPeriodRain.HasValue)
            {
                if (entity.DPeriodRain.Value >= 0)
                {
                    result.Add(entity.DPeriodRain.Value.ToString("0.00"));/*时段雨量,计算*/
                }
                else
                {
                    result.Add("0.00");
                }
            }
            else
            {
                result.Add(CS_NullUIStr);
            }
            if (entity.DWaterYield.HasValue)
            {
                if (entity.DDayRainFall != (decimal) - 20000)
                {
                    result.Add(entity.DWaterYield.Value.ToString("0.00"));/*水位*/
                }
                else
                {
                    result.Add(CS_NullUIStr);
                }
            }
            else
            {
                result.Add(CS_NullUIStr);
            }
            if (entity.DWaterFlowActual.HasValue)
            {
                result.Add(entity.DWaterFlowActual.Value.ToString("0.00"));/*实测流量*/
            }
            else
            {
                result.Add(CS_NullUIStr);
            }
            if (entity.DWaterFlowFindInTable.HasValue)
            {
                result.Add(entity.DWaterFlowFindInTable.Value.ToString("0.00"));/*相应流量*/
            }
            else
            {
                result.Add(CS_NullUIStr);/*相应流量*/
            }


            result.Add(entity.Dvoltage.ToString());/*电压*/
            result.Add(entity.StrPort);
            result.Add(CEnumHelper.MessageTypeToUIStr(entity.EIMessageType));
            result.Add(CEnumHelper.ChannelTypeToUIStr(entity.EIChannelType));
            return(result);
        }
        //11.12
        private void EH_MI_ExportToExcel_Click(object sender, EventArgs e)
        {
            // 弹出对话框,并导出到Excel文件
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "Excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
            if (DialogResult.OK == dlg.ShowDialog())
            {
                // 保存到Excel表格中
                DataTable dataTable = new DataTable();
                //   dataTable.Columns.Add(CS_VoltageID, typeof(Int64));
                dataTable.Columns.Add(CS_StationID);
                dataTable.Columns.Add(CS_StationName, typeof(string));
                dataTable.Columns.Add(CS_TimeCollected, typeof(DateTime));
                dataTable.Columns.Add(CS_Voltage, typeof(string));
                dataTable.Columns.Add(CS_V10, typeof(string));
                dataTable.Columns.Add(CS_M10, typeof(string));
                dataTable.Columns.Add(CS_V20, typeof(string));
                dataTable.Columns.Add(CS_M20, typeof(string));
                dataTable.Columns.Add(CS_V30, typeof(string));
                dataTable.Columns.Add(CS_M30, typeof(string));
                dataTable.Columns.Add(CS_V40, typeof(string));
                dataTable.Columns.Add(CS_M40, typeof(string));
                dataTable.Columns.Add(CS_V60, typeof(string));
                dataTable.Columns.Add(CS_M60, typeof(string));
                dataTable.Columns.Add(CS_ReciveTime, typeof(DateTime));
                dataTable.Columns.Add(CS_MsgType, typeof(string));
                dataTable.Columns.Add(CS_ChannelType, typeof(string));
                // 逐页读取数据
                for (int i = 0; i < m_iTotalPage; ++i)
                {
                    List <CEntitySoilData> tmpListData = m_proxySoilData.QueryByStationAndTime(m_strStaionId, m_dateTimeStart, m_dateTimeEnd);
                    foreach (CEntitySoilData soilData in tmpListData)
                    {
                        // 赋值到dataTable中去
                        DataRow row = dataTable.NewRow();
                        // row[CS_VoltageID] = voltage.VoltageID;
                        row[CS_StationID]     = soilData.StationID;
                        row[CS_StationName]   = CDBSoilDataMgr.Instance.GetSoilStationInfoByStationId(soilData.StationID).StationName;
                        row[CS_TimeCollected] = soilData.DataTime;
                        row[CS_Voltage]       = soilData.DVoltage;
                        row[CS_V10]           = soilData.Voltage10;
                        row[CS_M10]           = soilData.Voltage10;
                        row[CS_V20]           = soilData.Voltage20;
                        row[CS_M20]           = soilData.Voltage20;
                        row[CS_V40]           = soilData.Voltage40;
                        row[CS_M40]           = soilData.Voltage40;
                        row[CS_V60]           = soilData.Voltage60;
                        row[CS_M60]           = soilData.Voltage60;
                        row[CS_ReciveTime]    = soilData.reciveTime;
                        row[CS_MsgType]       = CEnumHelper.MessageTypeToUIStr(soilData.MessageType);
                        row[CS_ChannelType]   = CEnumHelper.ChannelTypeToUIStr(soilData.ChannelType);
                        dataTable.Rows.Add(row);
                    }
                }
                // 显示提示框
                CMessageBox box = new CMessageBox()
                {
                    MessageInfo = "正在导出表格,请稍候"
                };
                box.ShowDialog(this);
                if (CExcelExport.ExportToExcelWrapper(dataTable, dlg.FileName, "电压表"))
                {
                    //box.Invoke((Action)delegate { box.Close(); });
                    box.CloseDialog();
                    MessageBox.Show(string.Format("导出成功,保存在文件\"{0}\"中", dlg.FileName));
                }
                else
                {
                    //box.Invoke((Action)delegate { box.Close(); });
                    box.CloseDialog();
                    MessageBox.Show("导出失败");
                }
            }//end of if dialog okay
        }
        // 设置显示的雨量记录
        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);
        }