Esempio n. 1
0
        //更新表单时用
        public int updateView(string sqlstr)
        {
            MySqlDataReader reader = Config.sqlSearch(sqlstr);

            flg = 0;
            if (reader == null)
            {
                MessageBox.Show("未找到数据", "错误提示");
                return(0);
            }
            listView1.Items.Clear();
            while (reader.Read())
            {
                int[] data = new int[11];
                data = setData(reader);
                Dates  dates   = new Dates();
                string datestr = dates.getDateStrNew(data[0]);
                Console.WriteLine(datestr);
                listView1.Items.Add(datestr);
                for (int i = 1; i < 11; i++)
                {
                    listView1.Items[flg].SubItems.Add(data[i].ToString());
                }
                flg = flg + 1;
            }

            return(1);
        }
Esempio n. 2
0
        //专门为平均值准备的查询
        public int updateViewForAver(string sqlstr)
        {
            int[] total = new int[10];
            for (int i = 0; i < 10; i++)
            {
                total[i] = 0;
            }
            MySqlDataReader reader = Config.sqlSearch(sqlstr);

            flg = 0;
            if (reader == null)
            {
                MessageBox.Show("未找到数据", "错误提示");
                return(0);
            }
            listView1.Items.Clear();
            while (reader.Read())
            {
                int[] data = new int[11];
                data = setData(reader);
                for (int i = 0; i < 10; i++)
                {
                    total[i] = total[i] + data[i + 1];
                }

                Dates  dates   = new Dates();
                string datestr = dates.getDateStrNew(data[0]);
                Console.WriteLine(datestr);
                listView1.Items.Add(datestr);
                for (int i = 1; i < 11; i++)
                {
                    listView1.Items[flg].SubItems.Add(data[i].ToString());
                }
                flg = flg + 1;
            }
            avers = new int[10]; //avers数组,用于记录平均数
            for (int i = 0; i < 10; i++)
            {
                avers[i] = total[i] / flg;
            }
            return(1);
        }
Esempio n. 3
0
        //用于查询地区
        private void provinceName_TextChanged(object sender, EventArgs e)
        {
            int             date   = 0;
            string          sqlstr = "select* from cityList where name='" + provinceName.Text + "'";
            string          province; //省份
            string          city;     //城市
            MySqlDataReader reader = Config.sqlSearch(sqlstr);

            if (reader == null)
            {
                MessageBox.Show("数据错误", "错误提示");
                return;
            }

            if (reader.Read())
            {
                province = reader.GetString("province");
                city     = reader.GetString("city");
                sqlstr   = "select* from " + city;
                reader   = Config.sqlSearch(sqlstr);
                if (reader == null)
                {
                    MessageBox.Show("数据错误", "错误提示");
                    return;
                }

                while (reader.Read())
                {
                    date = reader.GetInt32("date");
                }
                Dates dates = new Dates();
                textBox1.Text = (date + 1).ToString();
                nextDate.Text = dates.getDateStrNew(date + 1);
            }
            else
            {
                return;
            }
        }
Esempio n. 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            string province; //省份
            string city;     //城市
            string sqlstr = "select* from cityList where name='" + provinceName.Text + "'";

            int[] datalist = new int[11];
            for (int i = 0; i < 11; i++)
            {
                datalist[i] = 0;
            }
            int[]           inputdata;
            MySqlDataReader reader = Config.sqlSearch(sqlstr);

            if (reader == null)
            {
                MessageBox.Show("数据错误", "错误提示");
                return;
            }

            if (reader.Read())
            {
                province = reader.GetString("province");
                city     = reader.GetString("city");
                int date = int.Parse(textBox1.Text);
                sqlstr = "select* from " + city + " where date=" + (date - 1).ToString();
                reader = Config.sqlSearch(sqlstr);
                if (reader == null)
                {
                    MessageBox.Show("数据错误", "错误提示");
                    return;
                }

                if (reader.Read())
                {
                    datalist = Config.setData(reader);
                }
                inputdata = datalist;

                try
                {
                    inputdata[0]  = date;
                    inputdata[2]  = int.Parse(newDefinite.Text);
                    inputdata[4]  = int.Parse(newCure.Text);
                    inputdata[6]  = int.Parse(newDeath.Text);
                    inputdata[8]  = int.Parse(newSuspected.Text);
                    inputdata[10] = int.Parse(newDanger.Text);

                    for (int i = 0; i < 5; i++)
                    {
                        inputdata[i * 2 + 1] = datalist[i * 2 + 1] + inputdata[i * 2 + 2];
                        if (inputdata[i * 2 + 1] < 0)
                        {
                            MessageBox.Show("数据不合法", "提示");
                            return;
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("错误输入", "提示");
                    return;
                }
                sqlstr = "insert into " + city + " (date,allDefinite,newDefinite,allCure,newCure,allDeath,newDeath,nowSuspected,newSuspected,nowDanger,newDanger) values (";
                for (int i = 0; i < 10; i++)
                {
                    sqlstr = sqlstr + inputdata[i] + ",";
                }
                sqlstr = sqlstr + inputdata[10] + ")";
                Console.WriteLine(sqlstr);
                if (Config.sqlExcuteChange(sqlstr) == 1)
                {
                    textBox1.Text = (inputdata[0] + 1).ToString();
                    Dates dates = new Dates();
                    nextDate.Text  = dates.getDateStrNew((inputdata[0] + 1));
                    basedate       = inputdata[0];
                    changedatalist = inputdata;
                    //这个地方出错需要回滚,需要加强鲁棒性
                    updateProvince(province, basedate, changedatalist);
                    updateAll(basedate, changedatalist);
                    MessageBox.Show("添加成功", "提示");

                    return;
                }
                else
                {
                    MessageBox.Show("数据库未正常连接", "提示");
                    return;
                }
            }
            else
            {
                MessageBox.Show("数据错误", "提示");
                return;
            }
        }
Esempio n. 5
0
        //点击查看拐点信息(写到这里才想起来C#有list,之前一直都在郁闷为什么C#没有vector)
        private void keyPoint_Click(object sender, EventArgs e)
        {
            string          sqlstr = "select * from allData";
            MySqlDataReader reader = Config.sqlSearch(sqlstr);

            if (reader == null)
            {
                MessageBox.Show("数据错误", "错误提示");
                return;
            }

            int check1 = 0;
            int check2 = 0;
            int tmp    = 0;

            int[] maybeData = new int[11];
            listView1.Items.Clear();
            flg = 0;
            while (reader.Read())
            {
                if (reader.GetInt32("newDefinite") > tmp)
                {
                    check1 = check1 + 1;
                    if (check1 >= 5)
                    {
                        maybeData = setData(reader);
                    }
                }
                else if (reader.GetInt32("newDefinite") == tmp)
                {
                }
                else
                {
                    if (check1 >= 5)
                    {
                        check2 = check2 + 1;
                        check1 = 5;
                    }
                    else
                    {
                        check1 = 0;
                        check2 = 0;
                    }
                }
                tmp = reader.GetInt32("newDefinite");
                if (check1 >= 5 && check2 >= 5)
                {
                    Console.WriteLine(maybeData[0]);
                    Dates  date    = new Dates();
                    string datastr = date.getDateStrNew(maybeData[0]);
                    listView1.Items.Add(datastr);
                    for (int i = 1; i < 11; i++)
                    {
                        listView1.Items[flg].SubItems.Add(maybeData[i].ToString());
                    }
                    flg    = flg + 1;
                    check1 = 0;
                    check2 = 0;
                }
            }
        }