예제 #1
0
        private void buttonQuery_Click(object sender, EventArgs e)
        {
            object[] objs = stf.GetCheckedSensors();
            //List<datas> result = new List<datas>();
            DataSet newSet = new DataSet();

            foreach (object[] obj in objs)
            {
                SENSOR_TYPE type = sites.GetType((uint)obj[0], (uint)obj[1]);
                newSet.Merge(DbClient.Query((uint)obj[0],
                                            (uint)obj[1],
                                            dateTimeFrom.Value,
                                            dateTimeTo.Value,
                                            timeUnit,
                                            (type == SENSOR_TYPE.GUANDAO || type == SENSOR_TYPE.MINGQU))
                             );
                //result.AddRange();
            }

            if (radioButtonGrid.Checked)
            {
                dataGridSensor.Show();
                chartSensors.Hide();
                FillGrid(newSet);
            }
            else
            {
                dataGridSensor.Hide();
                chartSensors.Show();
                FillChart(newSet);
            }
        }
예제 #2
0
        private void buttonMake_Click(object sender, EventArgs e)
        {
            Settings.Default.TitleName = textBoxName.Text;
            Properties.Settings.Default.Save();
            Sensor ss = null;

            sel_st.Get((uint)comboBoxSensors.SelectedValue, out ss);
            DataSet ds = DbClient.Query(sel_st.num,
                                        ss.num,
                                        dateTimeFrom.Value,
                                        dateTimeTo.Value,
                                        (DbClient.TIME_UNIT)comboBoxTime.SelectedValue,
                                        ss.type == SENSOR_TYPE.GUANDAO || ss.type == SENSOR_TYPE.MINGQU
                                        );
            DataTable dt_fill = null;

            foreach (DataTable dt in ds.Tables)
            {
                if (dt.Rows.Count > 0)
                {
                    dt_fill = dt;
                    break;
                }
            }
            if (dt_fill == null)
            {
                MessageBox.Show("没有查到数据,请重新设定查询条件。");
                return;
            }
            DataView dv = dt_fill.DefaultView;

            dv.Sort = "time asc";
            dt_fill = dv.ToTable();
            dt_fill.Columns.Remove("site");
            dt_fill.Columns.Remove("sensor");
            dt_fill.Columns.Add("sum");
            dt_fill.Columns["time"].ColumnName = "_time";
            dt_fill.Columns.Add("time");
            string format = "yyyy年MM月dd日HH时";

            switch (comboBoxTime.SelectedIndex)
            {
            case 0:
                format = "yyyy年MM月dd日HH时mm分";
                break;

            case 1:
                format = "yyyy年MM月dd日HH时";
                break;

            case 2:
                format = "yyyy年MM月dd日";
                break;

            case 3:
                format = "yyyy年MM月";
                break;

            default:

                break;
            }
            if (ss.type == SENSOR_TYPE.GUANDAO || ss.type == SENSOR_TYPE.MINGQU)
            {
                for (int i = 0; i < dt_fill.Rows.Count; ++i)
                {
                    double sum = 0.0;
                    for (int j = 0; j <= i; ++j)
                    {
                        double value = (double)dt_fill.Rows[j]["data"];
//                         switch (comboBoxTime.SelectedIndex)
//                         {
//                             case 0:
//                                 sum *= 1;
//                                 break;
//                             case 1:
//                                 sum *= 24;
//                                 break;
//                             case 2:
//                                 DateTime time = (DateTime)dt_fill.Rows[j].ItemArray[0];
//                                 sum *= DateTime.DaysInMonth(time.Year, time.Month);
//                                 break;
//                             default:
//                                 sum *= 1;
//                                 break;
//                         }
                        sum += value;
                    }

                    DateTime obtm = (DateTime)dt_fill.Rows[i]["_time"];
                    dt_fill.Rows[i]["time"] = obtm.ToString(format);
                    dt_fill.Rows[i]["sum"]  = sum;
                }
            }
            else
            {
                for (int i = 0; i < dt_fill.Rows.Count; ++i)
                {
                    DateTime obtm = (DateTime)dt_fill.Rows[i]["_time"];
                    dt_fill.Rows[i]["time"] = obtm.ToString(format);
                    dt_fill.Rows[i]["sum"]  = "--";
                }
            }
            dt_fill.TableName = "SwDatas";
            //List<ReportParameter> rps = new List<ReportParameter>();
            ReportParameter p1 = new ReportParameter("colName1", "时间");
            ReportParameter p2 = new ReportParameter("colName3", "总累计");
            string          colName2;
            string          title = textBoxName.Text;

            switch (ss.type)
            {
            case SENSOR_TYPE.MINGQU:
            case SENSOR_TYPE.GUANDAO:
                colName2 = @"单位时间流量(㎥)";
                title   += "流量";
                break;

            case SENSOR_TYPE.SHUIWEI:
            case SENSOR_TYPE.WUWEI:
                colName2 = @"水位(m)";
                title   += "水位";
                break;

            case SENSOR_TYPE.WENDU:
                colName2 = @"温度(℃)";
                title   += "温度";
                break;

            case SENSOR_TYPE.YALI:
                colName2 = @"压力(MPa)";
                title   += "压力";
                break;

            case SENSOR_TYPE.DIANYA:
                colName2 = @"伏(V)";
                title   += "电压";
                break;

            default:
                colName2 = "";
                break;
            }
            ReportParameter p3 = new ReportParameter("colName2", colName2);
            ReportParameter p4 = new ReportParameter("title", title);
            ReportParameter p5 = new ReportParameter("beginTime", dateTimeFrom.Value.ToString(dateTimeFrom.CustomFormat));
            ReportParameter p6 = new ReportParameter("endTime", dateTimeTo.Value.ToString(dateTimeTo.CustomFormat));

            reportViewer1.LocalReport.ReportEmbeddedResource = "Shuiwen.Report1.rdlc";
            reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3, p4, p5, p6 });
            reportViewer1.LocalReport.DataSources.Clear();
            reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("SwDatas", dt_fill));
            reportViewer1.RefreshReport();

            if ((sender as Button).Tag != null)
            {
                if ((sender as Button).Tag.ToString() == "Export")
                {
                    Warning[] warnings;
                    string[]  streamids;
                    string    mimeType;
                    string    encoding;
                    string    extension;

                    byte[] bytes = reportViewer1.LocalReport.Render(
                        "Excel", null, out mimeType, out encoding, out extension,
                        out streamids, out warnings);

                    string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
                                                   DateTime.Now.ToString("yyyyMMddHHmmss") + title + "记录.xls");
                    FileStream fs = new FileStream(fileName, FileMode.Create);
                    fs.Write(bytes, 0, bytes.Length);
                    fs.Close();

                    MessageBox.Show(Path.GetFileName(fileName) + "已导出至桌面!", "提示");
                }
            }
        }