Пример #1
0
        /// <summary>
        /// 获取数据库的大小
        /// </summary>
        /// <returns></returns>
        public virtual double GetDBSize()
        {
            DataSet ds = Helper.RunProcedureDs("sp_spaceused");
            string  r  = (string)ds.Tables[0].Rows[0]["database_size"];

            return(CommOp.ToDouble(r.Split(' ')[0]));
        }
Пример #2
0
        private void SetCellValue(ICell cell, object obj)
        {
            if (obj == null)
            {
                cell.SetCellValue("");
                return;
            }
            Type type = obj.GetType();

            if (type == typeof(bool) || type == typeof(bool?))
            {
                cell.SetCellValue(CommOp.ToBool(obj));
            }
            else if (CommOp.ToDecimal(obj).ToString() == obj.ToString())
            {
                cell.SetCellValue(CommOp.ToDouble(obj));
            }
            else if (type == typeof(DateTime))
            {
                cell.SetCellValue(CommOp.ToDateTime(obj));
            }
            else
            {
                cell.SetCellValue(CommOp.ToStr(obj));
            }
        }
Пример #3
0
        public void TestGetDataSetReadXlsx1()
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestData", "2013年苏里格气田扩边新发现table.xlsx");

            ExcelHelper helper = new ExcelHelper(path);
            DataSet     ds     = helper.ExcelToDataSet(true);

            Assert.AreEqual(3156.23, CommOp.ToDouble(ds.Tables["类比表"].Rows[4]["类比气藏"]));
        }
Пример #4
0
        public void TestGetDataSetReadXlsx()
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestData", "2013年苏里格气田扩边新发现table.xlsx");

            ExcelHelper helper = new ExcelHelper(path);
            DataSet     ds     = helper.ExcelToDataSet(false);

            Assert.AreEqual(3589.37, CommOp.ToDouble(ds.Tables["参数表"].Rows[7]["C"]));
        }
Пример #5
0
        public void TestReadXls1()
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestData", "2014年长庆油流向表油.xls");

            ExcelHelper helper = new ExcelHelper(path);
            DataTable   dt     = helper.ExcelToDataTable("区块数", true);

            Assert.AreEqual(5, CommOp.ToDouble(dt.Rows[4]["序号"]));
        }
Пример #6
0
        public void TestReadXls0()
        {
            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestData", "2014年长庆油流向表油.xls");

            ExcelHelper helper = new ExcelHelper(path);
            DataTable   dt     = helper.ExcelToDataTable("2014年分年度", false);

            Assert.AreEqual(132.486469471686, CommOp.ToDouble(dt.Rows[17]["K"]));
        }
Пример #7
0
        public void TestReadXlsxStream0()
        {
            string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestData", "2013年苏里格气田扩边新发现table.xlsx");

            Stream _innerStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            ExcelHelper helper = new ExcelHelper(_innerStream);
            DataTable   dt     = helper.ExcelToDataTable("参数表", false);

            Assert.AreEqual(3589.37, CommOp.ToDouble(dt.Rows[7]["C"]));
        }
Пример #8
0
        public void TestReadXlsStream0()
        {
            string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestData", "2014年长庆油流向表油.xls");

            Stream _innerStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            ExcelHelper helper = new ExcelHelper(_innerStream);
            DataTable   dt     = helper.ExcelToDataTable("2014年分年度", false);

            Assert.AreEqual(132.486469471686, CommOp.ToDouble(dt.Rows[17]["K"]));
        }
Пример #9
0
 /// <summary>
 /// 更新对象中字段的值
 /// </summary>
 /// <param name="obj">对象</param>
 /// <param name="fi">字段信息</param>
 /// <param name="value">值</param>
 /// <param name="actualType">值的类型,为空时自动判断</param>
 static void SetFieldValue(object obj, FieldInfo fi, string value, Type actualType = null)
 {
     if (fi == null)
     {
         return;
     }
     if (String.IsNullOrEmpty(value))
     {
         return;
     }
     if (PraserDict.ContainsKey(fi.FieldType))
     {
         var pvalue = PraserDict[fi.FieldType].Prase(value);
         if (pvalue == null)
         {
             return;
         }
         fi.SetValue(obj, pvalue);
         return;
     }
     if (fi.FieldType == typeof(string) || fi.FieldType == typeof(object)) //字段类型为String
     {
         fi.SetValue(obj, value);
     }
     else if (fi.FieldType == typeof(int) || fi.FieldType == typeof(Int64) || fi.FieldType == typeof(Int16))
     {
         fi.SetValue(obj, CommOp.ToLong(value));
     }
     else if (fi.FieldType == typeof(bool))
     {
         fi.SetValue(obj, CommOp.ToBool(value));
     }
     else if (fi.FieldType == typeof(double) || fi.FieldType == typeof(float))
     {
         fi.SetValue(obj, CommOp.ToDouble(value));
     }
     else if (fi.FieldType == typeof(decimal))
     {
         fi.SetValue(obj, CommOp.ToDecimal(value));
     }
     else if (fi.FieldType.IsEnum)
     {
         if (fi.FieldType.IsEnumDefined(value ?? ""))
         {
             fi.SetValue(obj, Enum.Parse(fi.FieldType, value));
         }
     }
     else
     {
         actualType = actualType ?? fi.FieldType;
         var p = JsonHelper.FormJson(value, actualType) ?? Activator.CreateInstance(actualType);
         fi.SetValue(obj, p);
     }
 }
Пример #10
0
        /// <summary>
        /// 将value中的值赋给对象的属性或字段
        /// </summary>
        /// <param name="obj">对象</param>
        /// <param name="propName">属性名</param>
        /// <param name="value">值</param>
        /// <param name="actualType">值的类型,为空时自动判断</param>
        public static void SetValue(object obj, string propName, string value, Type actualType = null)
        {
            //if (String.IsNullOrEmpty(value)) return;
            FieldInfo fi = obj.GetType().GetField(propName, bindAttr);

            if (fi != null)
            {
                SetFieldValue(obj, fi, value, actualType);
                return;
            }
            PropertyInfo pi = GetPropertyInfo(obj, propName);

            if (pi == null)
            {
                return;
            }
            if (!pi.CanWrite)
            {
                return;
            }
            if (PraserDict.ContainsKey(pi.PropertyType))
            {
                var pvalue = PraserDict[pi.PropertyType].Prase(value);
                if (pvalue == null)
                {
                    return;
                }
                pi.SetValue(obj, pvalue, null);
                return;
            }
            if (pi.PropertyType == typeof(string) || pi.PropertyType == typeof(object))
            {
                pi.SetValue(obj, value, null);
            }
            else if (pi.PropertyType == typeof(int))
            {
                pi.SetValue(obj, CommOp.ToInt(value), null);
            }
            else if (pi.PropertyType == typeof(Int64))
            {
                pi.SetValue(obj, CommOp.ToLong(value), null);
            }
            else if (pi.PropertyType == typeof(Int16))
            {
                pi.SetValue(obj, (short)CommOp.ToInt(value), null);
            }
            else if (pi.PropertyType == typeof(int?))
            {
                pi.SetValue(obj, CommOp.ToIntNull(value), null);
            }
            else if (pi.PropertyType == typeof(bool))
            {
                pi.SetValue(obj, CommOp.ToBool(value), null);
            }
            else if (pi.PropertyType == typeof(bool?))
            {
                pi.SetValue(obj, CommOp.ToBoolNull(value), null);
            }
            else if (pi.PropertyType == typeof(char))
            {
                pi.SetValue(obj, CommOp.ToChar(value), null);
            }
            else if (pi.PropertyType == typeof(double) || pi.PropertyType == typeof(float))
            {
                pi.SetValue(obj, CommOp.ToDouble(value), null);
            }
            else if (pi.PropertyType == typeof(decimal))
            {
                pi.SetValue(obj, CommOp.ToDecimal(value), null);
            }
            else if (pi.PropertyType.IsEnum)
            {
                if (CommOp.IsNumeric(value))
                {
                    var val = CommOp.ToInt(value);
                    if (pi.PropertyType.IsEnumDefined(val))
                    {
                        pi.SetValue(obj, Enum.Parse(pi.PropertyType, val.ToString()), null);
                    }
                }
                else
                {
                    var val = CommOp.ToStr(value);
                    if (pi.PropertyType.IsEnumDefined(val))
                    {
                        pi.SetValue(obj, Enum.Parse(pi.PropertyType, val), null);
                    }
                }
            }
            else if (pi.PropertyType == typeof(DateTime))
            {
                DateTime dt = CommOp.ToDateTime(value);
                if (dt == default(DateTime))
                {
                    return;
                }
                pi.SetValue(obj, dt, null);
            }
            else if (pi.PropertyType == typeof(DateTime?))
            {
                DateTime?dt = CommOp.ToDateTimeNull(value);
                pi.SetValue(obj, dt, null);
            }
            else
            {
                actualType = actualType ?? pi.PropertyType;
                var p = JsonHelper.FormJson(value, actualType) ?? Activator.CreateInstance(actualType);
                try
                {
                    pi.SetValue(obj, p, null);
                }
                catch
                {
                    throw;
                }
            }
        }