private SegmentRmsClass GetTableValue(String idfFilePath, String tableName, String condition) { SegmentRmsClass srCls = new SegmentRmsClass(); srCls.tableName = tableName; using (OleDbConnection sqlconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + idfFilePath + ";Persist Security Info=True")) { String sSQL = "select Id,KiloMeter,Speed,Segment_RMS,Segment_RMS_Peak,valid from " + tableName + condition; OleDbCommand sqlcom = new OleDbCommand(sSQL, sqlconn); sqlconn.Open(); OleDbDataReader sdr = sqlcom.ExecuteReader(); while (sdr.Read()) { SegmentRmsItemClass segmentRmsItemCls = new SegmentRmsItemClass(); segmentRmsItemCls.id = (int.Parse(sdr.GetValue(0).ToString())); segmentRmsItemCls.kiloMeter = (float.Parse(sdr.GetValue(1).ToString())); segmentRmsItemCls.speed = (float.Parse(sdr.GetValue(2).ToString())); segmentRmsItemCls.segmentRms = (float.Parse(sdr.GetValue(3).ToString())); segmentRmsItemCls.segmentRmsPeak = (float.Parse(sdr.GetValue(4).ToString())); segmentRmsItemCls.valid = (int.Parse(sdr.GetValue(5).ToString())); segmentRmsItemCls.channelName = tableName; srCls.segmentRmsItemClsList.Add(segmentRmsItemCls); } sdr.Close(); sqlconn.Close(); } return(srCls); }
private void ShowDataGridView(SegmentRmsClass segmentRmsCls) { dataGridView1.Rows.Clear(); for (int i = 0; i < segmentRmsCls.segmentRmsItemClsList.Count; i++) { DataGridViewRow dgvr = new DataGridViewRow(); dgvr.CreateCells(dataGridView1); dgvr.Cells[0].Value = segmentRmsCls.segmentRmsItemClsList[i].id; dgvr.Cells[1].Value = segmentRmsCls.segmentRmsItemClsList[i].kiloMeter; dgvr.Cells[2].Value = segmentRmsCls.segmentRmsItemClsList[i].speed; dgvr.Cells[3].Value = segmentRmsCls.segmentRmsItemClsList[i].segmentRms; dgvr.Cells[4].Value = segmentRmsCls.segmentRmsItemClsList[i].segmentRmsPeak; dgvr.Cells[5].Value = segmentRmsCls.segmentRmsItemClsList[i].valid; // liyang: 增加一列的数据,表示是否是道岔,这一列先加到所有列的后面,因为程序中别的地方用列的索引的时候是写死的 //dgvr.Cells[5].Value = segmentRmsCls.segmentRmsItemClsList[i].isDaoCha ? "是" :"否"; dgvr.Cells[6].Value = "请加载道岔位置表"; if (segmentRmsCls.segmentRmsItemClsList[i].valid == 0) { dgvr.DefaultCellStyle.BackColor = Color.LightGray; } else { if (segmentRmsCls.segmentRmsItemClsList[i].segmentRmsPeak >= float.Parse(textBoxPeakLine.Text)) { dgvr.Cells[4].Style.BackColor = Color.Red; } } dataGridView1.Rows.Add(dgvr); } AddListMenuItem(); }
//liyang: 选中一个idf, 或者在图表(左边)右键菜单选中一个别的通道时候,调用。 private void ShowMaxIn50m(String idfFile, String tableName) { SegmentRmsClass segmentRmsCls = GetTableValue(idfFile, tableName, ""); //ShowList(segmentRmsCls); ShowDataGridView(segmentRmsCls); // liyang: 用来显示最后一列,是否道岔,如果this.daoChaMileRange为空(道岔位置表还没有加载),这个函数不起作用。 ShowDataGridView(this.daoChaMileRange); }
/// <summary> /// 读取各个断面文件区段大值中的超标值 /// </summary> /// <returns>超标值列表</returns> private List <SegmentRmsItemClass> GetList() { List <SegmentRmsItemClass> tmp = new List <SegmentRmsItemClass>(); String searchPattern_rmsidf = "*Rms.idf"; String[] rmsIdfFiles = Directory.GetFiles(citDirectoryPath, searchPattern_rmsidf, SearchOption.TopDirectoryOnly); List <String> tableNames = null; if (String.IsNullOrEmpty(textBoxPeakLine.Text)) { MessageBox.Show("请设置直线和曲线超限值!"); return(tmp); } if (String.IsNullOrEmpty(textBoxDaoChaPeakLine.Text)) { MessageBox.Show("请设置道岔超限值!"); return(tmp); } //liyang: 修改成不加载道岔位置表,也能导出。只根据“曲线或直线超限阀值(默认为4)” 导出 //if (null == this.daoChaMileRange) //{ // MessageBox.Show("请导入道岔位置表!"); // return null; //} String condition = null; String strYes = "是"; String strNo = "否"; try { foreach (string rmsIdfFile in rmsIdfFiles) { if (rmsIdfFile.Contains(comboBoxFileAcclrtn.SelectedItem.ToString())) { String[] tmpStr = rmsIdfFile.Split('.'); tableNames = CommonClass.wdp.GetTableNames(rmsIdfFile); tableNames.RemoveAt(0); foreach (String str in tableNames) { condition = String.Format(" where (valid = 1)", textBoxPeakLine.Text); SegmentRmsClass srCls = GetTableValue(rmsIdfFile, str, condition); for (int i = 0; i < srCls.segmentRmsItemClsList.Count; i++) { bool isDaoCha = false; if (null != this.daoChaMileRange) {// liyang: 加入是否道岔的判断,并置上。 isDaoCha = this.daoChaMileRange.IsDaoChao(srCls.segmentRmsItemClsList[i].kiloMeter); srCls.segmentRmsItemClsList[i].isDaoCha = isDaoCha ? strYes : strNo; } else { srCls.segmentRmsItemClsList[i].isDaoCha = "未加载道岔位置表"; } // liyang: 加入针对于道岔的峰值的判断。 //liyang:是道岔就按照道岔的超限值判断 if (isDaoCha) { if (srCls.segmentRmsItemClsList[i].segmentRmsPeak >= float.Parse(textBoxDaoChaPeakLine.Text)) { tmp.Add(srCls.segmentRmsItemClsList[i]); } } else //liyang:不是道岔就按照直线曲线的超限值判断 { if (srCls.segmentRmsItemClsList[i].segmentRmsPeak >= float.Parse(textBoxPeakLine.Text)) { tmp.Add(srCls.segmentRmsItemClsList[i]); } } } //tmp.AddRange(srCls.segmentRmsItemClsList); } } } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } return(tmp); }
private void PictureChart(String idfFile, String tableName) { SegmentRmsClass segmentRmsCls = GetTableValue(idfFile, tableName, " where valid = 1"); double[][] d = QuerySUDU("select KiloMeter,Speed from " + tableName + " where valid = 1 order by KiloMeter"); tChart1.Series.Clear(); tChart1.Chart.Header.Text = "50米区段大值分布散点图"; //Points ps = new Points(); //for (int i = 0; i < segmentRmsCls.idList.Count; i++) //{ // ps.Add(segmentRmsCls.kiloMeterList[i], segmentRmsCls.segmentRmsList[i]); //} //ps.Color = Color.Blue; ////l.LinePen.Width = 1; //ps.Pointer.VertSize = 3; //ps.Pointer.HorizSize = 3; //ps.ShowInLegend = false; Points psBlue = new Points(); Points psRed = new Points(); if (isTPI == false) { tChart1.Text = "50米区段大值散点图"; for (int i = 0; i < segmentRmsCls.segmentRmsItemClsList.Count; i++) { if (segmentRmsCls.segmentRmsItemClsList[i].segmentRmsPeak < float.Parse(textBoxPeakLine.Text)) { psBlue.Add(segmentRmsCls.segmentRmsItemClsList[i].kiloMeter, segmentRmsCls.segmentRmsItemClsList[i].segmentRms); } else { if (reShow) { psRed.Add(segmentRmsCls.segmentRmsItemClsList[i].kiloMeter, segmentRmsCls.segmentRmsItemClsList[i].segmentRms); } else { psBlue.Add(segmentRmsCls.segmentRmsItemClsList[i].kiloMeter, segmentRmsCls.segmentRmsItemClsList[i].segmentRms); } } } } else { tChart1.Text = "轨道冲击指数散点图"; for (int i = 0; i < segmentRmsCls.segmentRmsItemClsList.Count; i++) { if (segmentRmsCls.segmentRmsItemClsList[i].segmentRmsPeak < float.Parse(textBoxPeakLine.Text)) { psBlue.Add(segmentRmsCls.segmentRmsItemClsList[i].kiloMeter, segmentRmsCls.segmentRmsItemClsList[i].segmentRmsPeak); } else { if (reShow) { psRed.Add(segmentRmsCls.segmentRmsItemClsList[i].kiloMeter, segmentRmsCls.segmentRmsItemClsList[i].segmentRmsPeak); } else { psBlue.Add(segmentRmsCls.segmentRmsItemClsList[i].kiloMeter, segmentRmsCls.segmentRmsItemClsList[i].segmentRmsPeak); } } } } psBlue.Color = Color.Blue; psBlue.Pointer.VertSize = 3; psBlue.Pointer.HorizSize = 3; psBlue.ShowInLegend = false; psRed.Color = Color.Red; psRed.Pointer.VertSize = 3; psRed.Pointer.HorizSize = 3; psRed.ShowInLegend = false; tChart1.Axes.Left.Automatic = true; tChart1.Axes.Bottom.Automatic = true; tChart1.Axes.Bottom.Title.Text = "里程"; tChart1.Axes.Bottom.Title.TextAlign = StringAlignment.Center; if (isTPI == true) { tChart1.Axes.Left.Title.Text = "轨道冲击指数"; } else { tChart1.Axes.Left.Title.Text = "有效值"; } tChart1.Axes.Left.Title.TextAlign = StringAlignment.Center; tChart1.Axes.Left.AutomaticMinimum = false; tChart1.Axes.Left.Minimum = 0; tChart1.Axes.Right.Title.Text = "速度"; tChart1.Axes.Right.Title.TextAlign = StringAlignment.Center; tChart1.Axes.Right.AutomaticMinimum = false; tChart1.Axes.Right.Minimum = 0; tChart1.Axes.Right.MinAxisIncrement = 1; Line l = new Line(); for (int i = 0; i < d[0].Length; i++) { l.Add(d[0][i], d[1][i]); } l.Color = Color.RosyBrown; l.LinePen.Width = 3; l.ShowInLegend = false; l.CustomVertAxis = tChart1.Axes.Right; //tChart1.Axes.Right.Automatic = true; tChart1.Axes.Right.Visible = true; tChart1.Series.Add(l); String pictureName = String.Format("{0}_{1}.jpg", tableName, tChart1.Text); String picturePath = Path.Combine(citDirectoryPath, pictureName); tChart1.Series.Add(psBlue); tChart1.Series.Add(psRed); //tChart1.Export.Image.JPEG.Save(citDirectoryPath + "\\50米区段大值分布散点图.jpg"); tChart1.Export.Image.JPEG.Save(picturePath); }