示例#1
0
        private void lbFileNames_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedFileNames = lbFileNames.SelectedItems;

            if (selectedFileNames.Count > 0)
            {
                foreach (Model.ExistsFileModel model in existsFiles)
                {
                    model.IsChecked = false;
                }
                if (selectedFileNames.Count > 1)
                {
                    foreach (var item in selectedFileNames)
                    {
                        Model.ExistsFileModel model = item as Model.ExistsFileModel;
                        model.IsChecked = true;
                    }
                }
                else
                {
                    Model.ExistsFileModel model = lbFileNames.SelectedValue as Model.ExistsFileModel;
                    existsFiles.Find(x => x.RealName == model.RealName).IsChecked = true;
                    try
                    {
                        dgTestInfo.SelectedIndex = lbFileNames.SelectedIndex;
                        dgTestInfo.ScrollIntoView(dgTestInfo.Items[dgTestInfo.SelectedIndex]);
                    }
                    catch
                    {
                    }

                    string   fileName  = existsFiles[dgTestInfo.SelectedIndex].FileName;
                    string[] fileLines = File.ReadAllLines(fileName);
                    tbFileName.Text = "文件名:" + fileName.Substring(fileName.LastIndexOf("\\") + 1);
                    tbContent1.Text = "";
                    tbContent2.Text = "";
                    tbContent3.Text = "";
                    for (int a = 0; a < 11; a++)
                    {
                        tbContent1.Text += fileLines[a] + "\r\n";
                        tbContent2.Text += fileLines[11 + a] + "\r\n";
                        tbContent3.Text += fileLines[22 + a] + "\r\n";
                    }
                }
            }
        }
示例#2
0
        //导入方法
        private void Import(string [] fileNames, bool ischeckRepeate)
        {
            importProgress.Maximum = fileNames.Count();
            importProgress.Minimum = 0;
            importProgress.Value   = 0;
            double value = 0;
            UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(importProgress.SetValue);

            for (int i = 0; i < fileNames.Count(); i++)
            {
                if (importFlag == 1)
                {
                    break;
                }
                if (importFlag == 2)
                {
                    i--;
                    continue;
                }
                value += 1;
                Dispatcher.Invoke(updatePbDelegate,
                                  System.Windows.Threading.DispatcherPriority.Background,
                                  new object[] { ProgressBar.ValueProperty, value });

                Model.ImportDataErrorModel errorModel = null;

                string baseFileName = fileNames[i];

                #region 写入进度
                tbFileName.Text = "文件名:" + baseFileName.Substring(baseFileName.LastIndexOf("\\") + 1);
                tbContent1.Text = "";
                tbContent2.Text = "";
                tbContent3.Text = "";
                tbProgress.Text = (i + 1) + "/" + fileNames.Count();
                #endregion

                #region 读取数据文件信息
                string[] contents = File.ReadAllLines(baseFileName);

                if (!CheckFile(baseFileName, contents))
                {
                    continue;
                }
                for (int a = 0; a < 11; a++)
                {
                    tbContent1.Text += contents[a] + "\r\n";
                    tbContent2.Text += contents[11 + a] + "\r\n";
                    tbContent3.Text += contents[22 + a] + "\r\n";
                }

                string   testDate     = GetLineValue(contents[2]);
                string   testTime     = GetLineValue(contents[3]);
                DateTime testDateTime = DateTime.Now;
                if (testDate != "" && testTime != "")
                {
                    try
                    {
                        testDateTime = Convert.ToDateTime(testDate + " " + testTime, dtPointFormat);
                    }
                    catch {
                        testDateTime = DateTime.Now;
                    }
                }

                Model.TB_AthleteInfo athModel = new Model.TB_AthleteInfo();
                athModel.Ath_PinYin   = athModel.Ath_Name = GetLineValue(contents[4]);
                athModel.Ath_Sex      = DataUtil.AthleteSexUtil.GetSex(GetLineValue(contents[29]));
                athModel.Ath_TestDate = testDateTime;
                string birthdayStr = GetLineValue(contents[27]);
                if (birthdayStr != "")
                {
                    try
                    {
                        athModel.Ath_Birthday = Convert.ToDateTime(birthdayStr, dtLineFormat);
                    }
                    catch {
                        athModel.Ath_Birthday = DateTime.Now;
                    }
                }
                else
                {
                    athModel.Ath_Birthday = null;
                }
                athModel.Ath_Height = GetLineValue(contents[26]);
                athModel.Ath_Weight = GetLineValue(contents[25]);

                Model.TB_AthleteInfo testAthInfoModel = CheckAthInfo(athModel);
                if (testAthInfoModel == null)
                {
                    continue;
                }

                Model.TB_TestInfo testInfo = new Model.TB_TestInfo();
                testInfo.BaseFileName    = contents[0].Trim();
                testInfo.TestTime        = testInfo.TestDate = testDateTime;
                testInfo.Joint_Side      = GetLineValue(contents[5]);
                testInfo.Test_Mode       = GetLineValue(contents[6]);
                testInfo.Joint           = GetLineValue(contents[7]);
                testInfo.Plane           = GetLineValue(contents[8]);
                testInfo.Motion_Start    = GetLineValue(contents[10]);
                testInfo.Motion_End      = GetLineValue(contents[11]);
                testInfo.Speed1          = GetLineValue(contents[12]);
                testInfo.Speed2          = GetLineValue(contents[13]);
                testInfo.Acceleration1   = GetLineValue(contents[14]);
                testInfo.Acceleration2   = GetLineValue(contents[15]);
                testInfo.Break           = GetLineValue(contents[18]);
                testInfo.NOOfSets        = GetLineValue(contents[22]);
                testInfo.NOOfRepetitions = GetLineValue(contents[23]);
                testInfo.InsuredSide     = GetLineValue(contents[28]);
                testInfo.Therapist       = GetLineValue(contents[30]);
                testInfo.Gravitycomp     = GetLineValue(contents[31]);

                testInfo.DataFileName = "";

                testInfo.Ath_ID = testAthInfoModel.ID;
                #endregion

                #region 检查是否重复导入
                if (ischeckRepeate)
                {
                    //检测是否有相同时间的数据导入
                    try
                    {
                        //判断该测试信息是否导入,判断条件 用户ID 测试日期,数据文件名
                        List <Model.TB_TestInfo> existsTestInfoList = testInfoBLL.GetModelList("ath_id=" + testInfo.Ath_ID + " and testdate=#" + testInfo.TestDate + "# and BaseFileName='" + testInfo.BaseFileName + "'");
                        if (existsTestInfoList.Count > 0)//有重复数据
                        {
                            existsIDs += existsTestInfoList[0].ID + ",";
                            Model.ExistsFileModel exFileModel = new Model.ExistsFileModel();
                            exFileModel.FileName = baseFileName;
                            exFileModel.RealName = baseFileName.Substring(baseFileName.LastIndexOf("\\") + 1);
                            existsFiles.Add(exFileModel);
                            continue;
                        }
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show("检查此文件是否导入时出错!\r\n" + ee.Message, "系统错误");
                        errorModel             = new Model.ImportDataErrorModel();
                        errorModel.ErrorString = "3";
                        errorModel.FileName    = baseFileName;
                        errorModelList.Add(errorModel);
                        continue;
                    }
                }
                #endregion

                //导入
                try
                {
                    BaseDataUtil dataUtil = new BaseDataUtil();
                    dataUtil.SmoothValue = (int)smoothValue;
                    dataUtil.Weight      = testAthInfoModel.Ath_Weight;
                    if (testInfo.Gravitycomp.Trim() != "")
                    {
                        dataUtil.Gravitycomp = testInfo.Gravitycomp;
                    }
                    string fileName = dataUtil.WriteBaseData(contents);

                    testInfo.DataFileName = fileName;
                }
                catch (Exception ee)
                {
                    MessageBox.Show("计算出错!\r\n" + ee.Message, "系统错误");
                    errorModel             = new Model.ImportDataErrorModel();
                    errorModel.ErrorString = "4";
                    errorModel.FileName    = baseFileName;
                    errorModelList.Add(errorModel);
                    continue;
                }
                //添加到数据库
                try
                {
                    testInfoBLL.Add(testInfo);
                }
                catch (Exception ee)
                {
                    MessageBox.Show("添加测试信息出错,请稍候重试!\r\n" + ee.Message, "系统错误");
                    errorModel             = new Model.ImportDataErrorModel();
                    errorModel.ErrorString = "5";
                    errorModel.FileName    = baseFileName;
                    errorModelList.Add(errorModel);
                    continue;
                }
            }

            if (errorModelList.Count > 0)
            {
                tbErrorCount.Text     = errorModelList.Count + "个文件导入错误";
                ErrorPanel.Visibility = Visibility.Visible;
            }

            if (ischeckRepeate)
            {//如果检查重复并且存在重复数据就刷新数据列表
                if (existsFiles.Count > 0)
                {
                    btnReImport.IsEnabled = true;
                    RefrenshDataGridSource();
                }
                else
                {
                    btnReImport.IsEnabled = false;
                }
            }
        }
        //导入方法
        private void Import(string [] fileNames,bool ischeckRepeate)
        {
            importProgress.Maximum = fileNames.Count();
            importProgress.Minimum = 0;
            importProgress.Value = 0;
            double value = 0;
            UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(importProgress.SetValue);
            for (int i = 0; i < fileNames.Count(); i++) {
                if (importFlag == 1) {
                    break;
                }
                if (importFlag == 2) {
                    i--;
                    continue;
                }
                value += 1;
                Dispatcher.Invoke(updatePbDelegate,
                    System.Windows.Threading.DispatcherPriority.Background,
                    new object[] { ProgressBar.ValueProperty, value });

                Model.ImportDataErrorModel errorModel=null;

                string baseFileName=fileNames[i];

                #region 写入进度
                tbFileName.Text = "文件名:" + baseFileName.Substring(baseFileName.LastIndexOf("\\") + 1);
                tbContent1.Text = "";
                tbContent2.Text = "";
                tbContent3.Text = "";
                tbProgress.Text = (i + 1) + "/" + fileNames.Count();
                #endregion

                #region 读取数据文件信息
                string[] contents = File.ReadAllLines(baseFileName);

                if (!CheckFile(baseFileName, contents))
                {
                    continue;
                }
                for (int a = 0; a < 11; a++)
                {
                    tbContent1.Text += contents[a] + "\r\n";
                    tbContent2.Text += contents[11 + a] + "\r\n";
                    tbContent3.Text += contents[22 + a] + "\r\n";
                }

                string testDate = GetLineValue(contents[2]);
                string testTime = GetLineValue(contents[3]);
                DateTime testDateTime = DateTime.Now;
                if (testDate != "" && testTime != "")
                {
                    try
                    {
                        testDateTime = Convert.ToDateTime(testDate + " " + testTime, dtPointFormat);
                    }
                    catch {
                        testDateTime = DateTime.Now;
                    }
                }

                Model.TB_AthleteInfo athModel = new Model.TB_AthleteInfo();
                athModel.Ath_PinYin = athModel.Ath_Name = GetLineValue(contents[4]);
                athModel.Ath_Sex = DataUtil.AthleteSexUtil.GetSex(GetLineValue(contents[29]));
                athModel.Ath_TestDate = testDateTime;
                string birthdayStr = GetLineValue(contents[27]);
                if (birthdayStr != "")
                {
                    try
                    {
                        athModel.Ath_Birthday = Convert.ToDateTime(birthdayStr, dtLineFormat);
                    }
                    catch {
                        athModel.Ath_Birthday = DateTime.Now;
                    }
                }
                else {
                    athModel.Ath_Birthday = null;
                }
                athModel.Ath_Height = GetLineValue(contents[26]);
                athModel.Ath_Weight = GetLineValue(contents[25]);

                Model.TB_AthleteInfo testAthInfoModel = CheckAthInfo(athModel);
                if (testAthInfoModel == null) {
                    continue;
                }

                Model.TB_TestInfo testInfo = new Model.TB_TestInfo();
                testInfo.BaseFileName = contents[0].Trim();
                testInfo.TestTime = testInfo.TestDate = testDateTime;
                testInfo.Joint_Side = GetLineValue(contents[5]);
                testInfo.Test_Mode = GetLineValue(contents[6]);
                testInfo.Joint = GetLineValue(contents[7]);
                testInfo.Plane = GetLineValue(contents[8]);
                testInfo.Motion_Start = GetLineValue(contents[10]);
                testInfo.Motion_End = GetLineValue(contents[11]);
                testInfo.Speed1 = GetLineValue(contents[12]);
                testInfo.Speed2 = GetLineValue(contents[13]);
                testInfo.Acceleration1 = GetLineValue(contents[14]);
                testInfo.Acceleration2 = GetLineValue(contents[15]);
                testInfo.Break = GetLineValue(contents[18]);
                testInfo.NOOfSets = GetLineValue(contents[22]);
                testInfo.NOOfRepetitions = GetLineValue(contents[23]);
                testInfo.InsuredSide = GetLineValue(contents[28]);
                testInfo.Therapist = GetLineValue(contents[30]);
                testInfo.Gravitycomp = GetLineValue(contents[31]);

                testInfo.DataFileName = "";

                testInfo.Ath_ID = testAthInfoModel.ID;
                #endregion

                #region 检查是否重复导入
                if (ischeckRepeate) {
                    //检测是否有相同时间的数据导入
                    try
                    {
                        //判断该测试信息是否导入,判断条件 用户ID 测试日期,数据文件名
                        List<Model.TB_TestInfo> existsTestInfoList = testInfoBLL.GetModelList("ath_id=" + testInfo.Ath_ID + " and testdate=#" + testInfo.TestDate + "# and BaseFileName='" + testInfo.BaseFileName + "'");
                        if (existsTestInfoList.Count > 0)//有重复数据
                        {
                            existsIDs += existsTestInfoList[0].ID + ",";
                            Model.ExistsFileModel exFileModel = new Model.ExistsFileModel();
                            exFileModel.FileName = baseFileName;
                            exFileModel.RealName = baseFileName.Substring(baseFileName.LastIndexOf("\\") + 1);
                            existsFiles.Add(exFileModel);
                            continue;
                        }
                    }
                    catch (Exception ee)
                    {
                        MessageBox.Show("检查此文件是否导入时出错!\r\n" + ee.Message, "系统错误");
                        errorModel = new Model.ImportDataErrorModel();
                        errorModel.ErrorString = "3";
                        errorModel.FileName = baseFileName;
                        errorModelList.Add(errorModel);
                        continue;
                    }
                }
                #endregion

                //导入
                try
                {
                    BaseDataUtil dataUtil = new BaseDataUtil();
                    dataUtil.SmoothValue = (int)smoothValue;
                    dataUtil.Weight = testAthInfoModel.Ath_Weight;
                    if (testInfo.Gravitycomp.Trim() != "") {
                        dataUtil.Gravitycomp = testInfo.Gravitycomp;
                    }
                    string fileName = dataUtil.WriteBaseData(contents);

                    testInfo.DataFileName = fileName;
                }
                catch (Exception ee)
                {
                    MessageBox.Show("计算出错!\r\n" + ee.Message, "系统错误");
                    errorModel = new Model.ImportDataErrorModel();
                    errorModel.ErrorString = "4";
                    errorModel.FileName = baseFileName;
                    errorModelList.Add(errorModel);
                    continue;
                }
                //添加到数据库
                try
                {
                    testInfoBLL.Add(testInfo);
                }
                catch (Exception ee)
                {
                    MessageBox.Show("添加测试信息出错,请稍候重试!\r\n" + ee.Message, "系统错误");
                    errorModel = new Model.ImportDataErrorModel();
                    errorModel.ErrorString = "5";
                    errorModel.FileName = baseFileName;
                    errorModelList.Add(errorModel);
                    continue;
                }

            }

            if (errorModelList.Count > 0) {
                tbErrorCount.Text = errorModelList.Count + "个文件导入错误";
                ErrorPanel.Visibility = Visibility.Visible;
            }

            if (ischeckRepeate)
            {//如果检查重复并且存在重复数据就刷新数据列表
                if (existsFiles.Count > 0)
                {
                    btnReImport.IsEnabled = true;
                    RefrenshDataGridSource();
                }
                else {
                    btnReImport.IsEnabled = false;
                }
            }
        }