public frmLockCurves() { // This call is required by the designer. InitializeComponent(); // Add any initialization after the InitializeComponent() call. //从存储文件中提取数据 mySettings_Application mySetting = new mySettings_Application(); object[] Date_Handle = null; Date_Handle = mySetting.Curve_BatchProcessing; if (Date_Handle != null) { // 将数据刷新到界面的列表中 int rowscount = Date_Handle.Length; this.MyDataGridView1.Rows.Add(rowscount); //必须要先添加行,然后才能在后面进行赋值,否则会出现索引不在集合内的报错。 //注意:第一行数据的行标为0,列表头所在行的下标为-1。 for (int rowNum = 0; rowNum <= rowscount - 1; rowNum++) { this.MyDataGridView1[0, rowNum].Value = Date_Handle[rowNum][0]; this.MyDataGridView1[1, rowNum].Value = Date_Handle[rowNum][1]; } } }
/// <summary> /// 执行 /// </summary> /// <remarks></remarks> public void btn_OK_Click(object sender, EventArgs e) { var a = this.MyDataGridView1.DataSource; // 提取frmRolling中已经选择的要进行滚动的监测曲线图对象 frmRolling RollingForm = APPLICATION_MAINFORM.MainForm.Form_Rolling; List <clsDrawing_Mnt_RollingBase> RollingMnts = RollingForm.F_SelectedDrawings.RollingMnt; // 提到表格中的数据 int rowscount = this.MyDataGridView1.Rows.Count; object[] Date_Handle = new object[rowscount - 2 + 1]; for (int rowNum = 0; rowNum <= rowscount - 2; rowNum++) { Date_Handle[rowNum] = new[] { this.MyDataGridView1[0, rowNum].Value, this.MyDataGridView1[1, rowNum].Value }; } //将结果保存到文件中 mySettings_Application mySetting = new mySettings_Application(); mySetting.Curve_BatchProcessing = Date_Handle; //将结果保存到文件中 mySetting.Save(); // //为每一个Excel图形创建一个线程 foreach (clsDrawing_Mnt_RollingBase RollingMnt in RollingMnts) { Thread thd = new Thread(new System.Threading.ThreadStart(LockOrDelete)); thd.Name = RollingMnt.Chart_App_Title; thd.Start(new[] { RollingMnt, Date_Handle }); } }
/// <summary> /// 程序的一些属性的初始值的设置,这些属性是与UI线程无关的属性,以在新的非UI线程中进行设置。 /// </summary> /// <remarks></remarks> private void myDefaltSettings() { mySettings_Application setting1 = new mySettings_Application(); ClsDrawing_PlanView.MonitorPointsInformation @struct = new ClsDrawing_PlanView.MonitorPointsInformation(); @struct.ShapeName_MonitorPointTag = "Tag"; @struct.pt_CAD_BottomLeft = new PointF(309598.527F, -119668.436F); @struct.pt_CAD_UpRight = new PointF(536642.644F, 201852.14F); @struct.pt_Visio_BottomLeft_ShapeID = 197; @struct.pt_Visio_UpRight_ShapeID = 217; setting1.MonitorPointsInfo = @struct; //在下面的Save方法中,不知为何为出现两次相同的报错:System.IO.FileNotFoundException //可以明确其于多线程无关,但是好在此异常对于程序的运行无影响。 setting1.Save(); }
/// <summary> /// 返回所有选择的测点的监测数组组成的大数组 /// </summary> /// <param name="RowNum_Tags"></param> /// <returns></returns> /// <remarks></remarks> private object[,] GetAllSelectedMonitorData(Excel.Worksheet sheetMonitorData, int[] RowNum_Tags) { //Dim Queue_SelectedData As New Queue(Of Object()) object[,] AllSelectedMonitorData = new object[RowNum_Tags.Length - 1 + 1, F_arrBottomRightCorner[1] - ColNum_FirstData_Displacement + 1]; object[,] arrAllData = null; //所有有效的监测数据,包括没有选择的测点上的数据,不包括日期行与测点编号列 Excel.Worksheet with_1 = sheetMonitorData; arrAllData = with_1.Range[with_1.Cells[RowNum_FirstData_WithoutDate, ColNum_FirstData_Displacement], with_1.Cells[F_arrBottomRightCorner[0], F_arrBottomRightCorner[1]]].Value; //---------------------- 所有选择的测点在工作表中对应的行号,并将行号对应到上面的数组arrAllData的行号 //先要处理Excel中的数组与VB中的数组的下标差的问题 byte diff_Row = RowNum_FirstData_WithoutDate - 0; byte diff_Col = ColNum_FirstData_Displacement - Information.LBound((System.Array)arrAllData, 2); //选择的测点编号所在的行对应到上面的ArrAllData数组中的行,第一个元素的下标为0 byte Count_ChosenTag = (byte)RowNum_Tags.Length; string[] arrChosenRownNum = new string[Count_ChosenTag - 1 + 1]; byte i2 = (byte)0; foreach (int RowNum_Tag in RowNum_Tags) { arrChosenRownNum[i2] = System.Convert.ToString(RowNum_Tag - diff_Row); i2++; } //------------ 为超级大数组赋值 mySettings_Application setting = new mySettings_Application(); bool blnCheckForEmpty = setting.CheckForEmpty; //Dim arrDataWithDate_EachTag(0 To UBound(arrAllData, 2) - LBound(arrAllData, 2) + 1) As Object if (!blnCheckForEmpty) { byte irow = (byte)0; foreach (short rownum in arrChosenRownNum) { for (short iCol = Information.LBound((System.Array)arrAllData, 2); iCol <= Information.UBound((System.Array)arrAllData, 2); iCol++) { //arrDataWithDate_EachTag(iCol - LBound(arrAllData, 2)) = arrAllData(rownum, iCol) AllSelectedMonitorData[irow, iCol - Information.LBound((System.Array)arrAllData, 2)] = arrAllData[rownum, iCol]; } //Queue_SelectedData.Enqueue(arrDataWithDate_EachTag) irow++; } } else { byte irow = (byte)0; foreach (byte rownum in arrChosenRownNum) { for (int iCol = Information.LBound((System.Array)arrAllData, 2); iCol <= Information.UBound((System.Array)arrAllData, 2); iCol++) { //如果单元格中是空字符串,而不是Nothing,则将其转换为Nothing。 object v = arrAllData[rownum, iCol]; if (v != null) { if (v.GetType() == typeof(string)) { if (v.ToString().Length == 0) { v = null; } } } //赋值 //arrDataWithDate_EachTag(iCol - LBound(arrAllData, 2)) = v AllSelectedMonitorData[irow, iCol - Information.LBound((System.Array)arrAllData, 2)] = v; } //Queue_SelectedData.Enqueue(arrDataWithDate_EachTag) irow++; } } return(AllSelectedMonitorData); }