コード例 #1
0
        private void tsButImport_Click(object sender, EventArgs e)
        {
            // 从文件中导入,格式如(1,212.23,2230.344),如果不对,不导入
            OpenFileDialog dlg = new OpenFileDialog();

            try
            {
                dlg.Title  = "选择水情测站文件";
                dlg.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
                DialogResult result = dlg.ShowDialog();
                if (DialogResult.OK == result)
                {
                    // 打开文件,并进行处理
                    CMessageBox msgBox = new CMessageBox()
                    {
                        MessageInfo = "正在处理数据"
                    };
                    msgBox.ShowDialog(this);
                    StreamReader reader = new StreamReader(dlg.FileName, Encoding.Default);
                    string       linebuffer;
                    int          linenumber   = 0;
                    string       strErrorInfo = "";
                    while ((linebuffer = reader.ReadLine()) != null)
                    {
                        // 处理一行数据
                        linenumber += 1;
                        if (!DealWithLineData(linebuffer, linenumber, ref strErrorInfo))
                        {
                            // 数据非法
                            msgBox.CloseDialog();
                            MessageBox.Show(strErrorInfo); // 显示错误信息
                            return;
                        }
                    }
                    reader.Close();
                    msgBox.CloseDialog();
                    MessageBox.Show("数据导入成功");
                }//end of ok
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            finally
            {
                this.Focus(); //防止窗体最小化
            }
        }
コード例 #2
0
        private void search_Click(object sender, EventArgs e)
        {
            //获取 radioButton 的table类型值;
            string tableType = getType();

            // 获取分中心
            string subcenterName = center.Text;
            //获取时间  date.value;

            // 获取站点信息 默认为全部站点
            List <string> stationSelected = new List <string>();

            for (int i = 0; i < stationSelect.Items.Count; i++)
            {
                if (stationSelect.GetItemChecked(i))
                {
                    stationSelected.Add(stationSelect.GetItemText(stationSelect.Items[i]));
                }
            }
            string TargetStation = stationSelected[0];

            string[] targetArray = TargetStation.Split('|');
            string   StationID   = targetArray[0];
            string   StationName = targetArray[1];
            DateTime dt1         = date.Value;
            DateTime dt          = dt1.Date;
            int      year        = dt.Year;
            int      Month       = dt.Month;
            int      days        = DateTime.DaysInMonth(dt.Year, dt.Month);
            DateTime Temp        = new DateTime(year, 1, 1, 9, 0, 0);

            if (tableType.Equals("雨  量"))
            {
                CMessageBox box = new CMessageBox();
                box.MessageInfo = "正在查询数据库";
                box.ShowDialog(this);
                this.Enabled = false;
                m_OneRainYear.SetFilter(StationID, Temp);
                m_OneRainYear.Visible = true;
                this.Enabled          = true;
                box.CloseDialog();
                this.Enabled = true;
            }
            if (tableType.Equals("水  位"))
            {
                CMessageBox box = new CMessageBox();
                box.MessageInfo = "正在查询数据库";
                box.ShowDialog(this);
                this.Enabled = false;
                m_OneWaterYear.SetFilter(StationID, Temp);
                m_OneWaterYear.Visible = true;
                this.Enabled           = true;
                box.CloseDialog();
                this.Enabled = true;
            }
            if (tableType.Equals("熵  情"))
            {
            }
        }
コード例 #3
0
        private bool DoSave()
        {
            CMessageBox box = new CMessageBox()
            {
                MessageInfo = "正在保存"
            };

            box.ShowDialog(this);
            bool result = true;

            //if (m_listImport.Count > 0)
            //{
            //    result = result && m_proxyWaterFlowMap.AddRange(m_listImport);
            //}
            if (m_listAdded.Count > 0)
            {
                result = result && m_proxyWaterFlowMap.AddRange(m_listAdded);
                m_listImport.Clear();
            }
            if (m_listUpated.Count > 0)
            {
                result = result && m_proxyWaterFlowMap.UpdateRange(m_listUpated);
            }
            if (m_listDeleted.Count > 0)
            {
                //       result = result && m_proxyWaterFlowMap.DeleteRange(m_listDeleted);
            }
            box.CloseDialog();
            if (result)
            {
                CMessageBox box2 = new CMessageBox();
                box2.MessageInfo = "正在更新数据";
                box2.ShowDialog(this);
                // 清空所有内容,和状态
                m_mapStationDGVStatus.Clear();
                // 通知DataMgr修改
                CDBDataMgr.Instance.UpdateStationWaterFlowMap();
                box2.CloseDialog();
                MessageBox.Show("保存成功");
            }
            else
            {
                MessageBox.Show("保存失败");
            }
            return(result);
        }
コード例 #4
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            // 判断分中心是否为空
            if (comboBox1.Text.Equals(""))
            {
                MessageBox.Show("请选择分中心");
                return;
            }
            string subcenterName = comboBox1.Text;

            if (comboBox1.Text == CS_Subcenter_All)
            {
                subcenterName = null;
            }
            // 判断报表类型是否为空
            if (TabelType.Text.Equals(""))
            {
                MessageBox.Show("请选择报表类型");
                return;
            }
            CMessageBox box = new CMessageBox();

            box.MessageInfo = "正在查询数据库";
            box.ShowDialog(this);
            this.Enabled = false;
            if (TabelType.Text.Equals(CS_ReportType_Day))
            {
                // 日报表
                m_dgvDayReport.SetFilter(subcenterName, DateTimer.Value);
                //lblToolTip.Text = string.Format("畅通率统计  低于95%: {0}个,满足95%:{1}个,共{2}个",
                //    m_dgvDayReport.TotalCount - m_dgvDayReport.MoreThan95Count,
                //    m_dgvDayReport.MoreThan95Count,
                //    m_dgvDayReport.TotalCount);
            }
            else
            {
                // 月报表
                m_dgvMonthReport.SetFilter(subcenterName, DateTimer.Value);
                //lblToolTip.Text = string.Format("畅通率统计  低于95%: {0}个,满足95%:{1}个,共{2}个",
                //    m_dgvMonthReport.TotalCount - m_dgvMonthReport.MoreThan95Count,
                //    m_dgvMonthReport.MoreThan95Count,
                //    m_dgvMonthReport.TotalCount);
            }
            this.Enabled = true;
            box.CloseDialog();
        }
コード例 #5
0
        private void CDatabaseConfigForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            // 判断当前配置是否已经配置成功
            if (CDBManager.Instance.TryToConnection())
            {
                // 继续关闭窗口
                // 判断数据库是否已经切换,如果是的话,需要重新加载界面和生成数据
                if (m_strDatabaseName != CDBManager.Instance.DataBaseName || m_strDataSource != CDBManager.Instance.DataSource)
                {
                    // 显示提示页面
                    CMessageBox box = new CMessageBox()
                    {
                        MessageInfo = "正在切换数据库,请耐心等待"
                    };
                    box.ShowDialog(this);
                    // 先更新分中心
                    //CDBDataMgr.Instance.UpdateAllSubCenter();
                    // 再更新站点信息
                    //CDBDataMgr.Instance.UpdateAllStation();
                    CDBSoilDataMgr.Instance.ReloadDatabase();
                    CDBDataMgr.Instance.ReloadDatabase();

                    //box.Invoke((Action)delegate { box.Close(); });
                    box.CloseDialog();

                    // 写入日志文件
                    CSystemInfoMgr.Instance.AddInfo(string.Format("切换数据库,从 {0}:{1} 切换到 {2}:{3} ",
                                                                  m_strDataSource, m_strDatabaseName, CDBManager.Instance.DataSource, CDBManager.Instance.DataBaseName));
                }
            }
            else
            {
                // 当前配置不正确,是否继续退出
                if (MessageBox.Show("数据库配置失败,是否仍然退出配置?", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    e.Cancel = true;
                }
            }
        }
コード例 #6
0
        private void export_Click(object sender, EventArgs e)
        {
            DateTime startTimeTmp = DateTimer.Value;
            DateTime endTimeTmp   = endDateTime.Value;
            DateTime startTime    = new DateTime(startTimeTmp.Year, startTimeTmp.Month, startTimeTmp.Day, 0, 0, 0);
            DateTime endTime      = new DateTime(endTimeTmp.Year, endTimeTmp.Month, endTimeTmp.Day, 0, 0, 0);
            // 获取是雨量还是水位类型
            string type = getType();
            // 获取被选择的站点
            // 获取站点信息 默认为全部站点
            List <string> stationSelected = new List <string>();

            int flagInt = 0;

            for (int i = 0; i < StationSelect.Items.Count; i++)
            {
                if (StationSelect.GetItemChecked(i))
                {
                    flagInt++;
                }
            }
            if (flagInt == 0)
            {
                for (int i = 0; i < StationSelect.Items.Count; i++)
                {
                    stationSelected.Add(StationSelect.GetItemText(StationSelect.Items[i]));
                }
            }
            else
            {
                for (int i = 0; i < StationSelect.Items.Count; i++)
                {
                    if (StationSelect.GetItemChecked(i))
                    {
                        stationSelected.Add(StationSelect.GetItemText(StationSelect.Items[i]));
                    }
                }
            }
            #region 雨量数据
            if (type.Equals("雨  量"))
            {
                CMessageBox box = new CMessageBox();
                box.MessageInfo = "正在导出雨量数据";
                box.ShowDialog(this);
                try
                {
                    for (int i = 0; i < stationSelected.Count; i++)
                    {
                        string             stationid    = stationSelected[i].Split('|')[0];
                        string             stationname  = stationSelected[i].Split('|')[1];
                        List <CEntityRain> rainList     = new List <CEntityRain>();
                        List <string>      rainInfoText = new List <string>();
                        rainList = CDBDataMgr.GetInstance().getListRainByTime(stationid, startTime, endTime);
                        for (int j = 0; j < rainList.Count; j++)
                        {
                            DateTime dataAndTime = rainList[j].TimeCollect;
                            string   rainInfo    = string.Empty;
                            rainInfo = rainInfo + "\"";
                            string tmp  = dataAndTime.ToString("d").Substring(2);
                            string year = dataAndTime.Year.ToString().Substring(2);
                            rainInfo = rainInfo + year + "/";
                            string month = dataAndTime.Month.ToString();
                            if (month.Length < 2)
                            {
                                month = "0" + month;
                            }
                            rainInfo = rainInfo + month + "/";
                            string day = dataAndTime.Day.ToString();
                            if (day.Length < 2)
                            {
                                day = "0" + day;
                            }
                            rainInfo = rainInfo + day + " ";
                            string hour = dataAndTime.Hour.ToString();
                            if (hour.Length < 2)
                            {
                                hour = "0" + hour;
                            }
                            rainInfo = rainInfo + hour;
                            string minute = dataAndTime.Minute.ToString();
                            if (minute.Length < 2)
                            {
                                minute = "0" + minute;
                            }
                            rainInfo = rainInfo + ":" + minute;

                            rainInfo = rainInfo + " ";
                            string rain = rainList[j].TotalRain.ToString();
                            for (int k = 0; k < 6 - rain.Length; k++)
                            {
                                rainInfo = rainInfo + "0";
                            }
                            rainInfo = rainInfo + rain;
                            rainInfo = rainInfo + "\"";
                            rainInfoText.Add(rainInfo);
                        }
                        if (rainInfoText != null && rainInfoText.Count > 1)
                        {
                            string fileName = "rainData" + "\\" + stationname + "站" + startTime.ToString("D") + "到" + endTime.ToString("D") + "雨量.Dat";
                            exportTxt(rainInfoText, fileName);
                        }
                    }
                    box.CloseDialog();
                    MessageBox.Show("导出雨量数据成功");
                }
                catch (Exception e1)
                {
                    box.CloseDialog();
                    MessageBox.Show("导出水位数据失败");
                }
            }
            #endregion

            #region 水位数据
            if (type.Equals("水  位"))
            {
                CMessageBox box = new CMessageBox();
                box.MessageInfo = "正在导出水位数据";
                box.ShowDialog(this);
                try
                {
                    for (int i = 0; i < stationSelected.Count; i++)
                    {
                        List <CEntityWater> waterList = new List <CEntityWater>();
                        string        stationid       = stationSelected[i].Split('|')[0];
                        string        stationname     = stationSelected[i].Split('|')[1];
                        List <string> waterInfoText   = new List <string>();
                        waterList = CDBDataMgr.GetInstance().GetWaterByTime(stationid, startTime, endTime);
                        for (int j = 0; j < waterList.Count; j++)
                        {
                            DateTime dataAndTime = waterList[j].TimeCollect;
                            string   waterInfo   = string.Empty;
                            waterInfo = waterInfo + "\"";
                            string year = dataAndTime.Year.ToString().Substring(2);
                            waterInfo = waterInfo + year + "/";
                            string month = dataAndTime.Month.ToString();
                            if (month.Length < 2)
                            {
                                month = "0" + month;
                            }
                            waterInfo = waterInfo + month + "/";
                            string day = dataAndTime.Day.ToString();
                            if (day.Length < 2)
                            {
                                day = "0" + day;
                            }
                            waterInfo = waterInfo + day + " ";
                            string hour = dataAndTime.Hour.ToString();
                            if (hour.Length < 2)
                            {
                                hour = "0" + hour;
                            }
                            waterInfo = waterInfo + hour;
                            string minute = dataAndTime.Minute.ToString();
                            if (minute.Length < 2)
                            {
                                minute = "0" + minute;
                            }
                            waterInfo = waterInfo + ":" + minute;

                            waterInfo = waterInfo + " ";
                            decimal waterd = waterList[j].WaterStage;

                            string water = ((int)(waterd * 100)).ToString();
                            for (int k = 0; k < 6 - water.Length; k++)
                            {
                                waterInfo = waterInfo + "0";
                            }
                            waterInfo = waterInfo + water;
                            waterInfo = waterInfo + "\"";
                            waterInfoText.Add(waterInfo);
                        }
                        if (waterInfoText != null && waterInfoText.Count > 1)
                        {
                            string fileName = "waterData" + "\\" + stationname + "站" + startTime.ToString("D") + "到" + endTime.ToString("D") + "水位.Dat";
                            exportTxt(waterInfoText, fileName);
                        }
                    }
                    box.CloseDialog();
                    MessageBox.Show("导出水位数据成功");
                }
                catch (Exception e2)
                {
                    box.CloseDialog();
                    MessageBox.Show("导出水位数据失败");
                }
            }
            #endregion

            #region 中澳格式数据
            if (type.Equals("中澳格式"))
            {
                CMessageBox box = new CMessageBox();
                box.MessageInfo = "正在导出中澳格式数据";
                box.ShowDialog(this);
                try
                {
                    for (int i = 0; i < stationSelected.Count; i++)
                    {
                        List <CEntityRainAndWater> rainWaterList = new List <CEntityRainAndWater>();

                        string        stationid     = stationSelected[i].Split('|')[0];
                        string        stationname   = stationSelected[i].Split('|')[1];
                        List <string> hydroInfoText = new List <string>();
                        rainWaterList = CDBDataMgr.GetInstance().getRainAndWaterList(stationid, startTime, endTime);
                        if (rainWaterList == null || rainWaterList.Count == 0)
                        {
                            continue;
                        }

                        for (int j = 0; j < rainWaterList.Count; j++)
                        {
                            DateTime dataAndTime = DateTime.Now;;
                            if (rainWaterList[j].rainTimeCollect <= DateTime.Now)
                            {
                                dataAndTime = rainWaterList[j].rainTimeCollect;
                            }
                            else if (rainWaterList[j].waterTimeCollect <= DateTime.Now)
                            {
                                dataAndTime = rainWaterList[j].waterTimeCollect;
                            }
                            else
                            {
                                continue;
                            }
                            string hydroInfo = string.Empty;
                            hydroInfo = hydroInfo + "1,";
                            hydroInfo = hydroInfo + dataAndTime.Year.ToString() + ",";
                            hydroInfo = hydroInfo + getDayOfYear(dataAndTime).ToString() + ",";
                            string hour = dataAndTime.Hour.ToString();
                            if (hour.Length < 2)
                            {
                                hour = "0" + hour;
                            }
                            string minute = dataAndTime.Minute.ToString();
                            if (minute.Length < 2)
                            {
                                minute = "0" + minute;
                            }
                            hydroInfo = hydroInfo + hour + minute + ",";
                            hydroInfo = hydroInfo + stationid.ToString() + ",";
                            if (rainWaterList[j].WaterStage != -9999)
                            {
                                hydroInfo = hydroInfo + rainWaterList[j].WaterStage.ToString() + ",";
                            }
                            else
                            {
                                hydroInfo = hydroInfo + ",";
                            }
                            if (rainWaterList[j].TotalRain != -9999)
                            {
                                hydroInfo = hydroInfo + rainWaterList[j].TotalRain.ToString() + ",";
                            }
                            else
                            {
                                hydroInfo = hydroInfo + ",";
                            }
                            hydroInfo = hydroInfo + "12.85";
                            hydroInfoText.Add(hydroInfo);
                        }
                        if (hydroInfoText != null && hydroInfoText.Count > 1)
                        {
                            string fileName = "specData" + "\\" + stationname + "站" + startTime.ToString("D") + "到" + endTime.ToString("D") + "数据.Dat";
                            exportTxt(hydroInfoText, fileName);
                        }
                    }
                    box.CloseDialog();
                    MessageBox.Show("导出中澳数据成功");
                }
                catch (Exception e2)
                {
                    box.CloseDialog();
                    MessageBox.Show("导出中澳数据失败");
                }
            }
            #endregion
            this.Focus();
        }
コード例 #7
0
        private void search_Click(object sender, EventArgs e)
        {
            //获取 radioButton 的table类型值;
            string tableType = "";

            foreach (var item in TableType.Controls)
            {
                if (item is RadioButton)
                {
                    RadioButton radioButton = item as RadioButton;
                    if (radioButton.Checked)
                    {
                        tableType = radioButton.Text.Trim();
                    }
                }
            }
            // 获取分中心
            string subcenterName = SubCenter.Text;
            //获取时间  date.value;
            // 获取站点信息 默认为全部站点
            List <string> stationSelected = new List <string>();

            int flagInt = 0;

            for (int i = 0; i < StationSelect.Items.Count; i++)
            {
                if (StationSelect.GetItemChecked(i))
                {
                    flagInt++;
                }
            }
            if (flagInt == 0)
            {
                for (int i = 0; i < StationSelect.Items.Count; i++)
                {
                    stationSelected.Add(StationSelect.GetItemText(StationSelect.Items[i]));
                }
            }
            else
            {
                for (int i = 0; i < StationSelect.Items.Count; i++)
                {
                    if (StationSelect.GetItemChecked(i))
                    {
                        stationSelected.Add(StationSelect.GetItemText(StationSelect.Items[i]));
                    }
                }
            }

            DateTime dt1  = DateTimer.Value;
            DateTime dt   = dt1.Date;
            string   type = getType();

            if (type.Equals("普通文本"))
            {
                CMessageBox box = new CMessageBox();
                box.MessageInfo = "正在查询数据库";
                box.ShowDialog(this);
                this.Enabled = false;
                this.Enabled = true;
                box.CloseDialog();
            }
            if (type.Equals("中澳格式"))
            {
                CMessageBox box = new CMessageBox();
                box.MessageInfo = "正在查询数据库";
                box.ShowDialog(this);
                this.Enabled = false;
                this.Enabled = true;
                box.CloseDialog();
            }
            if (type.Equals("墒    情"))
            {
                CMessageBox box = new CMessageBox();
                box.MessageInfo = "正在查询数据库";
                box.ShowDialog(this);
                this.Enabled = false;
                this.Enabled = true;
                box.CloseDialog();
            }
            this.Enabled = true;
        }