Beispiel #1
0
 public static T Convert <T>(System.Data.Common.DbDataReader reader, ref T obj)
 {
     try
     {
         var fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public);
         foreach (var f in fields)
         {
             var col = reader.GetOrdinal(f.Name);
             if (col >= 0)
             {
                 f.SetValue(obj, ChangeType(reader.GetValue(col), f.FieldType));
             }
         }
         var props = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public);
         foreach (var p in props)
         {
             var col = reader.GetOrdinal(p.Name);
             if (col >= 0)
             {
                 p.SetValue(obj, ChangeType(reader.GetValue(col), p.PropertyType), null);
             }
         }
     }
     catch (Exception ex) { TraceLogger.Instance.WriteException(ex); throw; }
     return(obj);
 }
Beispiel #2
0
        public static MobileDeviceOther getMobileDeviceOther(System.Data.Common.DbDataReader reader)
        {
            MobileDeviceOther mobileDeviceOther = new MobileDeviceOther();

            mobileDeviceOther.MD_   = reader.GetString(reader.GetOrdinal("MD#"));
            mobileDeviceOther.Other = reader.GetString(reader.GetOrdinal("Other"));

            return(mobileDeviceOther);
        }
Beispiel #3
0
        public static MobileDeviceMutimedia getMobileDeviceMutimedia(System.Data.Common.DbDataReader reader)
        {
            MobileDeviceMutimedia mobileDeviceMutimedia = new MobileDeviceMutimedia();

            mobileDeviceMutimedia.MD_       = reader.GetString(reader.GetOrdinal("MD#"));
            mobileDeviceMutimedia.Mutimedia = reader.GetString(reader.GetOrdinal("Mutimedia"));

            return(mobileDeviceMutimedia);
        }
Beispiel #4
0
        public static MobileDeviceCC getMobileDeviceCC(System.Data.Common.DbDataReader reader)
        {
            MobileDeviceCC mobileDeviceCC = new MobileDeviceCC();

            mobileDeviceCC.MD_ = reader.GetString(reader.GetOrdinal("MD#"));
            mobileDeviceCC.CC  = reader.GetString(reader.GetOrdinal("CC"));

            return(mobileDeviceCC);
        }
Beispiel #5
0
        public static Manufacture getManufacture(System.Data.Common.DbDataReader reader)
        {
            Manufacture manufacture = new Manufacture();

            manufacture.ManuName = reader.GetString(reader.GetOrdinal("ManuName"));
            manufacture.ManuURL  = reader.GetString(reader.GetOrdinal("ManuURL"));

            return(manufacture);
        }
Beispiel #6
0
        public static SMD getSMD(System.Data.Common.DbDataReader reader)
        {
            SMD SMD = new SMD();

            SMD.StoreName = reader.GetString(reader.GetOrdinal("StoreName"));
            SMD.MD_       = reader.GetString(reader.GetOrdinal("MD#"));
            SMD.SMDURL    = reader.GetString(reader.GetOrdinal("SMDURL"));
            SMD.SMDPrice  = reader.GetInt32(reader.GetOrdinal("SMDPrice"));

            return(SMD);
        }
Beispiel #7
0
        public static MobileDeviceReview getMobileDeviceReview(System.Data.Common.DbDataReader reader)
        {
            MobileDeviceReview mobileDeviceReview = new MobileDeviceReview();

            mobileDeviceReview.MD_            = reader.GetString(reader.GetOrdinal("MD#"));
            mobileDeviceReview.ReviewURL      = reader.GetString(reader.GetOrdinal("ReviewURL"));
            mobileDeviceReview.ReviewType     = reader.GetString(reader.GetOrdinal("ReviewType"));
            mobileDeviceReview.ReviewName     = reader.GetString(reader.GetOrdinal("ReviewName"));
            mobileDeviceReview.ReviewMainSite = reader.GetString(reader.GetOrdinal("ReviewMainSite"));

            return(mobileDeviceReview);
        }
Beispiel #8
0
        private static void QueryEmployee(Oracle.DataAccess.Client.OracleConnection conn)
        {
            string sql = "Select Emp_Id, Emp_No, Emp_Name, Mng_Id from Employee";

            // Tạo một đối tượng Command.
            Oracle.DataAccess.Client.OracleCommand cmd = new Oracle.DataAccess.Client.OracleCommand();

            // Liên hợp Command với Connection.
            cmd.Connection  = conn;
            cmd.CommandText = sql;


            using (System.Data.Common.DbDataReader reader = cmd.ExecuteReader())
            {
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        // Chỉ số (index) của cột Emp_ID trong câu lệnh SQL.
                        int empIdIndex = reader.GetOrdinal("Emp_Id"); // 0


                        long empId = Convert.ToInt64(reader.GetValue(0));

                        // Chỉ số của cột Emp_No là 1.
                        string empNo        = reader.GetString(1);
                        int    empNameIndex = reader.GetOrdinal("Emp_Name");// 2
                        string empName      = reader.GetString(empNameIndex);


                        int mngIdIndex = reader.GetOrdinal("Mng_Id");

                        long?mngId = null;

                        if (!reader.IsDBNull(mngIdIndex))
                        {
                            mngId = Convert.ToInt64(reader.GetValue(mngIdIndex));
                        }
                        Console.WriteLine("--------------------");
                        Console.WriteLine("empIdIndex:" + empIdIndex);
                        Console.WriteLine("EmpId:" + empId);
                        Console.WriteLine("EmpNo:" + empNo);
                        Console.WriteLine("EmpName:" + empName);
                        Console.WriteLine("MngId:" + mngId);
                    }
                }
            }
        }
Beispiel #9
0
        public static GPU getGPU(System.Data.Common.DbDataReader reader)
        {
            GPU GPU = new GPU();

            GPU.GPU_         = reader.GetString(reader.GetOrdinal("GPU#"));
            GPU.ManuName     = reader.GetString(reader.GetOrdinal("ManuName"));
            GPU.GPUName      = reader.GetString(reader.GetOrdinal("GPUName"));
            GPU.Cores        = reader.GetString(reader.GetOrdinal("Cores"));
            GPU.BaseClock    = reader.GetString(reader.GetOrdinal("BaseClock"));
            GPU.BoostClock   = reader.GetString(reader.GetOrdinal("BoostClock"));
            GPU.MemorySpeed  = reader.GetString(reader.GetOrdinal("MemorySpeed"));
            GPU.MemoryConfig = reader.GetString(reader.GetOrdinal("MemoryConfig"));
            GPU.PowerDraw    = reader.GetString(reader.GetOrdinal("PowerDraw"));

            return(GPU);
        }
Beispiel #10
0
        public static LapTop getLapTop(System.Data.Common.DbDataReader reader)
        {
            LapTop laptop = new LapTop();

            laptop.MD_         = reader.GetString(reader.GetOrdinal("MD#"));
            laptop.CDPlayer    = reader.GetString(reader.GetOrdinal("CDPlayer"));
            laptop.Adapter     = reader.GetString(reader.GetOrdinal("Adapter"));
            laptop.Port        = reader.GetString(reader.GetOrdinal("Port"));
            laptop.Webcam      = reader.GetString(reader.GetOrdinal("Webcam"));
            laptop.CpuName     = reader.GetString(reader.GetOrdinal("CpuName"));
            laptop.CPUManuName = reader.GetString(reader.GetOrdinal("CPUManuName"));
            laptop.InPort      = reader.GetString(reader.GetOrdinal("InPort"));

            return(laptop);
        }
Beispiel #11
0
        public static x86CPU getX86CPU(System.Data.Common.DbDataReader reader)
        {
            x86CPU x86CPU = new x86CPU();

            x86CPU.CpuName    = reader.GetString(reader.GetOrdinal("CpuName"));
            x86CPU.ManuName   = reader.GetString(reader.GetOrdinal("ManuName"));
            x86CPU.CAndT      = reader.GetString(reader.GetOrdinal("CAndT"));
            x86CPU.BaseClock  = reader.GetString(reader.GetOrdinal("BaseClock"));
            x86CPU.TurboClock = reader.GetString(reader.GetOrdinal("TurboClock"));
            x86CPU.TDP        = reader.GetString(reader.GetOrdinal("TDP"));
            x86CPU.Graphics   = reader.GetString(reader.GetOrdinal("Graphics"));
            x86CPU.Cache      = reader.GetString(reader.GetOrdinal("Cache"));

            return(x86CPU);
        }
Beispiel #12
0
        public static Screen getScreen(System.Data.Common.DbDataReader reader)
        {
            Screen screen = new Screen();

            screen.Screen_    = reader.GetString(reader.GetOrdinal("Screen#"));
            screen.Resulation = reader.GetString(reader.GetOrdinal("Resulation"));
            screen.Reflash    = reader.GetString(reader.GetOrdinal("Reflash"));
            screen.SRGB       = reader.GetString(reader.GetOrdinal("SRGB"));
            screen.SType      = reader.GetString(reader.GetOrdinal("SType"));
            screen.Size       = reader.GetString(reader.GetOrdinal("Size"));
            screen.HDR        = reader.GetString(reader.GetOrdinal("HDR"));

            return(screen);
        }
Beispiel #13
0
        public static string GetReaderValueString(System.Data.Common.DbDataReader reader, string name)
        {
            var ordinal = reader.GetOrdinal(name);

            if (reader.IsDBNull(ordinal))
            {
                return(null);
            }
            try
            {
                return(reader.GetString(ordinal));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(null);
        }
Beispiel #14
0
        public static Storage getStorage(System.Data.Common.DbDataReader reader)
        {
            Storage storage = new Storage();

            storage.Storage_        = reader.GetString(reader.GetOrdinal("Storage#"));
            storage.StorageName     = reader.GetString(reader.GetOrdinal("StorageName"));
            storage.ManuName        = reader.GetString(reader.GetOrdinal("ManuName"));
            storage.StorageType     = reader.GetString(reader.GetOrdinal("StorageType"));
            storage.StoragePort     = reader.GetString(reader.GetOrdinal("StoragePort"));
            storage.StorageCapacity = reader.GetString(reader.GetOrdinal("StorageCapacity"));

            return(storage);
        }
        /// <summary>
        /// Gets a float column. Slower then GetOrdinal + GetFloat
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static float GetFloat(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.GetFloat(ordinal));
        }
        /// <summary>
        /// Gets a double column. Slower then GetOrdinal + GetDouble
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static double GetDouble(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.GetDouble(ordinal));
        }
        /// <summary>
        /// Gets a float column. Slower then GetOrdinal + GetFloat
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static float?GetNFloat(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (float?)null : reader.GetFloat(ordinal));
        }
        /// <summary>
        /// Gets a bool column. Slower then GetOrdinal + GetBoolean
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool GetBoolean(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.GetBoolean(ordinal));
        }
        /// <summary>
        /// Gets a bool column. Slower then GetOrdinal + GetBool
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool?GetNBoolean(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (bool?)null : reader.GetBoolean(ordinal));
        }
        /// <summary>
        /// Gets an int column. Slower then GetOrdinal + GetInt32
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Int32 GetInt32(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.GetInt32(ordinal));
        }
Beispiel #21
0
        private int GetInt(System.Data.Common.DbDataReader RS, String FiledName)
        {
            int FieldID = RS.GetOrdinal(FiledName);

            return(RS.IsDBNull(FieldID) ? 0 : RS.GetInt32(FieldID));
        }
Beispiel #22
0
 private String GetString(System.Data.Common.DbDataReader RS, String FiledName)
 {
     return(RS.IsDBNull(RS.GetOrdinal(FiledName)) ? "" : RS[FiledName].ToString());
 }
        /// <summary>
        /// Gets a decimal column. Slower then GetOrdinal + GetDecimal
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static decimal?GetNDecimal(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (decimal?)null : reader.GetDecimal(ordinal));
        }
        /// <summary>
        /// Gets a datetime column. Slower then GetOrdinal + GetDateTime
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static DateTime?GetNDateTime(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (DateTime?)null : reader.GetDateTime(ordinal));
        }
        /// <summary>
        /// Gets a byte array column.
        /// Use this for small byte array only, such as timestamps
        ///
        /// Slower then GetOrdinal + GetByteArray(ordinal)
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name">The name of the column</param>
        /// <returns></returns>
        public static byte[]? GetByteArray(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? null : (byte[])reader.GetValue(ordinal));
        }
        /// <summary>
        /// Gets a string column. Slower then GetOrdinal + GetString
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string?GetNString(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? null : reader.GetString(ordinal));
        }
        /// <summary>
        /// Gets an int column. Slower then GetOrdinal + GetInt32
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Int32?GetNInt32(this System.Data.Common.DbDataReader reader, string name)
        {
            int ordinal = reader.GetOrdinal(name);

            return(reader.IsDBNull(ordinal) ? (int?)null : reader.GetInt32(ordinal));
        }
Beispiel #28
0
        public static MobileDevice getMobileDevice(System.Data.Common.DbDataReader reader)
        {
            MobileDevice mobileDevice = new MobileDevice();

            mobileDevice.MD_             = reader.GetString(reader.GetOrdinal("MD#"));
            mobileDevice.MDName          = reader.GetString(reader.GetOrdinal("MDName"));
            mobileDevice.MDType          = reader.GetString(reader.GetOrdinal("MDType"));
            mobileDevice.OfficialWebsite = reader.GetString(reader.GetOrdinal("OfficialWebsite"));
            mobileDevice.OS       = reader.GetString(reader.GetOrdinal("OS"));
            mobileDevice.Weight   = reader.GetString(reader.GetOrdinal("Weight"));
            mobileDevice.Size     = reader.GetString(reader.GetOrdinal("Size"));
            mobileDevice.Battery  = reader.GetString(reader.GetOrdinal("Battery"));
            mobileDevice.Warranty = reader.GetString(reader.GetOrdinal("Warranty"));
            mobileDevice.Ram      = reader.GetString(reader.GetOrdinal("Ram"));
            mobileDevice.ImageURL = reader.GetString(reader.GetOrdinal("ImageURL"));
            mobileDevice.Screen_  = reader.GetString(reader.GetOrdinal("Screen#"));
            mobileDevice.ManuName = reader.GetString(reader.GetOrdinal("ManuName"));
            mobileDevice.Series_  = reader.GetString(reader.GetOrdinal("Series#"));

            return(mobileDevice);
        }