Exemplo n.º 1
0
 private void txtRcvRhH_TextChanged(object sender, EventArgs e)
 {
     //Console.WriteLine("水份检测参数:"+txtRcvRhH.Text);
     if (strRhOutPath == "")
     {
         if (!File.Exists(strRhOutPath))
         {
             strRhOutPath = "";
             return;
         }
         try
         {
             StreamWriter swOutputCmd = new StreamWriter(strRhOutPath, true, Encoding.GetEncoding("gb2312"));
             swOutputCmd.WriteLine((Uart.GetTimeStamp() - StartTimeNum) + "\t" + txtRcvRhH.Text);
             swOutputCmd.Flush();
             swOutputCmd.Close();
         }
         catch
         {
             strRhOutPath       = "";
             menuRcvRhSave.Text = "保存数据";
             MessageBox.Show("动态输出文件无法写入,已关闭。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         }
     }
 }
Exemplo n.º 2
0
 private void menuRcvRhSave_Click(object sender, EventArgs e)
 {
     if (menuRcvRhSave.Text == "保存数据")
     {
         StartTimeNum = Uart.GetTimeStamp();
         SaveFileDialog save = new SaveFileDialog();
         save.Filter           = "表格格式|*.xls|文本格式|*.txt|所有格式|*.*";
         save.Title            = "保存参数";
         save.RestoreDirectory = true;
         save.FilterIndex      = 1;
         if (save.ShowDialog() == DialogResult.OK)
         {
             string str = save.FileName;
             try
             {
                 using (StreamWriter sw = new StreamWriter(str, false, Encoding.GetEncoding("gb2312")))
                 {
                     sw.Write("时间" + "\t" + "参数");
                     sw.Flush();
                     sw.Close();
                 }
             }
             catch (Exception)
             {
                 strRhOutPath = "";
                 MessageBox.Show("文件保存失败,请重新选择。");
                 return;
             }
             strRhOutPath       = str;
             menuRcvRhSave.Text = "取消保存";
         }
     }
     else
     {
         strRhOutPath       = "";
         menuRcvRhSave.Text = "保存数据";
     }
 }