//点击生成平均值 private void averdata_Click(object sender, EventArgs e) { int m1; //起始月份 int m2; //终止月份 int d1; //起始日期 int d2; //终止日期 int y1; //起始年份 int y2; //终止年份 try { m1 = int.Parse(month1.Text); m2 = int.Parse(month2.Text); d1 = int.Parse(day1.Text); d2 = int.Parse(day2.Text); y1 = int.Parse(yearText1.Text); y2 = int.Parse(yearText2.Text); Dates dates = new Dates(); int days1 = dates.getStrDateNew(y1, m1, d1); int days2 = dates.getStrDateNew(y2, m2, d2); //判断日期是否合理 if (days1 == 0 || days2 == 0) { MessageBox.Show("日期非法", "错误提示"); return; } if (days2 - days1 > 0) { string sqlstr = "select* from allData where date >= " + days1.ToString() + "&&" + "date <= " + days2.ToString(); Console.WriteLine(sqlstr); if (updateViewForAver(sqlstr) == 1) { listView1.Items.Add("平均数据"); for (int i = 0; i < 10; i++) { listView1.Items[flg].SubItems.Add(avers[i].ToString()); } } } else { MessageBox.Show("数据错误", "错误提示"); } } catch (Exception) { MessageBox.Show("数据错误", "错误提示"); } }
//获取数据库现有数据 private int getPreData() { try { int m = int.Parse(month.Text); //月 int d = int.Parse(day.Text); //日 int y = int.Parse(yearsText.Text); //年 Dates dates = new Dates(); int searchDate = dates.getStrDateNew(y, m, d); Console.WriteLine(searchDate); if (searchDate == 0) { MessageBox.Show("请检查日期输入", "错误提示"); return(0); } basedate = searchDate; string name = comboBox1.SelectedItem.ToString(); string sqlstr = "select* from cityList where name='" + name + "'"; MySqlDataReader reader = Config.sqlSearch(sqlstr); if (reader == null) { MessageBox.Show("数据错误", "错误提示"); return(0); } if (reader.Read()) { cityWord = reader.GetString("city"); provinceWord = reader.GetString("province"); sqlstr = "select* from " + cityWord + " where date=" + searchDate.ToString(); reader = Config.sqlSearch(sqlstr); if (reader.Read()) { preDatalist = Config.setData(reader); return(1); } else { MessageBox.Show("该日数据未输入", "错误提示"); return(0); } } else { MessageBox.Show("找不到地区", "错误提示"); return(0); } } catch (Exception) { MessageBox.Show("请输入正确数据", "错误提示"); return(0); } }