コード例 #1
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;
                }
            }
        }
コード例 #2
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();
        }
コード例 #3
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;
        }
コード例 #4
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;

            if (tableType.Equals("雨  量"))
            {
                CMessageBox box = new CMessageBox();
                box.MessageInfo = "正在查询数据库";
                box.ShowDialog(this);
                this.Enabled = false;
                Temp         = new DateTime(year, 1, 1, 9, 0, 0);
                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;
                Temp         = new DateTime(year, 1, 1, 0, 0, 0);
                m_OneWaterYear.SetFilter(StationID, Temp);
                m_OneWaterYear.Visible = true;
                this.Enabled           = true;
                box.CloseDialog();
                this.Enabled = true;
            }
            if (tableType.Equals("熵  情"))
            {
            }
        }