Exemple #1
0
        /// <summary>
        /// Execl导入到数据库
        /// </summary>
        /// <param name="Path">Execl路径</param>
        /// <param name="connEnum">Web.config配置文件中数据库信息的Name;例如:Hr</param>
        /// <param name="TableName">表的名称</param>
        /// <param name="Columns">表除去ID,CreateUserID,CreateUser,CreateDate,ModifyUserID,ModifyUser,ModifyDate之外的所有字段),例如:C1,C2</param>
        /// <param name="Titles">Execl表头,例如:T1,T2,T3</param>
        /// <param name="CreateId">创建人Id</param>
        /// <param name="CreateName">创建人名字</param>
        /// <param name="datetimeFormatTitles">需要格式化的日期字段</param>
        /// <returns></returns>
        public DataTable Import(string Path, ConnEnum connEnum, string TableName, string Columns, string Titles, string CreateId, string CreateName, string datetimeFormatColumns, string MainTitle)
        {
            DataTable dtNew = new DataTable();

            try
            {
                DataTable dt = ReadExcel(Path, MainTitle);
                dtNew = BuildTable(connEnum, dt, TableName, Columns, Titles, CreateId, CreateName, datetimeFormatColumns);
                SqlBulkCopy SqlCopy = new SqlBulkCopy(ConfigurationManager.ConnectionStrings[connEnum.ToString()].ConnectionString, SqlBulkCopyOptions.UseInternalTransaction);
                SqlCopy.SqlRowsCopied +=
                    new SqlRowsCopiedEventHandler(OnRowsCopied);    //订阅复制完成后的方法,参数是 sqlbulk.NotifyAfter的值
                SqlCopy.NotifyAfter          = dtNew.Rows.Count;
                SqlCopy.DestinationTableName = TableName;
                SqlCopy.WriteToServer(dtNew);
                _totalCount = dtNew.Rows.Count;
            }
            catch (Formula.Exceptions.BusinessException ex)
            {
                _error = ex.Message;
            }
            return(dtNew);
        }
Exemple #2
0
 public static SQLHelper CreateSqlHelper(ConnEnum connName)
 {
     return(CreateSqlHelper(connName.ToString()));
 }
Exemple #3
0
 public static void RegistEntities <T>(ConnEnum conn)
 {
     _entitiesDic[typeof(T).FullName] = conn.ToString();
 }