/// <summary> /// 构造函数 /// </summary> /// <param name="DataSheet">图表对应的数据工作表</param> /// <param name="DrawingChart">Excel图形所在的Chart对象</param> /// <param name="ParentApp">此图表所在的Excel类的实例对象</param> /// <param name="DateSpan">此图表的TimeSpan跨度</param> /// <param name="type">此图表的类型,则枚举DrawingType提供</param> /// <param name="CanRoll">是图表是否可以滚动,即是动态图还是静态图</param> /// <param name="date_ColNum">此测斜点的监测数据工作表中的每一天与其在工作表中对应的列号, /// 以监测数据的日期key索引数据所在列号item</param> /// <param name="usedRg">监测曲线的数据范围,此Range对象中, /// 包括此工作表的UsedRange中的第一列,即深度的数据;但是不包括第一行的日期数据</param> /// <param name="Info">记录数据信息的文本框</param> /// <param name="FirstSeriesTag">第一条数据系列对应的Tag信息</param> /// <param name="ProcessRegionData">在施工进度工作表中,每一个基坑区域相关的各种信息,比如区域名称,区域的描述, /// 区域数据的Range对象,区域所属的基坑ID及其ID的数据等</param> /// <remarks></remarks> public ClsDrawing_Mnt_Incline(Excel.Worksheet DataSheet, Excel.Chart DrawingChart, Cls_ExcelForMonitorDrawing ParentApp, DateSpan DateSpan, DrawingType type, bool CanRoll, TextFrame2 Info, MonitorInfo DrawingTag, MntType MonitorType, Dictionary <DateTime, int> date_ColNum, Excel.Range usedRg, SeriesTag_Incline FirstSeriesTag, clsData_ProcessRegionData ProcessRegionData = null) : base(DataSheet, DrawingChart, ParentApp, type, CanRoll, Info, DrawingTag, MonitorType, DateSpan, new clsDrawing_Mnt_RollingBase.SeriesTag(FirstSeriesTag.series, FirstSeriesTag.ConstructionDate)) { // // -------------------------------------------- try { ClsDrawing_Mnt_Incline with_1 = this; with_1.P_rgMntData = usedRg; //'包括第一列,但是不包括第一行的日期。 Excel.Range colRange = usedRg.Columns[1] as Excel.Range; with_1.F_YValues = ExcelFunction.ConvertRangeDataToVector <Single>(colRange); with_1.Information = Info; with_1._ExcavationDepth_lineAndTextbox = FirstSeriesTag; with_1.F_dicDateAndColumnNumber = date_ColNum; with_1.P_ProcessRegionData = ProcessRegionData; with_1._inclineTopElevaion = Project_Expo.InclineTopElevaion; // ----- 集合数据的记录 with_1.F_DicSeries_Tag[(int)LowIndexOfObjectsInExcel.SeriesInSeriesCollection] = FirstSeriesTag; // -----对图例进行更新--------- //Call LegendRefresh(List_HasCurve) } catch (Exception ex) { MessageBox.Show("构造测斜曲线图出错。" + "\r\n" + ex.Message + "\r\n" + ex.TargetSite.Name, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private DateTime[] GetDate() { // ----------arrDateRange----------------------- 获取此工作表中的整个施工日期的数组(0-Based,数据类型为Date) Excel.Range rg_AllDay = default(Excel.Range); //注意此数组元素的类型为Object,而且其第一个元素的下标值有可能是(1,1) short startColNum = ColNum_FirstData_Displacement; short endColNum = (short)(F_arrBottomRightCorner[1]); rg_AllDay = F_shtMonitorData.Rows[RowNumForDate].Range(F_shtMonitorData.Cells[1, startColNum], F_shtMonitorData.Cells[1, endColNum]); DateTime[] arrDateRange = null; arrDateRange = ExcelFunction.ConvertRangeDataToVector <DateTime>(rg_AllDay); // DateTime Dt = default(DateTime); try { Dictionary <DateTime, int> dicDate = new Dictionary <DateTime, int>(); foreach (DateTime tempLoopVar_Dt in arrDateRange) { Dt = tempLoopVar_Dt; dicDate.Add(Dt, 0); } } catch (Exception ex) { MessageBox.Show("工作表中的日期字段出错,出错的日期为:" + Dt.ToString("yyyy/MM/dd") + " 。请检查工作表!" + "\r\n" + ex.Message + "\r\n" + "报错位置:" + ex.TargetSite.Name, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } return(arrDateRange); }
/// <summary> /// 当选择的数据工作表发生变化时引发 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks></remarks> public void listSheetsName_SelectedIndexChanged(object sender, EventArgs e) { this.F_shtMonitorData = (Excel.Worksheet)listSheetsName.SelectedValue; //wkbkData.Worksheets(listSheetsName.SelectedItem) string[] arrPointsTag = null; //此工作表中的测点的编号列表 //测点编号所在的起始行与末尾行 int startRow = RowNum_FirstData_WithoutDate; int endRow = F_shtMonitorData.UsedRange.Rows.Count; int endColumn = F_shtMonitorData.UsedRange.Columns.Count; F_arrBottomRightCorner = new[] { endRow, endColumn }; //'进行操作的工作表的UsedRange的右下角的行号与列号 if (endRow >= startRow) { Excel.Range rg_PointsTag = F_shtMonitorData.Columns[ColNum_PointsTag].Range(F_shtMonitorData.Cells[startRow, 1], F_shtMonitorData.Cells[endRow, 1]); arrPointsTag = ExcelFunction.ConvertRangeDataToVector <string>(rg_PointsTag); //------------ 将编号列表的每一个值与其对应的行号添加到字典dicPointTag_RowNum中 short TagsCount = (short)arrPointsTag.Length; LstbxDisplayAndItem[] arrPoints = new LstbxDisplayAndItem[TagsCount - 1 + 1]; int add = 0; int i = 0; foreach (string tag in arrPointsTag) { //在Excel数据表中,每一个监测点位的Tag所在的行号。 short RowNumToPointsTag = (short)(startRow + add); arrPoints[i] = new LstbxDisplayAndItem(tag, startRow + add); add++; i++; } //---------------------- 将编号列表的所有值显示在窗口的测点列表中 ListBoxPointsName.DisplayMember = LstbxDisplayAndItem.DisplayMember; ListBoxPointsName.ValueMember = LstbxDisplayAndItem.ValueMember; ListBoxPointsName.DataSource = arrPoints; //.Items.Clear() //.Items.AddRange(arr) //.SelectedIndex = 0 '选择列表中的第一项 // btnGenerate.Enabled = true; } else //说明此表中的监测数据行数小于1 { ListBoxPointsName.DataSource = null; //ListPointsName.Items.Clear() MessageBox.Show("此工作表没有合法数据(数据行数小于1行),请选择合适的工作表", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error); F_shtMonitorData = null; btnGenerate.Enabled = false; } }
/// <summary> /// 绘制距选定的日期(包括选择的日期)最近的日期的监测数据 /// </summary> /// <param name="dateThisDay">选定的施工日期</param> /// <param name="State">指示选定的日期所处的状态</param> /// <param name="Closestday">距离选定日期最近的日期,如果选定的日期在工作表中有数据,则等效于dateThisDay</param> /// <remarks></remarks> private void CurveRolling(DateTime dateThisDay, TodayState State, DateTime Closestday) { const string strDateFormat = AMEApplication.DateFormat; F_DicSeries_Tag[1].ConstructionDate = dateThisDay; //刷新滚动的曲线所代表的日期 bool blnHasCurve = false; // //进行监测曲线的滚动 MovingSeries.Values = F_YValues; //Y轴的数据 switch (State) { case TodayState.BeforeStartDay: MovingSeries.XValues = new object[] { null }; //不能设置为Series.Value=vbEmpty,因为这会将x轴标签中的某一个值设置为0.0。 MovingSeries.Name = dateThisDay.ToString(strDateFormat) + " :早于" + DateSpan.StartedDate.ToString(strDateFormat); blnHasCurve = false; break; case TodayState.AfterFinishedDay: MovingSeries.XValues = new object[] { null }; // VB语法: MovingSeries.XValues = {Nothing} MovingSeries.Name = dateThisDay.ToString(strDateFormat) + " :晚于" + DateSpan.FinishedDate.ToString(strDateFormat); blnHasCurve = false; break; case TodayState.DateNotFound: MovingSeries.Name = Closestday.ToString(strDateFormat) + "(" + dateThisDay.ToString(strDateFormat) + "无数据" + ")"; blnHasCurve = true; break; case TodayState.DateMatched: MovingSeries.Name = dateThisDay.ToString(strDateFormat); blnHasCurve = true; break; } if (blnHasCurve) { //--------------------------- 设置信息文本框中的信息 double max = 0; double min = 0; string StrdepthForMax = ""; string StrdepthForMin = ""; // var strcolumn = F_dicDateAndColumnNumber[Closestday]; //当天的监测数据的Range对象 var rgDisplacement = P_rgMntData.Columns[strcolumn] as Excel.Range; //只包含对应施工日期的监测数据的那一列Range对象 //当天的监测数据,这里只能定义为Object的数组,因为有可能单元格中会出现没有数据的情况。 object[] MonitorData = ExcelFunction.ConvertRangeDataToVector <object>(rgDisplacement); MovingSeries.XValues = MonitorData; //X轴的数据 // //find the maximun/Minimum displacement max = Sheet_Data.Application.WorksheetFunction.Max(MonitorData); min = Sheet_Data.Application.WorksheetFunction.Min(MonitorData); try { // find the corresponding depth of the maximun displacement //如果 MATCH 函数查找匹配项不成功,在Excel中它会返回错误值 #N/A。 而在VB.NET中,它会直接报错。 int Row_Max = Convert.ToInt32(rgDisplacement.Cells[1, 1].Row - 1 + Sheet_Data.Application.WorksheetFunction.Match(max, MonitorData, 0)); float sngDepthForMax = Convert.ToSingle( Sheet_Data.Cells[Row_Max, Data_Drawing_Format.Mnt_Incline.ColNum_Depth].Value); StrdepthForMax = sngDepthForMax.ToString("0.0"); } catch (Exception) { StrdepthForMax = " Null "; Debug.Print("搜索最大位移所对应的深度失败!"); } try { // find the corresponding depth of the mininum displacement //如果 MATCH 函数查找匹配项不成功,在Excel中它会返回错误值 #N/A。 而在VB.NET中,它会直接报错。 int Row_Min = Convert.ToInt32(rgDisplacement.Cells[1, 1].Row - 1 + Sheet_Data.Application.WorksheetFunction.Match(min, MonitorData, 0)); float sngDepthForMin = Convert.ToSingle( Sheet_Data.Cells[Row_Min, Data_Drawing_Format.Mnt_Incline.ColNum_Depth].Value); StrdepthForMin = sngDepthForMin.ToString("0.0"); } catch (Exception) { StrdepthForMin = " Null "; Debug.Print("搜索最小位移所对应的深度失败!"); } //在信息文本框中输出文本,记录当前曲线的最大与最小位移,以及出现的深度 Information.TextRange.Text = "Max:" + max.ToString("0.00") + "mm" + "\t" + "In depth of " + StrdepthForMax + "m" + "\r\n" + "Min:" + min.ToString("0.00") + "mm" + "\t" + "In depth of " + StrdepthForMin + "m"; } else { Information.TextRange.Text = "Max:" + "\t" + "In depth of " + "\r\n" + "Min:" + "\t" + "In depth of "; } }