Example #1
0
        BackgroundWorker woker;//后台线程管理者

        public StartPage()
        {
            string conStr = (string)Application.Current.FindResource("PrivateConnString");

            con = new OleDbConnection(conStr);
            try
            {
                con.Open();
                if (con.State == ConnectionState.Open)
                {
                    OleDbCommand     cmd = new OleDbCommand("select * from tb_lhf_measure where saveindex is not null", con);
                    DataSet          set = new DataSet();
                    OleDbDataAdapter adp = new OleDbDataAdapter(cmd);
                    adp.Fill(set);
                    dt_measure = set.Tables[0];     //获取参数配置表格
                    strInsert  = ConstructString(); //构建插入字符串

                    var re1 = from h in dt_measure.AsEnumerable()
                              where h.Field <string>("name") == "pH"
                              select Convert.ToInt32(h.Field <object>("saveindex"));

                    foreach (int d in re1)
                    {
                        pH_saveindex = d;
                    }

                    var re2 = from h in dt_measure.AsEnumerable()
                              where h.Field <string>("name") == "电导率"
                              select Convert.ToInt32(h.Field <object>("saveindex"));

                    foreach (int d in re2)
                    {
                        DDL_saveindex = d;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            //读取电子表格
            dt_property = OperateExcel.ReadExcel("系统用溶解度表.xlsx");
            InitializeComponent();//初始化组建
            /// 订阅事件
            UpdateUI += new UpdateUIHandler(mainWnd.DoWork);
            UpdateUI += new UpdateUIHandler(onLineStatic.BeginThread);
            //定时器设置
            timer       = new DispatcherTimer();
            timer.Tick += new EventHandler(ProvideData);
            timer.Tick += new EventHandler(DoWork);


            timer.Interval = new TimeSpan(0, 0, 1);
            timer.Start();

            woker = new BackgroundWorker();//后台更新UI线程

            woker.DoWork += ComputeData;
        }
Example #2
0
        private void OnSave(object sender, RoutedEventArgs e)
        {
            try
            {
                string startStr = startTime.Text;
                string endStr   = endTime.Text;
                if (startStr == null)
                {
                    throw new Exception("请输入起始时间!");
                }
                if (endStr == null)
                {
                    throw new Exception("请输入结束时间!");
                }
                string strSelect      = "select * from tb_lhf_data where cytime between '" + startStr + "' and '" + endStr + "'" + " order by cytime asc";
                string strSelectCorro = "select * from tb_lhf_corro where cytime between '" + startStr + "' and '" + endStr + "'" + " and T=" + TControl.Text + " order by cytime asc";
                if (con.State == ConnectionState.Open)
                {
                    DataTable temp_dt      = GetTable(strSelect, con);
                    DataTable temp_dtCorro = GetTable(strSelectCorro, con);

                    //创建一个保存文件式的对话框
                    SaveFileDialog sfd = new SaveFileDialog();
                    //设置这个对话框的起始保存路径
                    sfd.InitialDirectory = System.Environment.CurrentDirectory + @"\";
                    //设置保存的文件的类型,注意过滤器的语法
                    sfd.Filter = "Excel文件|*.xlsx";
                    //调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
                    if (sfd.ShowDialog() == true)
                    {
                        OperateExcel operateExcel = new OperateExcel(sfd.FileName);
                        operateExcel.AddToSheet(temp_dt);
                        operateExcel.AddToSheet(temp_dtCorro);
                        System.Windows.MessageBox.Show("保存成功");
                    }
                    else
                    {
                        System.Windows.MessageBox.Show("取消保存");
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
            // OperateExcel operateExcel = new OperateExcel();
        }