コード例 #1
0
        //导入曲线按钮
        private void impCurBtn_Click(object sender, RoutedEventArgs e)
        {
            FileOperator fOptor = new FileOperator();
            string       s      = null;
            string       line   = null;

            string[]     strs = null;
            MotoDataItem motoDataItem;

            //打开曲线文件路径
            s = fOptor.getOpenPath();
            if (s != null)
            {
                StreamReader sr = new StreamReader(s);
                //清空原有数据曲线,准备添加新的数据曲线
                speedCurve.Clear();

                line = sr.ReadLine();//读取文件头
                line = sr.ReadLine();
                while ((line = sr.ReadLine()) != null)
                {
                    //解析数据
                    strs         = line.Split('\t');
                    motoDataItem = new MotoDataItem();
                    try
                    {
                        motoDataItem.Number   = int.Parse(strs[0]);    //编号
                        motoDataItem.Minute   = double.Parse(strs[1]); //分钟
                        motoDataItem.Second   = double.Parse(strs[2]); //秒
                        motoDataItem.StaSpeed = double.Parse(strs[3]); //起始转速
                        motoDataItem.EndSpeed = double.Parse(strs[4]); //末端转速
                    }
                    catch (Exception ex)
                    {
                        ModernDialog.ShowMessage(ex.ToString(), "Message:", MessageBoxButton.OK);
                        break;
                    }
                    speedCurve.Add(motoDataItem);//添加数据曲线
                }
                sr.Close();
            }
        }
コード例 #2
0
        //打开文件按钮(绘图)
        private void opFileBtn_Click(object sender, RoutedEventArgs e)
        {
            FileOperator fOptor = new FileOperator();
            string       s      = null; //文件路径
            string       line   = null; //一条记录

            string[] strs      = null;
            string[] titleItem = null;

            int          i = 0;
            FileDataItem fileDataItem;

            s = fOptor.getOpenPath(); //打开曲线文件路径
            avrDataLabel.Visibility = Visibility.Hidden;

            if (s != null)
            {
                filePathLabel.Content = "文件:" + s;
                StreamReader sr = new StreamReader(s);
                filePtCollection.Clear();

                line      = sr.ReadLine();//文件头(包含各项说明)
                titleItem = line.Split('\t');
                for (i = 3; i < titleItem.Length; i++)
                {
                    ComboBoxItem item = new ComboBoxItem();
                    item.Content = titleItem[i];
                    curTypeCombox.Items.Add(item);
                }

                fileData.Clear();//清空数据以便存入新的文件数据
                while ((line = sr.ReadLine()) != null)
                {
                    //解析数据记录
                    strs         = line.Split('\t');
                    fileDataItem = new FileDataItem();

                    try
                    {
                        fileDataItem.Time = double.Parse(strs[0]);
                        for (i = 3; i < strs.Length; i++)
                        {
                            switch (titleItem[i])
                            {
                            case "压力":
                                fileDataItem.Pressure = double.Parse(strs[i]); break;

                            case "温度":
                                fileDataItem.Temperature = double.Parse(strs[i]); break;

                            case "相对湿度":
                                fileDataItem.Humidity = double.Parse(strs[i]); break;

                            case "平台转速":
                                fileDataItem.PlatSpeed = double.Parse(strs[i]); break;

                            case "电机转速":
                                fileDataItem.MotoSpeed = double.Parse(strs[i]); break;

                            case "电机扭矩":
                                fileDataItem.MotoTorque = double.Parse(strs[i]); break;

                            case "摩擦力":
                                fileDataItem.FricForce = double.Parse(strs[i]); break;

                            case "摩擦速度":
                                fileDataItem.FricSpeed = double.Parse(strs[i]); break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ModernDialog.ShowMessage(ex.ToString(), "Message:", MessageBoxButton.OK);
                        break;
                    }

                    fileData.Add(fileDataItem); //添加一条数据记录
                }
                sr.Close();
            }
        }