ImportCommon
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的更多相关文章
随机推荐
- 获取css信息
一般情况是用style直接获取css信息但是style只能获取到卸载行内的样式外链的和嵌入的样式会获取不到 2.5 用下面方法获取外链和嵌入的css样式 这种方法只能用于读取 window.getCo ...
- 【转载】读懂IL代码就这么简单(三)完结篇
一 前言 写了两篇关于IL指令相关的文章,分别把值类型与引用类型在 堆与栈上的操作区别详细的写了一遍这第三篇也是最后一篇,之所以到第三篇就结束了,是因为以我现在的层次,能理解到的都写完了,而且个人认为 ...
- Node.js 数据存储方式的选择
如何为你的 Node.js 应用挑选数据库 Node.js 应用一般有三种方式保存数据. 不使用任何数据库管理系统(DBMS),把数据保存在内存里或直接使用文件系统. 使用关系数据库.例如 MySQL ...
- java对象访问
下面这句代码: Object obj = new Object(); 对象引用在栈中,对象实体存在堆中,引用的方式有两种,分别是通过句柄访问对象和通过直接指针访问对象. Sun HotSpot使用第二 ...
- shell-函数、数组、正则
expect ssh远程脚本 expect非交互式 脚本代码如下: #!/usr/bin/expect set timeout spawn ssh -l root 192.168.1.1 expect ...
- LeetCode:二叉树的非递归中序遍历
第一次动手写二叉树的,有点小激动,64行的if花了点时间,上传leetcode一次点亮~~~ /* inorder traversal binary tree */ #include <stdi ...
- SQL还原数据库后,数据库显示受限制用户解决方法
数据库->属性->选项
- session自己定义存储,怎样更好地进行session共享;读tomcat7源代码,org.apache.catalina.session.FileStore可知
session自己定义存储.怎样更好地进行session共享: 读tomcat源代码,org.apache.catalina.session.FileStore可知 一.详见: 方法1 public ...
- 收集Oracle数据库中的SQL基线信息(一)基础信息收集
Oracle数据库中的SQL基线信息,当数据库出现性能问题时,在业务无法提供相应业务信息时,通过对比SQL基线信息来查找SQL的变化. 查找数据库一天内运行次数大于5000次的sqlid select ...
- AutoItLibrary安装和常见问题解决
http://blog.csdn.net/bible_reader/article/details/52044345