Exemplo n.º 1
0
        private void SaveImgs(System.Guid contentId,string path,string name)
        {
            try
            {
                string[] imgNames = null;
                string[] imgPaths = null;
                if (!string.IsNullOrEmpty(CY.Utility.Common.RequestUtility.GetFormString(path)) && !string.IsNullOrEmpty(CY.Utility.Common.RequestUtility.GetFormString(name)))
                {
                    imgPaths = CY.Utility.Common.RequestUtility.GetFormString(path).Split(',');
                    imgNames = CY.Utility.Common.RequestUtility.GetFormString(name).Split(',');
                }
                else
                {
                    return;
                }
                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))
                        {
                            if (path == "imgPath")
                            {
                                subset.Contact = CY.Utility.Common.AnnexUtility.SubAnneImgDir + imgName + imgExtention;
                                SubCenterSetting.UpdateSubCenterSetting(subset);
                            }
                            else
                            {
                                subset.Des = CY.Utility.Common.AnnexUtility.SubAnneImgDir + imgName + imgExtention;
                                SubCenterSetting.UpdateSubCenterSetting(subset);
                            }

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

            }
        }
Exemplo n.º 2
0
        private void SaveImgs(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.ManufacturerAnneImgDir + imgName + imgExtention;
                            imgAnnex.Save();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

            }
        }
Exemplo n.º 3
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;
                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 && !string.IsNullOrEmpty(imgAnnex.AnnexURI))
                {
                    fileName = imgAnnex.Name;
                    fileExtention = CY.Utility.Common.FileUtility.GetFileExtension(imgAnnex.AnnexURI);
                    string fileSmall;
                    if (imgAnnex.AnnexURI.LastIndexOf('.') < 0)
                    {
                        fileSmall = imgAnnex.AnnexURI + strType + fileExtention;
                    }
                    else
                    {
                        fileSmall = imgAnnex.AnnexURI.Substring(0, imgAnnex.AnnexURI.LastIndexOf('.')) + strType + fileExtention;
                    }

                    if (File.Exists(dirPath + imgAnnex.AnnexURI.Replace("/", @"\")))
                    {
                        if (File.Exists(dirPath + fileSmall.Replace("/", @"\")))
                        {
                            reader = new StreamReader(dirPath + fileSmall.Replace("/", @"\"));
                        }
                        else
                        {
                            CY.Utility.Common.PicProcess.MakeThumbnail(dirPath + imgAnnex.AnnexURI.Replace("/", @"\"), dirPath + fileSmall.Replace("/", @"\"), 75, 66, "DB", "");
                            reader = new StreamReader(dirPath + fileSmall.Replace("/", @"\"));
                        }
                    }
                    else
                    {
                        string fileDir = "Content\\Default\\InstrumentDefault.jpg";
                        if (!appPath.EndsWith("\\"))
                        {
                            fileDir = "\\" + fileDir;
                        }
                        if (File.Exists(appPath + fileDir))
                        {
                            reader = new StreamReader(appPath + fileDir);
                        }
                    }
                }
                else
                {
                    string fileDir = "Content\\Default\\InstrumentDefault.jpg";
                    if (!appPath.EndsWith("\\"))
                    {
                        fileDir = "\\" + fileDir;
                    }
                    if (File.Exists(appPath + fileDir))
                    {
                        reader = new StreamReader(appPath + fileDir);
                    }
                }

                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;
        }