Example #1
0
        /// <summary>
        /// 
        /// </summary>
        public string PickUrl(Guid id)
        {
            //string path = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath +
            //    CY.Utility.Common.CodeInterface.DefaultImg.InstrumentDefaultImg.Dir +
            //    CY.Utility.Common.CodeInterface.DefaultImg.InstrumentDefaultImg.Name +
            //    CY.Utility.Common.CodeInterface.DefaultImg.InstrumentDefaultImg.Extention;
            string path = string.Empty;

            try
            {
                if (id != Guid.Empty)
                {
                    CY.CSTS.Core.Business.AnnexType type = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(
                           CY.Utility.Common.AnnexUtility.ImgAnnexType
                        );
                    if (type == null)
                    {
                        type = new CY.CSTS.Core.Business.AnnexType();
                        type.TypeName = "Img";
                        type.Save();
                    }
                    IEnumerable<CY.CSTS.Core.Business.Annex> annexes = CY.CSTS.Core.Business.Annex.SelectAnnexByContentID(id).AsEnumerable();
                    CY.CSTS.Core.Business.Annex img = null;
                    if (annexes != null)
                    {
                        img = annexes.Where(item => item.AnnexTypeID == type.Id) != null ? annexes.Where(item => item.AnnexTypeID == type.Id).FirstOrDefault() : null;
                        if (img != null)
                        {
                            if (File.Exists(
                                CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath +
                                img.AnnexURI
                                ))
                            {
                                path = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath + img.AnnexURI;
                            }
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return path;
        }
Example #2
0
        public AnnexType this[string key]
        {
            get
            {
                if (!string.IsNullOrEmpty(key) || dic[key] != null)
                {
                    CY.CSTS.Core.Business.AnnexType anneType = new CY.CSTS.Core.Business.AnnexType();
                    anneType.TypeName = dic[key].TypeName;
                    anneType.Id = dic[key].Id;
                    anneType.MarkOld();
                    return anneType;
                }
                return null;
            }
            set
            {

            }
        }
Example #3
0
        private bool StoreAnnex(System.Guid contentId, string name, string address, string type)
        {
            bool IsSucess = false;
            try
            {
                if (contentId != System.Guid.Empty)
                {
                    CY.CSTS.Core.Business.AnnexType annexType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(type);

                    if (annexType == null)
                    {
                        annexType = new CY.CSTS.Core.Business.AnnexType();
                        annexType.TypeName = type;
                        annexType.Save();
                    }
                    CY.CSTS.Core.Business.Annex annex = new CY.CSTS.Core.Business.Annex();
                    annex.ContentID = contentId;
                    annex.Name = name;
                    annex.AnnexURI = address;
                    annex.AnnexTypeID = annexType.Id;
                    annex.Save();
                    IsSucess = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
            return IsSucess;
        }
Example #4
0
        protected void SaveImg(System.Guid contentId)
        {
            try
            {
                if (contentId == System.Guid.Empty)
                {
                    return;
                }

                string[] strPaths = Request.Form.GetValues("imgpath");
                string[] strNames = Request.Form.GetValues("imgname");
                if (strPaths == null || strNames == null || strPaths.Length <= 0 || strNames.Length <= 0 || strPaths.Length != strNames.Length)
                {
                    return;
                }
                string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
                string dir = appPath + CY.Utility.Common.AnnexUtility.UnitAnneImgDir;
                DirectoryInfo di = new DirectoryInfo(dir);
                if (!di.Exists)
                {
                    di.Create();
                }

                CY.CSTS.Core.Business.AnnexType anneType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType);

                if (anneType == null)
                {
                    anneType = new CY.CSTS.Core.Business.AnnexType();
                    anneType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType;
                    anneType.Save();
                }

                string fileName = string.Empty;

                string fileExtention = string.Empty;

                CY.CSTS.Core.Business.Annex imgannex = null;

                for (int i = 0; i < strNames.Length; i++)
                {
                    fileName = CY.Utility.Common.FileUtility.GetFileName(strNames[i]);
                    //string fileSaveName = fileName + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString();
                    fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(strNames[i]);
                    imgannex = new CY.CSTS.Core.Business.Annex();
                    imgannex.ContentID = contentId;
                    imgannex.AnnexTypeID = anneType.Id;
                    imgannex.Name = fileName;
                    imgannex.AnnexURI = CY.Utility.Common.AnnexUtility.UnitAnneImgDir + fileName + fileExtention;
                    imgannex.Save();
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
        }
Example #5
0
        protected void SaveFiles(System.Guid contentId)
        {
            try
            {
                HttpFileCollection files = CY.Utility.Common.RequestUtility.GetHttpFiles();

                if (files != null)
                {
                    string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
                    string dirPath = appPath + CY.Utility.Common.AnnexUtility.UnitAnnexFileDir;
                    DirectoryInfo di = new DirectoryInfo(dirPath);
                    if (!di.Exists)
                    {
                        di.Create();
                    }
                    string fileExtention = string.Empty;
                    string fileName = string.Empty;
                    string filesaveName = string.Empty;
                    for (int i = 0; i < files.Count; i++)
                    {
                        if (files[i].ContentLength > 0)
                        {
                            fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(files[i].FileName);
                            fileName = CY.Utility.Common.FileUtility.GetFileName(files[i].FileName);
                            if (fileExtention != ".doc" &&
                                fileExtention != ".docx" &&
                                fileExtention != ".pdf" &&
                                fileExtention != ".txt" &&
                                fileExtention != ".text")
                            {
                                continue;
                            }
                            filesaveName = fileName + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString();
                            files[i].SaveAs(dirPath + filesaveName + fileExtention);
                            CY.CSTS.Core.Business.Annex annex = new CY.CSTS.Core.Business.Annex();
                            CY.CSTS.Core.Business.AnnexType anneType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.DocAnnexType);
                            if (anneType == null)
                            {
                                anneType = new CY.CSTS.Core.Business.AnnexType();
                                anneType.TypeName = CY.Utility.Common.AnnexUtility.DocAnnexType;
                                anneType.Save();
                            }
                            annex.AnnexTypeID = anneType.Id;
                            annex.ContentID = contentId;
                            annex.Name = fileName;
                            annex.AnnexURI = CY.Utility.Common.AnnexUtility.UnitAnnexFileDir + filesaveName + fileExtention;
                            annex.Save();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
        }
Example #6
0
        /// <summary>
        ///  Id  Indecator the Entity  Type Indecator the Img Type: big ,middler, small
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private byte[] HanlderData(HttpContext context)
        {
            StringBuilder sbResult = new StringBuilder();
            byte[] buffer = null;
            try
            {
                string strId = string.Empty;
                string strType = string.Empty;

                if (CY.Utility.Common.RequestUtility.IsGet)
                {
                    strId = CY.Utility.Common.RequestUtility.GetQueryString("Id");
                    strType = CY.Utility.Common.RequestUtility.GetQueryString("Type");
                }
                if (CY.Utility.Common.RequestUtility.IsPost)
                {
                    strId = CY.Utility.Common.RequestUtility.GetFormString("Id");
                    strType = CY.Utility.Common.RequestUtility.GetFormString("Type");
                }
                if (string.IsNullOrEmpty(strId) || !CY.Utility.Common.StringUtility.IsGuid(strId.Trim()))
                {
                    return new byte[1];
                }
                if (string.IsNullOrEmpty(strType))
                {
                    strType = CY.Utility.Common.CodeInterface.ImgInfo.BigImg;
                }

                string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
                string dirPath = appPath + CY.Utility.Common.AnnexUtility.SubsidieAnneImgDir;
                string fileName = string.Empty;
                string fileExtention = string.Empty;
                string fileType = strType;

                StreamReader reader = null;
                CY.CSTS.Core.Business.AnnexType anneType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType);
                if (anneType == null)
                {
                    anneType = new CY.CSTS.Core.Business.AnnexType();
                    anneType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType;
                    anneType.Save();
                }
                CY.CSTS.Core.Business.Annex imgAnnex = CY.CSTS.Core.Business.Annex.Load(new Guid(strId));

                if (imgAnnex != null)
                {
                    fileName = imgAnnex.Name;
                    fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgAnnex.AnnexURI);
                    if (File.Exists(dirPath + fileName + fileType + fileExtention))
                    {
                        reader = new StreamReader(dirPath + fileName + fileType + fileExtention);
                    }
                }

                if (reader != null)
                {
                    buffer = new byte[reader.BaseStream.Length];
                    reader.BaseStream.Read(buffer, 0, Convert.ToInt32(reader.BaseStream.Length));
                    reader.Close();
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
            if (buffer == null)
            {
                buffer = new byte[1];
            }
            return buffer;
        }
        protected string ConstructorUrl(CY.CSTS.Core.Business.view_INSTRUMENT instrument)
        {
            StringBuilder sbResult = new StringBuilder();
            string defaultPath = CY.Utility.Common.CodeInterface.DefaultImg.InstrumentDefaultImg.Dir +
                CY.Utility.Common.CodeInterface.DefaultImg.InstrumentDefaultImg.Name +
                CY.Utility.Common.CodeInterface.DefaultImg.InstrumentDefaultImg.Extention;
            string physicalRootPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
            try
            {
                sbResult.Append("[");

                if (instrument != null)
                {
                    CY.CSTS.Core.Business.AnnexType type = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(
                          CY.Utility.Common.AnnexUtility.ImgAnnexType
                        );

                    if (type == null)
                    {
                        type = new CY.CSTS.Core.Business.AnnexType() { TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType };
                        type.Save();
                    }

                    IEnumerable<CY.CSTS.Core.Business.Annex> imgs = instrument.GetAnnexs(CY.Utility.Common.AnnexUtility.ImgAnnexType);

                    if (imgs != null && imgs.Count() > 0)
                    {
                        string smallPath = string.Empty;

                        string middlePath = string.Empty;

                        string bigPath = string.Empty;

                        string virtualPath = string.Empty;

                        defaultPath = imgs.First().AnnexURI;

                        foreach (CY.CSTS.Core.Business.Annex i in imgs)
                        {
                            sbResult.Append("{");

                            virtualPath = CY.Utility.Common.SiteUtility.CurHttpContext.Server.MapPath(i.AnnexURI);

                            if (!string.IsNullOrEmpty(CY.Utility.Common.FileUtility.GetFileExtension(i.AnnexURI)))

                            smallPath = CY.Utility.Common.FileUtility.GetFileDirPath(virtualPath) +
                                CY.Utility.Common.FileUtility.GetFileName(virtualPath) +
                                CY.Utility.Common.CodeInterface.ImgInfo.SmallImg +
                                CY.Utility.Common.FileUtility.GetFileExtension(virtualPath);

                            middlePath = CY.Utility.Common.FileUtility.GetFileDirPath(virtualPath) +
                                CY.Utility.Common.FileUtility.GetFileName(virtualPath) +
                                CY.Utility.Common.CodeInterface.ImgInfo.MiddleImg +
                                CY.Utility.Common.FileUtility.GetFileExtension(virtualPath);

                            bigPath = CY.Utility.Common.FileUtility.GetFileDirPath(virtualPath) +
                                CY.Utility.Common.FileUtility.GetFileName(virtualPath) +
                                CY.Utility.Common.CodeInterface.ImgInfo.BigImg +
                                CY.Utility.Common.FileUtility.GetFileExtension(virtualPath);

                            if (string.IsNullOrEmpty(CY.Utility.Common.FileUtility.GetFileExtension(i.AnnexURI)))
                            {

                                smallPath = "/Content/Default/InstrumentDefault.jpg";

                            }

                            if (string.IsNullOrEmpty(CY.Utility.Common.FileUtility.GetFileExtension(i.AnnexURI)))
                            {

                                middlePath = "/Content/Default/InstrumentDefault.jpg";

                            }

                            if (string.IsNullOrEmpty(CY.Utility.Common.FileUtility.GetFileExtension(i.AnnexURI)))
                            {

                                bigPath = "/Content/Default/InstrumentDefault.jpg";

                            }

                            if (!string.IsNullOrEmpty(CY.Utility.Common.FileUtility.GetFileExtension(i.AnnexURI)))
                            {
                                sbResult.Append(string.Format("small:'{0}'", CY.Utility.Common.StringUtility.EscapeString(
                                    File.Exists(smallPath) ? CY.Utility.Common.FileUtility.GetHttpDirPath(@i.AnnexURI.Replace("\\", "/")) + @i.Name + "_small" + CY.Utility.Common.FileUtility.GetFileExtension(@i.AnnexURI) : defaultPath
                                    )));

                                sbResult.Append(string.Format(",middle:'{0}'", CY.Utility.Common.StringUtility.EscapeString(
                                    File.Exists(middlePath) ? CY.Utility.Common.FileUtility.GetHttpDirPath(@i.AnnexURI.Replace("\\", "/")) + @i.Name + "_middle" + CY.Utility.Common.FileUtility.GetFileExtension(@i.AnnexURI) : defaultPath
                                   )));

                                sbResult.Append(string.Format(",big:'{0}'", CY.Utility.Common.StringUtility.EscapeString(
                                    File.Exists(bigPath) ? CY.Utility.Common.FileUtility.GetHttpDirPath(@i.AnnexURI.Replace("\\", "/")) + @i.Name + "_big" + CY.Utility.Common.FileUtility.GetFileExtension(@i.AnnexURI) : defaultPath
                                   )));
                            }
                            else {
                                sbResult.Append(string.Format("small:'{0}'", CY.Utility.Common.StringUtility.EscapeString(
                                   smallPath
                                   )));

                                sbResult.Append(string.Format(",middle:'{0}'", CY.Utility.Common.StringUtility.EscapeString(
                                   middlePath
                                   )));

                                sbResult.Append(string.Format(",big:'{0}'", CY.Utility.Common.StringUtility.EscapeString(
                                    bigPath
                                   )));
                            }

                            sbResult.Append("},");
                        }
                        if (imgs.Count() > 0)
                        {
                            sbResult.Remove(sbResult.Length - 1, 1);
                        }
                    }
                }

                sbResult.Append("]");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return sbResult.ToString();
        }
        private void SaveImg(System.Guid contentId)
        {
            try
            {
                string[] imgNames = null;
                string[] imgPaths = null;
                if (string.IsNullOrEmpty(CY.Utility.Common.RequestUtility.GetFormString("imgpath")) || string.IsNullOrEmpty(CY.Utility.Common.RequestUtility.GetFormString("imgname")))
                {
                    return;
                }
                imgPaths = CY.Utility.Common.RequestUtility.GetFormString("imgpath").Split(',');
                imgNames = CY.Utility.Common.RequestUtility.GetFormString("imgName").Split(',');
                string appPath = string.Empty;
                string imgName = string.Empty;
                string imgExtention = string.Empty;
                string dirPath = string.Empty;
                if (imgPaths != null && imgNames != null && imgPaths.Length == imgNames.Length)
                {
                    for (int i = 0; i < imgPaths.Length; i++)
                    {
                        CY.CSTS.Core.Business.AnnexType imgType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType);
                        if (imgType == null)
                        {
                            imgType = new CY.CSTS.Core.Business.AnnexType();
                            imgType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType;
                            imgType.Save();
                        }
                        appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;
                        imgName = CY.Utility.Common.FileUtility.GetFileName(imgNames[i]);
                        imgExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgNames[i]);
                        dirPath = CY.Utility.Common.SiteUtility.CurServer.MapPath(imgPaths[i]);
                        if (File.Exists(dirPath))
                        {
                            CY.CSTS.Core.Business.Annex imgAnnex = new CY.CSTS.Core.Business.Annex();
                            imgAnnex.Name = imgName;
                            imgAnnex.AnnexTypeID = imgType.Id;
                            imgAnnex.ContentID = contentId;
                            imgAnnex.AnnexURI = CY.Utility.Common.AnnexUtility.InstrumentAnneImgDir + imgName + imgExtention;
                            imgAnnex.Save();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
        }
Example #9
0
        protected void SaveImg(System.Guid contentId)
        {
            try
            {
                if (contentId == System.Guid.Empty)
                {
                    return;
                }

                string[] strPaths = Request.Form.GetValues("imgpath");
                string[] strNames = Request.Form.GetValues("imgname");
                if (strPaths == null || strNames == null || strPaths.Length <= 0 || strNames.Length <= 0 || strPaths.Length != strNames.Length)
                {
                    return;
                }

                #region Get AnnexType

                CY.CSTS.Core.Business.AnnexType anneType = CY.CSTS.Core.Business.AnnexType.SelectAnnexTypeByTypeName(CY.Utility.Common.AnnexUtility.ImgAnnexType);

                if (anneType == null)
                {
                    anneType = new CY.CSTS.Core.Business.AnnexType();
                    anneType.TypeName = CY.Utility.Common.AnnexUtility.ImgAnnexType;
                    anneType.Save();
                }

                #endregion

                string fileName = string.Empty;

                string fileExtention = string.Empty;

                CY.CSTS.Core.Business.Annex imgannex = null;

                for (int i = 0; i < strNames.Length; i++)
                {
                    fileName = CY.Utility.Common.FileUtility.GetFileName(strNames[i]);
                    fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(strNames[i]);

                    imgannex = new CY.CSTS.Core.Business.Annex();
                    imgannex.ContentID = contentId;
                    imgannex.AnnexTypeID = anneType.Id;
                    imgannex.Name = fileName;
                    imgannex.AnnexURI = @"/Content/Instrument/Img/" + fileName + fileExtention;
                    imgannex.Save();
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
        }