Ejemplo n.º 1
0
 private void AddRemovePhotos(EmCostumePhoto item)
 {
     if (RemovePhotos == null)
     {
         RemovePhotos = new List <EmCostumePhoto>();
     }
     RemovePhotos.Add(item);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加展示图片使用缩率图
        /// </summary>
        /// <param name="flowLayoutPanel"></param>
        /// <param name="emCostumePhoto"></param>
        /// <param name="img"></param>
        private void InsertImage(TitleImageControlWidth flowLayoutPanel, EmCostumePhoto emCostumePhoto, Image img)
        {
            Image thumbnailImage    = img?.GetThumbnailImage(100, 100, null, new IntPtr());
            TitleImageOfCostume pic = new TitleImageOfCostume()
            {
                Image = thumbnailImage,
                Tag   = emCostumePhoto
            };

            pic.Disposed += ColorPic_Disposed;
            flowLayoutPanel.AddTitleImage(pic);
        }
Ejemplo n.º 3
0
 private void TitleImageMoveDown(TitleImageOfCostume sender, EventArgs e)
 {
     if (sender != null && sender.Tag != null &&
         sender.Tag is EmCostumePhoto)
     {
         EmCostumePhoto moved = sender.Tag as EmCostumePhoto;
         int            index = CostumePhotos.IndexOf(moved);
         if (index < CostumePhotos.Count - 1)
         {
             CostumePhotos.Remove(moved);
             CostumePhotos.Insert(index + 1, moved);
         }
     }
 }
Ejemplo n.º 4
0
        private void RemoveDisposedCostumePhoto()
        {
            if (RemovePhotos != null)
            {
                for (int i = 0; i < RemovePhotos.Count; i++)
                {
                    EmCostumePhoto photo = RemovePhotos[i];

                    if (!String.IsNullOrEmpty(photo.LinkAddress))
                    {
                        //删除原来的文件
                        GlobalCache.ServerProxy.DeletePhotoToCos(photo.PhotoName);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void AutoInsertTitleImage()
        {
            try
            {
                byte[] photo = null;

                if (GlobalUtil.EngineUnconnectioned(this))
                {
                    return;
                }

                string strTime = DateTime.Now.ToString();

                Image        img    = null;
                MemoryStream stream = new MemoryStream();
                photo = stream.ToArray();
                img   = JGNet.Core.ImageHelper.GetNewSizeImage(global::JGNet.Manage.Properties.Resources._800, 800);

                stream = new MemoryStream();
                img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                photo = stream.ToArray();

                Image          thumbnailImage = img.GetThumbnailImage(100, 100, null, new IntPtr());
                EmCostumePhoto emCostumePhoto = null;
                String         newFileName    = JGNet.Core.ImageHelper.GetNewFileName(this.skinTextBox_ID.Text, strTime);
                String         savePath       = GlobalUtil.EmallDir + newFileName;
                Core.ImageHelper.Compress(img, savePath, 50);
                // imtPath = savePath;
                emCostumePhoto = new EmCostumePhoto()
                {
                    Image     = img,
                    SavePath  = savePath,
                    Bytes     = photo,
                    PhotoName = newFileName
                };

                AddPhoto(emCostumePhoto);
                InsertImage(this.titleImageControlWidth1, emCostumePhoto, thumbnailImage);
            }
            catch (Exception ex) { GlobalUtil.ShowError(ex); }
            finally
            {
                GlobalUtil.UnLockPage(this);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 添加展示图片使用缩率图
        /// </summary>
        /// <param name="flowLayoutPanel"></param>
        /// <param name="emCostumePhoto"></param>
        /// <param name="img"></param>
        private void InsertImage(FlowLayoutPanel flowLayoutPanel, EmCostumePhoto emCostumePhoto, Image img)
        {
            Image thumbnailImage = img?.GetThumbnailImage(100, 100, null, new IntPtr());

            //if (flowLayoutPanel == flowLayoutPanel2)
            //{
            //    //颜色的增加标题
            //    TitleImage colorPic = new TitleImage()
            //    {
            //        Title = emCostumePhoto.ColorName,
            //        Image = thumbnailImage,//ShowDeleteBtn  = true
            //        Tag = emCostumePhoto
            //    };
            //    colorPic.Disposed += ColorPic_Disposed; ;
            //    flowLayoutPanel.Controls.Add(colorPic);
            //}
            //else
            //{
            InsertImage(titleImageControlWidth1, emCostumePhoto, img);
            //}
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 添加图片实体类
 /// </summary>
 /// <param name="photo"></param>
 private void AddPhoto(EmCostumePhoto photo)
 {
     if (CostumePhotos == null)
     {
         CostumePhotos = new List <EmCostumePhoto>();
     }
     if (CostumePhotos.Count < 10)
     {
         //判断添加方式,有颜色的放后面,以此解决排序上的更改的问题
         if (String.IsNullOrEmpty(photo.ColorName))
         {
             //将商品详情方最后
             int index = this.CostumePhotos.FindLastIndex(t => String.IsNullOrEmpty(t.ColorName));
             this.CostumePhotos.Insert(index + 1, photo);
         }
         else
         {
             this.CostumePhotos.Add(photo);
         }
         photo.Image.Tag = photo;
     }
 }
Ejemplo n.º 8
0
        private void ImportExcel(String importPath)
        {
            try
            {
                List <ImportPfInfosPara> items          = new List <ImportPfInfosPara>();
                List <ImportPfInfosPara> incorrectItems = new List <ImportPfInfosPara>();
                DataTable dt = NPOIHelper.FormatToDatatable(importPath, 0);


                if (dt.Rows.Count == 0)
                {
                    //没有任何记录
                    ShowMessage("没有可以导入的信息!");
                    CompleteEdit();
                    return;
                }
                InitProgress(dt.Rows.Count);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    UpdateProgress("加载数据:");
                    if (progressStop)
                    {
                        break;
                    }

                    DataRow           row  = dt.Rows[i];
                    ImportPfInfosPara item = new ImportPfInfosPara();
                    try
                    {
                        item.Index        = i + 1;
                        item.CostumeID    = CommonGlobalUtil.ConvertToString(row[0]);
                        item.BarCodeValue = CommonGlobalUtil.ConvertToString(row[1]);
                        item.Name         = CommonGlobalUtil.ConvertToString(row[2]);
                        item.Colors       = CommonGlobalUtil.ConvertToString(row[3]).Replace(",", ",");
                        item.BigClass     = CommonGlobalUtil.ConvertToString(row[4]);
                        item.Price        = Convert.ToDecimal(row[5]);
                        item.PhotoName    = CommonGlobalUtil.ConvertToString(row[6]);
                        item.IsNew        = CommonGlobalUtil.ConvertToString(row[7]) == "是";
                        item.IsHot        = CommonGlobalUtil.ConvertToString(row[8]) == "是";
                    }
                    catch (Exception ex)
                    {
                    }

                    if (!(String.IsNullOrEmpty(item.CostumeID) || String.IsNullOrEmpty(item.Name)))
                    {
                        item.CostumeID = CommonGlobalCache.GetCorrectCostumeID(item.CostumeID);
                        items.Add(item);
                    }
                    else
                    {
                        incorrectItems.Add(item);
                    }
                }
                if (incorrectItems.Count > 0)
                {
                    String str = string.Empty;
                    str = str.Substring(0, str.LastIndexOf(","));
                    ShowError("以下行数中,款号/名称为空,请重新检查!\r\n" + str);
                    return;
                }
                if (items == null || items.Count == 0)
                {
                    ShowMessage("没有数据可以导入,请检查会员信息!");
                    return;
                }

                String failImgs     = String.Empty;
                String tooLargeImgs = String.Empty;
                InitProgress(items.Count);
                foreach (var item in items)
                {
                    if (progressStop)
                    {
                        break;
                    }
                    UpdateProgress("检查图片:");
                    //if (!String.IsNullOrEmpty(item.PhotoName))
                    //{
                    //找图片并上传
                    try
                    {
                        String imagePath = Path.GetDirectoryName(path) + "//" + item.PhotoName;
                        if (!File.Exists(imagePath))
                        {
                            failImgs += "第" + item.Index + "行 款号:" + item.CostumeID;
                            failImgs += "\r\n";
                        }
                        else
                        {
                            Image        img    = JGNet.Core.ImageHelper.FromFileStream(imagePath);
                            MemoryStream stream = new MemoryStream();
                            byte[]       photo  = stream.ToArray();
                            img    = JGNet.Core.ImageHelper.GetNewSizeImage(img, 800);
                            stream = new MemoryStream();
                            img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                            photo = stream.ToArray();
                            if (photo.Length > 2097152)
                            {
                                tooLargeImgs += "第" + item.Index + "行 款号:" + item.CostumeID;
                                tooLargeImgs += "\r\n";
                                //return;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        FailedProgress(ex);
                    }
                    // }
                }

                if (!String.IsNullOrEmpty(failImgs))
                {
                    FailedProgress(new Exception("以下图片不存在:" + "\r\n" + failImgs));

                    return;
                }
                else if (!String.IsNullOrEmpty(tooLargeImgs))
                {
                    FailedProgress(new Exception("以下图片太大:" + "\r\n" + tooLargeImgs));
                    return;
                }

                InteractResult result = GlobalCache.ServerProxy.ImportPfInfos(items);
                switch (result.ExeResult)
                {
                case ExeResult.Success:
                    break;

                case ExeResult.Error:
                    // ShowMessage(result.Msg);
                    FailedProgress(new Exception(result.Msg));
                    return;

                default:
                    break;
                }
                try
                {
                    InitProgress(items.Count);
                    foreach (var item in items)
                    {
                        if (progressStop)
                        {
                            break;
                        }

                        UpdateProgress("图片上传:");
                        //if (!String.IsNullOrEmpty(item.PhotoName))
                        //{
                        //找图片并上传
                        String[] colors = item.Colors.Split(',');

                        String       imagePath   = Path.GetDirectoryName(path) + "//" + item.PhotoName;
                        String       newFileName = JGNet.Core.ImageHelper.GetNewFileName(item.CostumeID, item.PhotoName);
                        Image        img         = JGNet.Core.ImageHelper.FromFileStream(imagePath);
                        MemoryStream stream      = new MemoryStream();
                        byte[]       photo       = stream.ToArray();
                        img    = JGNet.Core.ImageHelper.GetNewSizeImage(img, 800);
                        stream = new MemoryStream();
                        img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                        photo = stream.ToArray();
                        EmCostumePhoto emPhoto = new EmCostumePhoto()
                        {
                            Image     = img,
                            SavePath  = imagePath,
                            IsMain    = true,
                            CostumeID = item.CostumeID,
                            //ColorName = ValidateUtil.CheckEmptyValue(this.skinComboBox_Color.SelectedValue),
                            Bytes     = photo,
                            PhotoName = newFileName
                        };
                        PhotoData data = new PhotoData()
                        {
                            Datas          = emPhoto.Bytes,
                            EmCostumePhoto = emPhoto,
                            Name           = item.PhotoName
                        };

                        WriteLog("UploadPhotoToCos:" + item.CostumeID);
                        GlobalCache.ServerProxy.UploadPhotoToCos(data);
                        //  Thread.Sleep(1000);
                    }
                    ShowMessage("导入成功!");
                }
                catch (Exception ex)
                {
                    FailedProgress(ex);
                }

                CompleteEdit();
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
            finally
            {
                UnLockPage();
                EnablePanel();
            }
        }
Ejemplo n.º 9
0
        private List <EmCostumePhoto> ExcelToImage(string sourcePath, string savepath)
        {
            List <EmCostumePhoto> listPhotos = new List <EmCostumePhoto>();

            try
            {
                using (FileStream fsReader = File.OpenRead(path))
                {
                    HSSFWorkbook wk       = new HSSFWorkbook(fsReader);
                    IList        pictures = wk.GetAllPictures();
                    int          i        = 0;
                    foreach (HSSFPictureData pic in pictures)
                    {
                        EmCostumePhoto cutPhoto = new EmCostumePhoto();



                        //if (pic.Data.Length == 19504) //跳过不需要保存的图片,其中pic.data有图片长度
                        //    continue;
                        string ext   = pic.SuggestFileExtension();//获取扩展名
                        string path  = string.Empty;
                        byte[] photo = null;
                        Image  img   = null;
                        if (ext.Equals("icon") || ext.Equals("jpeg") || ext.Equals("bmp") || ext.Equals("gif") || ext.Equals("png"))
                        {
                            img = Image.FromStream(new MemoryStream(pic.Data)); //从pic.Data数据流创建图片

                            path = Path.Combine(savepath, string.Format("pic{0}." + ext, i++));
                            img.Save(path);//保存
                            photo = pic.Data;

                            //   ShowMessage(pic.Data.Length.ToString());
                        }
                        img = JGNet.Core.ImageHelper.GetNewSizeImage(img, 800);



                        MemoryStream stream = new MemoryStream();
                        img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                        photo = stream.ToArray();

                        Image          thumbnailImage = img.GetThumbnailImage(64, 64, null, new IntPtr());
                        EmCostumePhoto emCostumePhoto = null;
                        String         newFileName    = JGNet.Core.ImageHelper.GetNewFileName(Path.GetFileName(path));
                        String         savePath       = GlobalUtil.EmallDir + newFileName;
                        Core.ImageHelper.Compress(img, savePath, 50);

                        path = savePath;

                        emCostumePhoto = new EmCostumePhoto()
                        {
                            Image    = img,
                            SavePath = path,
                            Bytes    = photo,
                            // CostumeID = this.skinTextBox_ID.Text,
                            PhotoName = newFileName
                        };
                        emCostumePhoto.Image = img;


                        //  cutPhoto.Photo = photo;
                        listPhotos.Add(emCostumePhoto);;
                    }
                }
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(listPhotos);
        }
Ejemplo n.º 10
0
        private void UploadCostumePhoto()
        {
            try
            {
                if (CostumePhotos != null)
                {
                    bool isMainFlag = false;
                    for (int i = 0; i < CostumePhotos.Count; i++)
                    {
                        EmCostumePhoto photo = CostumePhotos[i];
                        photo.DisplayIndex = i;
                        photo.CostumeID    = this.skinTextBox_ID.Text;
                        if (i == 0)
                        {
                            if (photo.ColorName == "")
                            {
                                photo.IsMain = true;
                                isMainFlag   = true;
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            if (isMainFlag == false)
                            {
                                if (photo.ColorName == "")
                                {
                                    photo.IsMain = true;
                                    isMainFlag   = true;
                                }
                            }
                        }

                        // GlobalCache.ServerProxy.InsertEmCostumePhoto(photo);
                        if (String.IsNullOrEmpty(photo.LinkAddress))
                        {
                            //文件重复?提示?缩略图每次都变????
                            if (!String.IsNullOrEmpty(photo.SavePath))
                            {
                                //这里还是要给新图片名称,下面取回来对应过去。才有LINKADDRESS

                                PhotoData para = new PhotoData()
                                {
                                    Datas          = photo.Bytes,
                                    EmCostumePhoto = photo,
                                    Name           = photo.PhotoName,
                                };
                                EmCostumePhoto EmPhoto = CommonGlobalUtil.UploadPhotoToCos(para, photo.CostumeID);
                                para.EmCostumePhoto = EmPhoto;
                                if (photo.IsMain)
                                {
                                    firstImgUrl = EmPhoto.LinkAddress;
                                }
                                GlobalCache.ServerProxy.InsertEmCostumePhoto(EmPhoto);
                                // GlobalCache.ServerProxy.UploadPhotoToCos(para);
                            }
                        }

                        this.BeginInvoke(new CJBasic.CbGeneric <int>(ShowProgress), i);
                    }
                }
            }
            catch (Exception ex)
            {
                GlobalUtil.WriteLog(ex);
            }
            finally
            {
                SetProgressVisible(false);
            }
        }
Ejemplo n.º 11
0
        private void Upload_Click(object sender, EventArgs e)
        {
            try
            {
                Control ctrl  = sender as Control;
                byte[]  photo = null;
                if (CostumePhotos != null && CostumePhotos.Count >= 10)
                {
                    GlobalMessageBox.Show("商品图片,最多上传10张!");
                    return;
                }
                string[] paths = CJBasic.Helpers.FileHelper.GetFilesToOpen("请选择要上传的图片");

                if (paths != null)
                {
                    bool flagHasOtherFile = false;
                    foreach (var checkimg in paths)
                    {
                        if (!IsImage(checkimg))
                        {
                            flagHasOtherFile = true;
                            break;
                        }
                    }
                    if (flagHasOtherFile)
                    {
                        GlobalMessageBox.Show("上传的文件中包含非图片,请确认后再上传!");
                        return;
                    }
                    if (CostumePhotos != null && CostumePhotos.Count + paths.Length > 10)
                    {
                        GlobalMessageBox.Show("商品图片,最多上传10张!");
                        return;
                    }
                    //if (CostumePhotos.Count + paths.Length > 9)
                    //{
                    //    titleImageControlWidth1.isNoDisplay();
                    //}
                    if (paths != null)
                    {
                        foreach (var vPath in paths)
                        {
                            String path = vPath;
                            if (String.IsNullOrEmpty(path))
                            {
                                photo = null;
                                return;
                            }

                            if (GlobalUtil.EngineUnconnectioned(this))
                            {
                                return;
                            }
                            Image        img    = JGNet.Core.ImageHelper.FromFileStream(path);
                            MemoryStream stream = new MemoryStream();
                            img.Save(stream, img.RawFormat);
                            photo = stream.ToArray();
                            if (photo.Length > 2097152)
                            {
                                GlobalMessageBox.Show("图片太大,请重新上传!");
                                return;
                            }


                            img = JGNet.Core.ImageHelper.GetNewSizeImage(img, 800);

                            stream = new MemoryStream();
                            img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                            photo = stream.ToArray();

                            Image          thumbnailImage = img.GetThumbnailImage(100, 100, null, new IntPtr());
                            EmCostumePhoto emCostumePhoto = null;
                            String         newFileName    = JGNet.Core.ImageHelper.GetNewFileName(this.skinTextBox_ID.Text, Path.GetFileName(path));
                            String         savePath       = GlobalUtil.EmallDir + newFileName;
                            Core.ImageHelper.Compress(img, savePath, 50);

                            path = savePath;

                            emCostumePhoto = new EmCostumePhoto()
                            {
                                Image     = img,
                                SavePath  = path,
                                Bytes     = photo,
                                CostumeID = this.skinTextBox_ID.Text,
                                PhotoName = newFileName
                            };
                            emCostumePhoto.Image = img;
                            if (CostumePhotos == null || CostumePhotos.Count <= 9)
                            {
                                AddPhoto(emCostumePhoto);
                                if (CostumePhotos != null && CostumePhotos.Count > 9)
                                {
                                    //  ctrl.Visible = false;
                                }
                                if (sender is FlowLayoutPanel)
                                {
                                    InsertImage(sender as FlowLayoutPanel, emCostumePhoto, thumbnailImage);
                                }
                                else
                                {
                                    InsertImage(ctrl.Parent as FlowLayoutPanel, emCostumePhoto, thumbnailImage);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex) { GlobalUtil.ShowError(ex); }
            finally
            {
                GlobalUtil.UnLockPage(this);
            }
        }