コード例 #1
0
        public CommandResult <KCT_ACCOUNTSET> ImportDataToTempTable(string fileName)
        {
            CommandResult <KCT_ACCOUNTSET> result = new CommandResult <KCT_ACCOUNTSET>();

            result.Result = false;

            string filePath      = HttpContext.Current.Server.MapPath("~/data/" + fileName);
            string directoryPath = filePath.Substring(0, filePath.LastIndexOf('.'));

            try
            {
                FileCompress.Decompress(directoryPath, filePath);
            }
            catch (Exception e)
            {
                result.Message = e.Message;
                return(result);
            }
            #region 校验文件,获得帐套ID

            //key是TableName  value是保存到的文件名
            Dictionary <string, string> tableList = LoadBCPConfigTables();
            int    accountSetID   = 0;
            string accountSetName = string.Empty;
            ValidateUploadData(directoryPath, tableList, ref accountSetID, ref accountSetName);
            if (accountSetID == 0)
            {
                result.Message = "错误的数据文件!";
                try
                {
                    File.Delete(filePath);
                }
                catch { }
                return(result);
            }

            #endregion

            Dictionary <string, string> dicData = new Dictionary <string, string>();
            string[] strs = null;
            foreach (var tableInfo in tableList)
            {
                strs = tableInfo.Key.Split('.');
                dicData.Add(strs[0] + "..Temp_" + strs[strs.Length - 1], directoryPath + "\\" + tableInfo.Value + ".txt");
            }

            #region  除临时表中数据,不成功直接返回错误

            if (!DelTempTableData(accountSetID))
            {
                return(result);
            }

            #endregion

            //执行BCP导入数据到临时表中
            if (DataProvider.DirecImportData(dicData))
            {
                int r = ValidateAccountsetDataIsDel(accountSetID);
                if (r != 0)//等于0标识存储过程执行发生错误
                {
                    result.Result             = true;
                    result.IntResult          = r;
                    result.Entity.ID          = accountSetID;
                    result.Entity.ACCOUNTYEAR = accountSetName;
                }
            }
            return(result);
        }