Пример #1
0
        /// <summary>
        /// 要给值的实体
        /// </summary>
        /// <param name="en">要给值的实体</param>
        /// <param name="file"></param>
        /// <param name="saveAsPath"></param>
        public WebFile(BP.En.Entity en, HtmlInputFile file, string saveAsPath)
        {
            if (file != null && file.Value.IndexOf(":") != -1)
            {
                /* 如果包含这二个字段。*/
                string fileName = file.PostedFile.FileName;
                fileName      = fileName.Substring(fileName.LastIndexOf("\\") + 1);
                this.FileName = fileName;

                string ext = "";
                if (fileName.IndexOf(".") != -1)
                {
                    ext = fileName.Substring(fileName.LastIndexOf(".") + 1);
                }
                this.FileExt = ext;

                if (saveAsPath != null)
                {
                    string fullFile = saveAsPath + "." + this.FileExt;
                    file.PostedFile.SaveAs(fullFile);
                    if (BP.DA.DataType.IsImgExt(ext))
                    {
                        System.Drawing.Image img = System.Drawing.Image.FromFile(fullFile);
                        this.ImgW = img.Width;
                        this.ImgH = img.Height;
                        img.Dispose();
                    }
                }

                if (en != null)
                {
                    en.SetValByKey("MyFileName", this.FileName);
                    en.SetValByKey("MyFileExt", this.FileExt);
                    en.SetValByKey("MyFileH", this.ImgH);
                    en.SetValByKey("MyFileW", this.ImgW);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 初始化附件信息
        /// 如果手工的上传的附件,就要把附加的信息映射出来.
        /// </summary>
        /// <param name="en"></param>
        public static void InitEntityAthInfo(BP.En.Entity en)
        {
            //求出保存路径.
            string path = en.EnMap.FJSavePath;

            if (path == "" || path == null || path == string.Empty)
            {
                path = BP.Sys.SystemConfig.PathOfDataUser + en.ToString() + "\\";
            }

            if (System.IO.Directory.Exists(path) == false)
            {
                System.IO.Directory.CreateDirectory(path);
            }

            //获得该目录下所有的文件.
            string[] strs       = System.IO.Directory.GetFiles(path);
            string   pkval      = en.PKVal.ToString();
            string   myfileName = null;

            foreach (string str in strs)
            {
                if (str.Contains(pkval + ".") == false)
                {
                    continue;
                }

                myfileName = str;
                break;
            }

            if (myfileName == null)
            {
                return;
            }

            /* 如果包含这二个字段。*/
            string fileName = myfileName;

            fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);

            en.SetValByKey("MyFilePath", path);

            string ext = "";

            if (fileName.IndexOf(".") != -1)
            {
                ext = fileName.Substring(fileName.LastIndexOf(".") + 1);
            }

            string reldir = path;

            if (reldir.Length > SystemConfig.PathOfDataUser.Length)
            {
                reldir =
                    reldir.Substring(reldir.ToLower().IndexOf(@"\datauser\") + @"\datauser\".Length).Replace(
                        @"\", "/");
            }
            else
            {
                reldir = "";
            }

            if (reldir.Length > 0 && Equals(reldir[0], '/') == true)
            {
                reldir = reldir.Substring(1);
            }

            if (reldir.Length > 0 && Equals(reldir[reldir.Length - 1], '/') == false)
            {
                reldir += "/";
            }

            en.SetValByKey("MyFileExt", ext);
            en.SetValByKey("MyFileName", fileName);
            en.SetValByKey("WebPath", "/DataUser/" + reldir + en.PKVal + "." + ext);

            string fullFile = path + @"\" + en.PKVal + "." + ext;

            System.IO.FileInfo info = new System.IO.FileInfo(fullFile);
            en.SetValByKey("MyFileSize", BP.DA.DataType.PraseToMB(info.Length));
            if (DataType.IsImgExt(ext))
            {
                System.Drawing.Image img = System.Drawing.Image.FromFile(fullFile);
                en.SetValByKey("MyFileH", img.Height);
                en.SetValByKey("MyFileW", img.Width);
                img.Dispose();
            }
            en.Update();
        }