示例#1
0
        ///// <summary>
        ///// 若一条记录里有多个单上传控件字段,则每个上传控件的文件名和主键需保持一致
        ///// </summary>
        ///// <param name="path"></param>
        ///// <param name="fileStorageName"></param>
        ///// <returns></returns>
        //protected string GetSingleResourceInfo(string path, string fileStorageName)
        //{
        //    if (!path.IsEmpty())
        //    {
        //        var pathInfo = path.Split('&');
        //        string fileName = pathInfo[0].Substring(pathInfo[0].LastIndexOf('/') + 1);
        //        string fileID = fileName.Split('.')[0];
        //        string pathID = fileName.Substring(0, 8);
        //        string fileExt = Path.GetExtension(fileName);
        //        if (FileID.IsEmpty())
        //        {
        //            FileID = fileID;
        //        }
        //        else
        //        {
        //            //重命名
        //            string fullPath = new Uri(Path.Combine(FileManagementUtil.GetRootPath(fileStorageName, FilePathScheme.Physical), path)).LocalPath;
        //            string dir = Path.GetDirectoryName(fullPath);
        //            string newPath = new Uri(Path.Combine(dir, "\\" + FileID + fileExt)).LocalPath;
        //            File.Move(fullPath, newPath);
        //            File.Delete(fullPath);
        //            fileID = FileID;
        //        }
        //        var resourceInfo = new ResourceInfo();
        //        resourceInfo.InfoType = ResourceInfoType.Config;
        //        resourceInfo.FileId = fileID;
        //        resourceInfo.PathID = pathID.Value<int>();
        //        resourceInfo.ExtName = fileExt;
        //        resourceInfo.FileNameTitle = pathInfo[1];
        //        resourceInfo.FileSizeK = pathInfo[2].Value<int>();
        //        resourceInfo.StorageConfigName = fileStorageName;
        //        return AtawAppContext.Current.FastJson.ToJSON(resourceInfo);

        //    }
        //    return "";
        //}

        //protected string GetMultiResourceInfo(string pathList, string fileStorageName)
        //{

        //    //string fileExtension = Path.GetExtension(fileName);
        //    //string fileID = AtawAppContext.Current.UnitOfData.GetUniId();
        //    //int pathID = fileID.Substring(0, 8).Value<int>();
        //    //string relativePath = Path.Combine(FileManagementUtil.GetRelativePath(fileStorageName, pathID),
        //    //    FileManagementUtil.GetFileName(fileStorageName, fileID, fileExtension));
        //    //string fullPath = new Uri(Path.Combine(FileManagementUtil.GetRootPath(fileStorageName, FilePathScheme.Physical), relativePath)).LocalPath;
        //    //FileManagementUtil.ForeDirectories(FileManagementUtil.GetParentDirectory(fullPath));
        //    //string tempfile = Path.Combine(AtawAppContext.Current.MapPath, Callback.Src(tempPath));

        //    //if (File.Exists(tempfile))
        //    //{
        //    //    File.Copy(tempfile, fullPath, false);
        //    //    File.Delete(tempfile);
        //    //}
        //    if (pathList.IsEmpty())
        //        return "";
        //    var pathArr = pathList.Split(',');
        //    string fileName = "";
        //    List<ResourceInfo> infoList = new List<ResourceInfo>();
        //    pathArr.ToList().ForEach(a =>
        //    {
        //        if (!a.IsEmpty())
        //        {
        //            var path = a.Split('&');
        //            fileName = path[0].Substring(path[0].LastIndexOf('\\') + 1);
        //            string fileID = fileName.Split('.')[0];
        //            string pathID = fileName.Substring(0, 8);
        //            string fileExt = Path.GetExtension(fileName);
        //            var resourceInfo = new ResourceInfo();
        //            resourceInfo.InfoType = ResourceInfoType.Config;
        //            resourceInfo.FileId = fileID;
        //            resourceInfo.PathID = pathID.Value<int>();
        //            resourceInfo.ExtName = fileExt;
        //            resourceInfo.FileNameTitle = path[1];
        //            resourceInfo.FileSizeK = path[2].Value<int>();
        //            resourceInfo.StorageConfigName = fileStorageName;
        //            infoList.Add(resourceInfo);
        //        }
        //    });
        //    //var pathInfo = new FilePathInfo { PathID = pathID.ToString(), FileID = fileID, FileExtension = fileExtension };
        //    return AtawAppContext.Current.FastJson.ToJSON(infoList);
        //}

        public virtual void SetPostDataRow(ObjectData data, DataAction dataAction, string key)
        {
            // throw new NotImplementedException();
            // if(data.)
            if (SingleUploadColumns != null && SingleUploadColumns.Count > 0)
            {
                SingleUploadColumns.ForEach(a =>
                {
                    if (data.MODEFY_COLUMNS.Contains(a.Name))
                    {
                        string storange = a.Upload.StorageName;
                        string fpath    = data.Row[a.Name].ToString();
                        if (!fpath.IsEmpty())
                        {
                            ResourceArrange arrange = AtawAppContext.Current.FastJson.ToObject <ResourceArrange>(fpath);
                            if (arrange != null)
                            {
                                arrange.MoveKeyPath(key, storange);
                                data.Row[a.Name] = AtawAppContext.Current.FastJson.ToJSON(arrange);
                            }
                        }
                        //data.Row[a.Name] = GetSingleResourceInfo(fpath, a.Upload.StorageName);
                    }
                });
            }

            if (MultiUploadColumns != null && MultiUploadColumns.Count > 0)
            {
                MultiUploadColumns.ForEach(a =>
                {
                    if (data.MODEFY_COLUMNS.Contains(a.Name))
                    {
                        string storange = a.Upload.StorageName;
                        string fpath    = data.Row[a.Name].ToString();
                        if (!fpath.IsEmpty())
                        {
                            ResourceArrange arrange = AtawAppContext.Current.FastJson.ToObject <ResourceArrange>(fpath);
                            arrange.MoveKeyPath(key, storange);
                            if (arrange != null)
                            {
                                data.Row[a.Name] = AtawAppContext.Current.FastJson.ToJSON(arrange);
                            }
                        }
                        // data.Row[a.Name] = GetMultiResourceInfo(fpath, a.Upload.StorageName);
                    }
                });
            }
            if (MomeryColumns != null && MomeryColumns.Count > 0)
            {
                MomeryColumns.ForEach(a =>
                {
                    if (data.MODEFY_COLUMNS.Contains(a.Name))
                    {
                        string _regname = a.RegName;
                        IMomery rr      = AtawIocContext.Current.FetchInstance <IMomery>(_regname);
                        rr.AddText(data.Row[a.Name].ToString(), AtawAppContext.Current.UnitOfData);
                    }
                });
            }
        }
示例#2
0
        public static List <string> GetImageHttpList(string arrangeString, string config, string size)
        {
            List <string>   https   = new List <string>();
            ResourceArrange arrange = arrangeString.SafeJsonObject <ResourceArrange>();

            if (arrange != null && arrange.ResourceInfoList != null && arrange.ResourceInfoList.Count > 0)
            {
                if (arrange.CoverIndex >= 0)
                {
                    https.Add(GetHttpPath(config, arrange.ResourceInfoList[arrange.CoverIndex].FileId, size));
                }
                for (int i = 0; i < arrange.ResourceInfoList.Count; i++)
                {
                    if (i != arrange.CoverIndex)
                    {
                        https.Add(GetHttpPath(config, arrange.ResourceInfoList[i].FileId, size));
                    }
                }
            }

            return(https);
        }
示例#3
0
        public override BaseOptions Create()
        {
            //var options = base.Create();
            //var UploadType = base.Config.ControlType;
            //var options = base.Create() as BaseUploadOptions;
            //UploadConfig uploadC = new UploadConfig();
            //string UploadInfo = FileManagementUtil.getFileUploadInfo(UploadType.ToString());
            //uploadC.FileLength = System.Convert.ToInt64(UploadInfo.Split(' ')[0]);
            //uploadC.FileExtension = UploadInfo.Split(' ')[1];
            //uploadC.FilePath = UploadInfo.Split(' ')[2];
            //if (UploadType.ToString() == "ImageUpload")
            //{
            //    uploadC.ImageSizeHeight = System.Convert.ToInt32(UploadInfo.Split(' ')[3]);
            //    uploadC.ImageSizeWidth = System.Convert.ToInt32(UploadInfo.Split(' ')[4]);
            //}
            //options.Upload = this.Config.Upload;
            // options.Upload = uploadC;
            base.Create();
            if (this.Config.Upload != null && !this.Config.Upload.UploadName.IsEmpty())
            {
                var config = FileManagementUtil.GetFileUploadConfig(this.Config.Upload.UploadName);
                fBaseUploadOptions.FileSize          = config.MaxSize;
                fBaseUploadOptions.FileExtension     = config.Extensions;
                fBaseUploadOptions.StorageName       = this.Config.Upload.StorageName;
                fBaseUploadOptions.UploadName        = this.Config.Upload.UploadName;
                fBaseUploadOptions.ImageSizeHeight   = config.ImageSizeHeight;
                fBaseUploadOptions.ImageSizeWidth    = config.ImageSizeWidth;
                fBaseUploadOptions.HasDocumentCenter = this.Config.Upload.HasDocumentCenter;

                //if (fBaseUploadOptions is AtawImageDetailOptions)
                //{
                // var options = base.Create();
                if (this.Config.Upload != null && this.Config.Upload.StorageName != null)
                {
                    fBaseUploadOptions.StorageName = this.Config.Upload.StorageName;
                }
                if (!fBaseUploadOptions.StorageName.IsEmpty())
                {
                    DataTable dt = this.PageView.Data.Tables[this.FormView.TableName];
                    if (dt != null && dt.Columns.Contains(this.Config.Name))
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            string          _str    = row[this.Config.Name].ToString();
                            ResourceArrange arrange = _str.SafeJsonObject <ResourceArrange>();
                            if (arrange != null)
                            {
                                if (arrange.ResourceInfoList != null)
                                {
                                    foreach (ResourceInfo info in arrange.ResourceInfoList)
                                    {
                                        string _fid    = info.FileId;
                                        string _ext    = info.ExtName;
                                        int    _pathId = info.PathID;

                                        string _http = FileManagementUtil.GetFullPath(fBaseUploadOptions.StorageName, FilePathScheme.Http, _pathId, _fid, _ext);
                                        // string sConfig = this.fTextOptions.
                                        info.HttpPath = _http;
                                    }

                                    row[this.Config.Name] = AtawAppContext.Current.FastJson.ToJSON(arrange);
                                }
                            }
                        }
                    }
                }
                //}

                if (fBaseUploadOptions is SingleImageUploadOptions)
                {
                    var _op = (SingleImageUploadOptions)fBaseUploadOptions;
                    if (!config.ImageCutGroupName.IsEmpty())
                    {
                        var _list = FileManagementUtil.GetImageCutsByCutConfigName(config.ImageCutGroupName);

                        //var _cuts = FileManagementUtil.FileManagementConfig.ImageCutGroups;
                        //if (_cuts != null && _cuts.Count > 0)
                        //{
                        //    ImageCutGroup cut = _cuts.FirstOrDefault(a => a.Name == config.ImageCutName);
                        //    AtawDebug.Assert(cut != null && cut.ImageCutList.Count > 0, string.Format(ObjectUtil.SysCulture,
                        //        "名称为{0}的截图配置不存在,或者没有截图配置项", config.ImageCutName), this);
                        //var _cconfig = _list[0];
                        //_op.ImageSizeHeight = _cconfig.ImageSizeHeight;
                        //_op.ImageSizeWidth = _cconfig.ImageSizeWidth;
                        //如果ImageSizeHeight和ImageSizeWidth没有配置那么默认为0,如果为0那么将不限制你要裁剪的大小比例
                        if (config.ImageSizeHeight != null && !config.ImageSizeHeight.Equals("") && config.ImageSizeWidth != null && !config.ImageSizeWidth.Equals(""))
                        {
                            _op.ImageSizeHeight = config.ImageSizeHeight;
                            _op.ImageSizeWidth  = config.ImageSizeWidth;
                        }
                        else
                        {
                            _op.ImageSizeHeight = 0;
                            _op.ImageSizeWidth  = 0;
                        }

                        //}
                    }
                    // ((SingleImageUploadOptions)fBaseUploadOptions).ImageSizeHeight = config.ImageSizeHeight;
                    //((SingleImageUploadOptions)fBaseUploadOptions).ImageSizeWidth = config.ImageSizeWidth;
                    _op.IsCut = this.Config.Upload.IsCut;
                }
            }
            string colName   = this.Config.Name;
            string tableName = this.FormView.TableName;
            var    ds        = this.PageView.Data;

            //if (PageStyle == PageStyle.Detail || PageStyle == Core.PageStyle.List)
            //{
            //if (ds.Tables.Contains(tableName))
            //{
            //    foreach (DataRow row in ds.Tables[tableName].Rows)
            //    {
            //        string val = row[colName].ToString();
            //        if (!val.IsEmpty())
            //        {
            //            bool isError = false;
            //            ResourceInfo resourceInfo = null;
            //            try
            //            {
            //                resourceInfo = AtawAppContext.Current.FastJson.ToObject<ResourceInfo>(val);
            //            }
            //            catch
            //            {
            //                isError = true;
            //            }
            //            if (!isError)
            //            {
            //                string fileStorageName = this.Config.Upload.StorageName;
            //                string fullPath = FileManagementUtil.GetFullPath(fileStorageName, FilePathScheme.Http,
            //                    resourceInfo.PathID, resourceInfo.FileId, resourceInfo.ExtName);
            //                row[colName] = fullPath;
            //            }
            //        }
            //        //}
            //    }

            // }
            return(fBaseUploadOptions);
        }