/// <summary>
        /// WDM:飞机零组件质量特性数据结构表描述
        /// </summary>
        /// <param name="id">机型ID</param>
        /// <param name="fileName">wdm文件路径</param>
        /// <returns></returns>
        public static TOper[] GetOpers(string id, string fileName)
        {
            //string id = @"aaa2012-03-22 13:31:07NOO";
            id += "NOO";
            int c = GetOperCount(fileName, id);

            TOper[] topers = new TOper[c];

            IntPtr[] ptArray = new IntPtr[1];
            ptArray[0] = Marshal.AllocHGlobal((Marshal.SizeOf(typeof(TOper))) * 10000);
            IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TOper)));

            Marshal.Copy(ptArray, 0, pt, 1);
            GetOper(pt, fileName, id);
            for (int i = 0; i < c; i++)
            {
                TOper a = (TOper)Marshal.PtrToStructure((IntPtr)((UInt32)ptArray[0] + i * 1036), typeof(TOper));
                topers[i] = a;
            }
            Marshal.FreeHGlobal(ptArray[0]);
            Marshal.FreeHGlobal(pt);

            return(topers);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// WDM:飞机零组件质量特性数据结构表描述
        /// </summary>
        /// <param name="id">机型ID</param>
        /// <param name="fileName">wdm文件路径</param>
        /// <returns></returns>
        public static TOper[] GetOpers(string id)
        {
            //string id = @"aaa2012-03-22 13:31:07NOO";
            id += "NOO";
            string connectString = getWDMDBConnectionStrings();

            if (connectString == "")
            {
                return(null);
            }
            using (SqlConnection sqlCnt = new SqlConnection(connectString))
            {
                using (SqlCommand command = sqlCnt.CreateCommand())
                {
                    sqlCnt.Open();
                    string tableName = getWDMDBQueryName("WDM_OPER");//"select count(1) from mm_oper";
                    if (tableName == "")
                    {
                        return(null);
                    }
                    command.CommandText = "select count(1) from " + tableName + " where bb='" + id + "' and cc=0";
                    int     c      = Convert.ToInt32(command.ExecuteScalar());
                    TOper[] topers = new TOper[c];

                    command.CommandText = "Select * from " + tableName + " where bb='" + id + "' and cc=0";
                    SqlDataReader reader = command.ExecuteReader();             //执行SQL,返回一个“流”
                    int           i      = 0;
                    while (reader.Read())
                    {
                        TOper to = new TOper();
                        to.ID       = reader["id"].ToString();
                        to.BB       = reader["BB"].ToString();
                        to.TH       = reader["TH"].ToString();
                        to.MC       = reader["MC"].ToString();
                        to.TGW      = Convert.ToSingle(reader["TGW"]);
                        to.DGW      = Convert.ToSingle(reader["DGW"]);
                        to.SCW      = Convert.ToSingle(reader["SCW"]);
                        to.ZTW      = Convert.ToSingle(reader["ZTW"]);
                        topers[i++] = to;
                    }
                    return(topers);
                }
            }

            /*
             * int c = GetOperCount(fileName, id);
             * TOper[] topers = new TOper[c];
             *
             * IntPtr[] ptArray = new IntPtr[1];
             * ptArray[0] = Marshal.AllocHGlobal((Marshal.SizeOf(typeof(TOper))) * 10000);
             * IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TOper)));
             * Marshal.Copy(ptArray, 0, pt, 1);
             * GetOper(pt, fileName, id);
             * for (int i = 0; i < c; i++)
             * {
             *  TOper a = (TOper)Marshal.PtrToStructure((IntPtr)((UInt32)ptArray[0] + i * 1036), typeof(TOper));
             *  topers[i] = a;
             * }
             * Marshal.FreeHGlobal(ptArray[0]);
             * Marshal.FreeHGlobal(pt);
             *
             * return topers;
             */
        }
        /// <summary>
        /// WDM:飞机零组件质量特性数据结构表描述
        /// </summary>
        /// <param name="id">机型ID</param>
        /// <param name="fileName">wdm文件路径</param>
        /// <returns></returns>
        public static TOper[] GetOpers(string id)
        {
            //string id = @"aaa2012-03-22 13:31:07NOO";
            id += "NOO";
            string connectString = getWDMDBConnectionStrings();
            if (connectString == "")
            {
                return null;
            }
            using (SqlConnection sqlCnt = new SqlConnection(connectString))
            {
                using (SqlCommand command = sqlCnt.CreateCommand())
                {
                    sqlCnt.Open();
                    string tableName=getWDMDBQueryName("WDM_OPER");//"select count(1) from mm_oper";
                    if (tableName == "")
                    {
                        return null;
                    }
                    command.CommandText = "select count(1) from " + tableName+" where bb='"+id+"' and cc=0";
                    int c = Convert.ToInt32(command.ExecuteScalar());
                    TOper[] topers = new TOper[c];

                    command.CommandText = "Select * from " + tableName+" where bb='"+id+"' and cc=0";
                    SqlDataReader reader = command.ExecuteReader();		//执行SQL,返回一个“流”
                    int i = 0;
                    while (reader.Read())
                    {
                        TOper to = new TOper();
                        to.ID = reader["id"].ToString();
                        to.BB = reader["BB"].ToString();
                        to.TH = reader["TH"].ToString();
                        to.MC = reader["MC"].ToString();
                        to.TGW = Convert.ToSingle(reader["TGW"]);
                        to.DGW = Convert.ToSingle(reader["DGW"]);
                        to.SCW = Convert.ToSingle(reader["SCW"]);
                        to.ZTW = Convert.ToSingle(reader["ZTW"]);
                        topers[i++] = to;
                    }
                    return topers;
                }
            }

            /*
            int c = GetOperCount(fileName, id);
            TOper[] topers = new TOper[c];

            IntPtr[] ptArray = new IntPtr[1];
            ptArray[0] = Marshal.AllocHGlobal((Marshal.SizeOf(typeof(TOper))) * 10000);
            IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TOper)));
            Marshal.Copy(ptArray, 0, pt, 1);
            GetOper(pt, fileName, id);
            for (int i = 0; i < c; i++)
            {
                TOper a = (TOper)Marshal.PtrToStructure((IntPtr)((UInt32)ptArray[0] + i * 1036), typeof(TOper));
                topers[i] = a;
            }
            Marshal.FreeHGlobal(ptArray[0]);
            Marshal.FreeHGlobal(pt);

            return topers;
             */
        }