⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 药检所实验室使用,绝对自己开发,细菌数量求均方差,输入简单,结果正确,已经应用于实际项目中.大大降低了工作量 .输入格式为 7.52*10(5) 7.49*10(5) 6.82*10(5) 表示
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.IO;

namespace standResult
{
    public partial class Form1 : Form
    {
        /// <summary>
        /// 采样点数
        /// </summary>
        int kNumber = 0; 
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "打开(Open)";
            ofd.FileName = "";
            ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Recent);//为了获取特定的系统文件夹,可以使用System.Environment类的静态方法GetFolderPath()。该方法接受一个Environment.SpecialFolder枚举,其中可以定义要返回路径的哪个系统目录
            ofd.Filter = "文本文件(*.txt)|*.txt";
            ofd.ValidateNames = true;     //文件有效性验证ValidateNames,验证用户输入是否是一个有效的Windows文件名
            ofd.CheckFileExists = true;  //验证路径有效性
            ofd.CheckPathExists = true; //验证文件有效性
            try
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    StreamReader sr = new StreamReader(ofd.FileName, System.Text.Encoding.Default);
                    this.richTextBox1.Text = sr.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
           
           //  double dbValue = Math.Pow(10 , 7);
             RichTextBox my = new RichTextBox();
             for ( int i=0; i < richTextBox1.Lines.Length ; i++ )
             {
                 if (richTextBox1.Lines[i].ToString().Trim().Length > 0 )
                 {
                     Console.WriteLine(richTextBox1.Lines[i].ToString() + "=");
                     String[] arrText = richTextBox1.Lines[i].ToString().Trim().Split(' ');
                     double dbValue = 0;
                     int k = 0;
                     double dbCur = 0;
                     for ( int j=0 ; j < arrText.Length;j++)
                     {
                         String strItem = arrText[j];
                         String X ="";
                         String Y ="";
                         String Z ="";
                         if ( strItem.IndexOf("(") > 0  && strItem.IndexOf("*") > 0 )
                         {
                             X =  strItem.Split('*')[0];
                             Y =  strItem.Split('*')[1].Split('(')[0];
                             Z = strItem.Split('*')[1].Split('(')[1].Replace(")", "");
                           
                             dbCur = Convert.ToDouble(X) * Math.Pow(Convert.ToDouble(Y), Convert.ToDouble(Z));
                             dbValue += dbCur;
                             Console.WriteLine(dbCur.ToString());
                             k++;
                           
                         }
                         else
                         {
                             if ( arrText[j].Trim().Length > 0 )
                             {
                                 dbCur  = Convert.ToDouble(arrText[j]);
                                 dbValue += dbCur;
                                 Console.WriteLine(dbCur.ToString()); 
                                 k++;
                             }
                           
                         }
                         
                         // iTotal += Convert.ToInt32(arrText[j]);
                     }
                     double dbAverage  = dbValue / k;
                     Console.WriteLine(dbAverage.ToString());
                     my.AppendText(richTextBox1.Lines[i].Replace(richTextBox1.Lines[i], richTextBox1.Lines[i] + " =" + dbAverage.ToString()));
                     my.AppendText("\n");
                     
                     
                 }
               
             }
             richTextBox1.Text = my.Text;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            double dbTotal = 0;
            kNumber = 0;
            for (int i = 0; i < richTextBox1.Lines.Length; i++)
            {
                String[] arrText = richTextBox1.Lines[i].Split('=');
                if ( arrText.Length ==2 )
                {
                    dbTotal += Convert.ToDouble(arrText[1]);
                    kNumber++;

                }
                else
                {
                    //MessageBox.Show("未计算粒子浓度");
                }
            }
            if (kNumber > 1)
            {
                dbTotal = (dbTotal / kNumber);
                richTextBox2.Text = dbTotal.ToString();
            }
           

        }

        private void button4_Click(object sender, EventArgs e)
        {
            double dbCurr = 0;
            double dbTotal = 0;
            double[] arrDb = new double[kNumber];
            int kTemp = 0;
            for (int i = 0; i < richTextBox1.Lines.Length; i++)
            {
                String[] arrText = richTextBox1.Lines[i].Split('=');
                if (arrText.Length == 2)
                {
                    dbCurr  = Convert.ToDouble(arrText[1]);
                    double dbTemp = Math.Abs((dbCurr - Convert.ToDouble(richTextBox2.Text)));
                    arrDb[kTemp] =  dbTemp* dbTemp;
                    dbTotal += dbTemp * dbTemp;
                    kTemp++;
                   

                }
                
            }

           dbTotal =  dbTotal / ((kNumber - 1) * kNumber);
           richTextBox3.Text =    Math.Sqrt(dbTotal).ToString();
                

           

        }

        private void button5_Click(object sender, EventArgs e)
        {
           Double db =  Convert.ToDouble(richTextBox2.Text) + Convert.ToDouble(comboBox1.Text.Split(' ')[0]) * Convert.ToDouble(richTextBox3.Text);
           richTextBox4.Text = db.ToString();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -