/// <summary> /// 保存按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { //删除 _fixedTable = new UserFixedTable(waveformMaker.WaveformDataList[0].IndexOperator, waveformMaker.WaveformDataList[0].CitFile.iKmInc); _fixedTable.Clear(); //重新保存索引库 for (int i = 0; i < dgvMarkedPoints.Rows.Count; i++) { UserMarkedPoint markedPoint = new UserMarkedPoint(); markedPoint.ID = dgvMarkedPoints.Rows[i].Cells[0].Value.ToString(); markedPoint.FilePointer = long.Parse(dgvMarkedPoints.Rows[i].Cells[2].Value.ToString()); markedPoint.UserSetMileage = float.Parse(dgvMarkedPoints.Rows[i].Cells[3].Value.ToString()) * 1000; _fixedTable.MarkedPoints.Add(markedPoint); } _fixedTable.Save(); //创建计算后的索引库 MilestoneFix fix = new MilestoneFix(waveformMaker.WaveformDataList[0].CitFilePath, waveformMaker.WaveformDataList[0].IndexOperator); try { fix.ClearMilestoneFixTable(); fix.RunFixingAlgorithm(); fix.SaveMilestoneFixTable(); MessageBox.Show("保存成功!"); btnLoad_Click(sender, e); } catch (Exception ex) { MyLogger.LogError("手动里程修正失败", ex); MessageBox.Show("错误:" + ex.Message); } }
private void SaveToFile(string targetCitFile, bool diffFileName = false) { string idfFile = targetCitFile.Replace(".cit", ".idf"); if (diffFileName) { idfFile = targetCitFile.Replace(".cit", "_MileageFix.idf"); } IndexOperator indexOperator = new IndexOperator(); indexOperator.IndexFilePath = idfFile; FileInformation citHeaderInfo = _citProcess.GetFileInformation(targetCitFile); UserFixedTable fixedTable = new UserFixedTable(indexOperator, citHeaderInfo.iKmInc); fixedTable.Clear(); foreach (var kvp in _CorrResult) { FixParams.Sort(); bool isFind = false; UserMarkedPoint markedPoint = null; foreach (var item in FixParams) { CorrelationResult corrResult = kvp.Value.FirstOrDefault(p => p.ChannelID == item.ChannelID); if (corrResult != null) { if (item.Priority == 0 && !isFind) { isFind = true; continue; } if (isFind) { markedPoint = new UserMarkedPoint(); markedPoint.FilePointer = corrResult.FilePointer; markedPoint.UserSetMileage = kvp.Key.UserSetMileage; break; } } } if (markedPoint != null) { fixedTable.MarkedPoints.Add(markedPoint); } } if (fixedTable.MarkedPoints.Count > 0) { fixedTable.Save(); } }
/// <summary> /// 向idf文件中写入 /// </summary> /// <param name="idfFilePath"></param> private void WriteIdf(String idfFilePath) { bool writeResult = false; bool CacluteResult = false; try { UserFixedTable fixedTable = new UserFixedTable(waveformMaker.WaveformDataList[0].IndexOperator, waveformMaker.WaveformDataList[0].CitFile.iKmInc); fixedTable.Clear(); for (int i = 0; i < dataGridView1.Rows.Count; i++) { float mile = (int)dataGridView1.Rows[i].Cells[2].Value + (int)(dataGridView1.Rows[i].Cells[3].Value); UserMarkedPoint markedPoint = new UserMarkedPoint(); markedPoint.ID = (i + 1).ToString(); markedPoint.FilePointer = long.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()); markedPoint.UserSetMileage = mile; fixedTable.MarkedPoints.Add(markedPoint); } fixedTable.Save(); writeResult = true; } catch (Exception ex) { MyLogger.logger.Error("读取里程修正表错误:" + ex.Message + ",堆栈:" + ex.StackTrace); MessageBox.Show("错误:" + ex.Message); } try { MilestoneFix fix = new MilestoneFix(waveformMaker.WaveformDataList[0].CitFilePath, waveformMaker.WaveformDataList[0].IndexOperator); fix.RunFixingAlgorithm(); fix.SaveMilestoneFixTable(); CacluteResult = true; } catch (Exception ex) { MyLogger.logger.Error("手动里程修正失败:" + ex.Message + ",堆栈:" + ex.StackTrace); MessageBox.Show("错误:" + ex.Message); } if (writeResult && CacluteResult) { MessageBox.Show("创建并且写入成功!"); } }
/// <summary> /// 向idf文件中写入 /// </summary> /// <param name="citFilePath">cit文件路径----->来自里程快速校正中的选择cit文件的按钮</param /// <param name="numericUpDown1">跳变允许值----->来自里程快速校正中的 跳变容许值</param> /// <param name="innerdbpath">内部数据库-----></param> private string _writeIdf(String citFilePath, int numericUpDown1, string innerdbpath) { //String idfFileName = Path.GetFileNameWithoutExtension(citFilePath) + ".idf"; //String idfFilePath = Path.Combine(Path.GetDirectoryName(citFilePath), idfFileName); //if (!File.Exists(idfFilePath)) //{ // //MessageBox.Show("找不到波形索引文件!"); // Console.WriteLine("找不到波形索引文件!"); // return; //} //公共方法 ResultInfo resultInfo = new ResultInfo(); //读取cit文件 List <AutoIndex> autoIndexClsList = _readCit(citFilePath, numericUpDown1); String idfFileName = Path.GetFileNameWithoutExtension(citFilePath) + "_MileageFix" + ".idf"; String idfFilePath = Path.Combine(Path.GetDirectoryName(citFilePath), idfFileName); //设置附带数据库路径和链接字符串,流程修正使用 InnerFileOperator.InnerFilePath = innerdbpath; InnerFileOperator.InnerConnString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = {0}; Persist Security Info = True; Mode = Share Exclusive; Jet OLEDB:Database Password = iicdc; "; //InnerFileOperator.InnerConnString = "provider=Microsoft.Ace.OLEDB.12.0;extended properties=excel 12.0; Data Source = {0}; Persist Security Info = True; Mode = Share Exclusive; Extended Properties=Excel 12.0:Database Password = iicdc; "; try { _op = new IndexOperator(); _op.IndexFilePath = idfFilePath; CITFileProcess cit = new CITFileProcess(); FileInformation fileforma = cit.GetFileInformation(citFilePath); UserFixedTable fixedTable = new UserFixedTable(_op, fileforma.iKmInc); fixedTable.Clear(); for (int i = 0; i < autoIndexClsList.Count; i++) { float mile = autoIndexClsList[i].km_current + autoIndexClsList[i].meter_current; UserMarkedPoint markedPoint = new UserMarkedPoint(); markedPoint.ID = (i + 1).ToString(); markedPoint.FilePointer = autoIndexClsList[i].milePos; markedPoint.UserSetMileage = mile; fixedTable.MarkedPoints.Add(markedPoint); } fixedTable.Save(); try { MilestoneFix fix = new MilestoneFix(citFilePath, _op); fix.RunFixingAlgorithm(); fix.SaveMilestoneFixTable(); resultInfo.flag = 1; resultInfo.msg = ""; resultInfo.data = idfFilePath; } catch (Exception ex) { resultInfo.flag = 0; resultInfo.msg = ex.Message; } } catch (Exception ex) { resultInfo.flag = 0; resultInfo.msg = ex.Message; } return(JsonConvert.SerializeObject(resultInfo)); }