Beispiel #1
0
        public string Import()
        {
            var result = new CheckEntityResult("操作成功");
            List <ImportBfCodeDto> data = null;

            try
            {
                EnsureFolderOnserver("FileUpload");
                var dataTable = CSVFile.Import(Request);
                var list      = new List <ImportBfCodeDto>();
                for (var i = 0; i < dataTable.Rows.Count; i++)
                {
                    var dataRow = dataTable.Rows[i];
                    var info    = new ImportBfCodeDto
                    {
                        ErrorMsg    = "",
                        CODE        = dataRow["编码"] == DBNull.Value ? "" : dataRow["编码"].ToString().Trim(),
                        DESCRIPTION = dataRow["描述"] == DBNull.Value ? "" : dataRow["描述"].ToString().Trim(),
                        DETAILCODE  = dataRow["明细编码"] == DBNull.Value ? "" : dataRow["明细编码"].ToString().Trim(),
                        DETAILNAME  = dataRow["明细名称"] == DBNull.Value ? "" : dataRow["明细名称"].ToString().Trim(),
                        SEQ_NUM     = dataRow["明细排序号"] == DBNull.Value ? "" : dataRow["明细排序号"].ToString().Trim()
                    };
                    list.Add(info);
                }
                var flag = (new BfCodeInfoManager()).BatchInsert(list, ref data);
                if (!flag)
                {
                    //todo:将来扩充分布式服务器,现有先发多服务器有问题
                    ICache cacheManager = new CacheManager();
                    var    errorKey     = UserSession.Current.UserID + "_BfCodeImport";
                    if (cacheManager.Exist(errorKey))
                    {
                        cacheManager.Remove(errorKey);
                    }
                    cacheManager.Add(errorKey, data, DateTime.Now.AddMinutes(10));
                    result.Success  = false;
                    result.ErrorKey = errorKey;
                    result.Msg      = "不成功";
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(this.GetType(), "", ex);
            }
            return(JsonConvert.SerializeObject(result));
        }