using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks; namespace WLYD.Utility.File
{
public class ImportCommon
{ public static string TitleRequiredValidate(PropertyInfo[] properties, Dictionary<int, string> titleDic)
{
foreach (var property in properties)
{
var attr = (DisplayAttribute)property.GetCustomAttribute(typeof(DisplayAttribute), false);
if (attr != null && !string.IsNullOrEmpty(attr.Name))
{
if (!titleDic.Values.Any(h => h == attr.Name))
{
return attr.Name;
}
}
}
return null;
} public static object StringToPropertyValue(PropertyInfo property, string src)
{
object obj = null;
switch (property.PropertyType.Name)
{
case "String":
return src;
case "Decimal":
return decimal.Parse(src);
case "Int32":
return int.Parse(src);
case "DateTime":
return DateTime.Parse(src);
case "Boolean":
return bool.Parse(src);
}
return obj;
} public static string GetPropertyByExcelName(PropertyInfo[] properties, string excelTitleName)
{
foreach (var property in properties)
{
var attr = (DisplayAttribute)property.GetCustomAttribute(typeof(DisplayAttribute), false);
if (attr != null && attr.Name == excelTitleName)
{
return property.Name;
}
}
return null;
} /// <summary>
/// 获取流编码
/// </summary>
/// <param name="fs"></param>
/// <returns></returns>
public static Encoding GetStreamEncode(Stream fs)
{
System.IO.BinaryReader br = new System.IO.BinaryReader(fs); Byte[] buffer = br.ReadBytes(2); if (buffer[0] >= 0xEF) { if (buffer[0] == 0xEF && buffer[1] == 0xBB) { return System.Text.Encoding.UTF8; } else if (buffer[0] == 0xFE && buffer[1] == 0xFF) { return System.Text.Encoding.BigEndianUnicode; } else if (buffer[0] == 0xFF && buffer[1] == 0xFE) { return System.Text.Encoding.Unicode; } else { return System.Text.Encoding.Default; } } else { return System.Text.Encoding.Default; }
}
}
}

  

ImportCommon的更多相关文章

随机推荐

  1. Codeforces Round #277 (Div. 2)D(树形DP计数类)

    D. Valid Sets time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Regex 手机号 座机 正則表達式

    近期在工作中须要推断一个号码是否是手机号,是否是座机号. 在网上也搜到了大家总结的方法,没有直接使用这些方法是由于:手机号码在不断開始新的号码段(比方17x).座机号中个别区号由于行政区域的变化而废除 ...

  3. 【转】VMware 11.0 简体中文版|附永久密钥

    VMware 11.0 简体中文版|附永久密钥 昨天,VMware虚拟机11.0 简体中文版正式发布,值得注意的是新版抛弃了32位系统支持,安装包体积大幅减小, 新增Windows 10 技术预览版支 ...

  4. 手把手教你nginx/linux下如何增加网站

    先进入到nginx的配置文件目录请输入以下命令 cd /alidata/server/nginx/conf/vhosts 再输入   ll 看看是不是像下面截图的一样 用神器xftp将default. ...

  5. Codeforces Round #267 (Div. 2) B. Fedor and New Game

    After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play ...

  6. Docker在centos下安装以及常见错误解决

    系列目录 Docker安装(使用阿里云镜像) Docker从1.13版本之后采用时间线的方式作为版本号,分为社区版CE和企业版EE. 社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收 ...

  7. ORACLE 36进制和10进制,互相转换函数

    第一部分 --36转10进制 create or replace function f_36to10 (str varchar) return int  is returnValue int;   s ...

  8. Qt 5.5.0 Windows环境搭建

    1)訪问官方站点:http://www.qt.io/download-open-source/ 2)选择离线安装包 3)选择 Windows 离线安装包(32 位或 64 位都可用,Windows 6 ...

  9. SQL还原数据库后,数据库显示受限制用户解决方法

    数据库->属性->选项

  10. httpclient4 模拟访问网页 模拟登录 简单例子

    JAVA后台模拟登录一个网站,获得一定权限后进一步操作. 所用的工具: Apache HttpComponents client 4.3版本 以下为代码: import org.apache.http ...