/// <summary> /// WDM:装载状态飞机结构特性表描述 /// </summary> /// <param name="id">机型ID</param> /// <param name="fileName">wdm文件路径</param> /// <returns></returns> public static TStmc[] GetStmcs(string id) { //string id = @"aaa2012-03-22 13:31:07NOS"; id += "NOS"; string connectString = getWDMDBConnectionStrings(); if (connectString == "") { return(null); } using (SqlConnection sqlCnt = new SqlConnection(connectString)) { using (SqlCommand command = sqlCnt.CreateCommand()) { sqlCnt.Open(); string tableName = getWDMDBQueryName("WDM_STMC"); if (tableName == "") { return(null); } command.CommandText = "select count(1) from " + tableName + " where bb='" + id + "'"; int c = Convert.ToInt32(command.ExecuteScalar()); TStmc[] tstmcs = new TStmc[c]; command.CommandText = "Select * from " + tableName + " where bb='" + id + "'"; SqlDataReader reader = command.ExecuteReader(); //执行SQL,返回一个“流” int i = 0; while (reader.Read()) { TStmc ts = new TStmc(); ts.ID = reader["id"].ToString(); ts.BB = reader["BB"].ToString(); ts.MC = reader["MC"].ToString(); ts.ZTW = Convert.ToSingle(reader["ZTW"]); ts.XCG = Convert.ToSingle(reader["XCG"]); ts.XCG = Convert.ToSingle(reader["XCG"]); tstmcs[i++] = ts; } return(tstmcs); } } /* * int c = GetStmcCount(fileName, id); * TStmc[] tstmc = new TStmc[c]; * * IntPtr[] ptArray = new IntPtr[1]; * ptArray[0] = Marshal.AllocHGlobal((Marshal.SizeOf(typeof(TStmc))) * 1000); * IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TStmc))); * Marshal.Copy(ptArray, 0, pt, 1); * GetStmc(pt, fileName, id); * for (int i = 0; i < c; i++) * { * TStmc a = (TStmc)Marshal.PtrToStructure((IntPtr)((UInt32)ptArray[0] + i * 368), typeof(TStmc)); * tstmc[i] = a; * } * Marshal.FreeHGlobal(ptArray[0]); * Marshal.FreeHGlobal(pt); * return tstmc; * */ }
/// <summary> /// WDM:装载状态飞机结构特性表描述 /// </summary> /// <param name="id">机型ID</param> /// <param name="fileName">wdm文件路径</param> /// <returns></returns> public static TStmc[] GetStmcs(string id) { //string id = @"aaa2012-03-22 13:31:07NOS"; id += "NOS"; string connectString = getWDMDBConnectionStrings(); if (connectString == "") { return null; } using (SqlConnection sqlCnt = new SqlConnection(connectString)) { using (SqlCommand command = sqlCnt.CreateCommand()) { sqlCnt.Open(); string tableName = getWDMDBQueryName("WDM_STMC"); if (tableName == "") { return null; } command.CommandText = "select count(1) from " + tableName+" where bb='"+id+"'"; int c = Convert.ToInt32(command.ExecuteScalar()); TStmc[] tstmcs = new TStmc[c]; command.CommandText = "Select * from " + tableName+" where bb='"+id+"'"; SqlDataReader reader = command.ExecuteReader(); //执行SQL,返回一个“流” int i = 0; while (reader.Read()) { TStmc ts = new TStmc(); ts.ID = reader["id"].ToString(); ts.BB = reader["BB"].ToString(); ts.MC = reader["MC"].ToString(); ts.ZTW = Convert.ToSingle(reader["ZTW"]); ts.XCG = Convert.ToSingle(reader["XCG"]); ts.XCG = Convert.ToSingle(reader["XCG"]); tstmcs[i++] = ts; } return tstmcs; } } /* int c = GetStmcCount(fileName, id); TStmc[] tstmc = new TStmc[c]; IntPtr[] ptArray = new IntPtr[1]; ptArray[0] = Marshal.AllocHGlobal((Marshal.SizeOf(typeof(TStmc))) * 1000); IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TStmc))); Marshal.Copy(ptArray, 0, pt, 1); GetStmc(pt, fileName, id); for (int i = 0; i < c; i++) { TStmc a = (TStmc)Marshal.PtrToStructure((IntPtr)((UInt32)ptArray[0] + i * 368), typeof(TStmc)); tstmc[i] = a; } Marshal.FreeHGlobal(ptArray[0]); Marshal.FreeHGlobal(pt); return tstmc; * */ }