示例#1
0
        public string GetDbValue(lib.Class.Reflection r, System.Reflection.PropertyInfo pi, bool IsSelect)
        {
            string value = "";
            Type   tp    = pi.PropertyType;

            lib.Class.Conversion Obj = new lib.Class.Conversion(r.GetPropertyValue(pi));

            if (tp == typeof(string))
            {
                if (IsSelect)
                {
                    value = string.Format("{0}", DbQuoted("%" + Obj.ToString() + "%"));
                }
                else
                {
                    value = string.Format("{0}", DbQuoted(Obj.ToString()));
                }
            }
            else if (tp == typeof(DateTime))
            {
                DateTime dt = Obj.ToDateTime();

                if (dt < lib.Class.Utils.StartGregorianCalendar())
                {
                    dt = DateTime.MinValue;
                }

                if (dt == DateTime.MinValue)
                {
                    value = "NULL";
                }
                else
                {
                    value = string.Format("'{0}'", dt.ToString("yyyy-MM-dd HH:mm:ss"));
                }
            }
            else if (tp == typeof(bool))
            {
                value = Obj.ToBool() ? "1" : "0";
            }
            else if (tp == typeof(decimal) || tp == typeof(double) || tp == typeof(float))
            {
                value = Obj.ToDecimal().ToString("0.00").Replace(",", ".");
            }
            else if (tp == typeof(int) || tp == typeof(long))
            {
                value = Obj.ToString();
            }
            else
            {
                value = Obj.ToString();
            }
            return(value);
        }
示例#2
0
        public void Assign(object o)
        {
            lib.Class.Reflection foParam = new lib.Class.Reflection(o);

            string[] flds = foParam.GetFields();
            for (int i = 0; i < flds.Length; i++)
            {
                foThis.SetField(flds[i], foParam.GetFieldValue(flds[i]));
            }

            string[] prps = foParam.GetProperties();
            for (int i = 0; i < prps.Length; i++)
            {
                foThis.SetProperty(prps[i], foParam.GetPropertyValue(prps[i]));
            }
        }