Exemple #1
0
        public string GetPictureUrl(Media picture, int width = 0, int height = 0, bool returnDefaultIfNotFound = false)
        {
            //check if picture is not null
            if (picture == null || picture.Id == 0)
            {
                return(string.Empty);
            }

            if (_mediaSettings.PictureSaveLocation == MediaSaveLocation.Database)
            {
                //todo: implement database storage
            }
            var expectedFile           = FileHelpers.GetPictureFileNameWithSize(picture.LocalPath, width, height);
            var expectedFileSystemPath = ServerHelper.GetLocalPathFromRelativePath(expectedFile);

            if (!File.Exists(expectedFileSystemPath))
            {
                //we need to create the file with required dimensions
                var fileSystemPathForOriginalImage = ServerHelper.GetLocalPathFromRelativePath(picture.LocalPath);

                //image format
                var imageFormat = PictureUtility.GetImageFormatFromContentType(picture.MimeType);
                //save resized image
                _imageProcessor.WriteResizedImage(fileSystemPathForOriginalImage, expectedFileSystemPath, width, height, imageFormat);
            }
            //return the image url
            var imageServeUrl = expectedFile.Replace("~", _generalSettings.ImageServerDomain);

            return(imageServeUrl);
        }
Exemple #2
0
 private void ReadData(Company company)
 {
     txtCompanyCode.Text            = company.CompanyCode;
     txtCompanyName.Text            = company.CompanyName;
     cboTypeOfCompany.SelectedValue = company.TypeId;
     txtAddress.Text         = company.Address;
     txtAccountant.Text      = company.Accountant;
     txtPhoneAccountant.Text = company.AccountantPhone;
     txtSwich.Text           = company.SwiftCode;
     txtTaxCode.Text         = company.Taxcode;
     txtNoBrach.Text         = company.Branch.ToString();
     txtStaft.Text           = company.NumberOfEmployee.IntToString();
     txtNote.Text            = company.Note;
     txtAcountBank.Text      = company.BankName;
     txtNumberBank.Text      = company.BankAccount;
     PictureUtility.BindImage(PictureSgnature, company.Photo);
     PictureUtility.BindImage(PictureLogo, company.PictureLogo);
     if (company.MainDeputy != null)
     {
         txtNameContact.Text = company.MainDeputy.DeputyName;
         txtPhone.Text       = company.MainDeputy.Phone;
         txtEmail.Text       = company.MainDeputy.Email;
         cbSex.SelectedValue = company.MainDeputy.Sex;
     }
     if (company.Class != null)
     {
         cbClassCustormer.SelectedValue = company.Class.CompanyClassId;
     }
 }
        private void gridView2_RowClick(object sender, RowClickEventArgs e)
        {
            gridutility.SetRowColor();
            int currentIndex = gridView2.GetSelectedRows().FirstOrDefault();

            if (selectindex == currentIndex)
            {
                return;
            }
            try
            {
                var imagePath = gridView2.GetRowCellValue(gridView2.FocusedRowHandle, gridView2.Columns["Material.PhotoPath"]);
                if (imagePath != null)
                {
                    PictureUtility.BindImage(ptPhoto, gridView2.GetRowCellValue(gridView2.FocusedRowHandle, gridView2.Columns["Material.PhotoPath"]).ToString());
                    selectindex = currentIndex;
                }
                else
                {
                    label6.Hide();
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RegisterPictureSize(IList <PictureSize> pictureSizes)
        {
            //we won't have media settings available if database is not installed, so let's check for that first
            if (!DatabaseManager.IsDatabaseInstalled())
            {
                return;
            }
            var mediaSettings = mobSocialEngine.ActiveEngine.Resolve <MediaSettings>();

            //register default sizes
            pictureSizes.UpdateOrInsertSize(PictureUtility.ParsePictureSize(mediaSettings.ThumbnailPictureSize, PictureSizeNames.ThumbnailImage));

            pictureSizes.UpdateOrInsertSize(PictureUtility.ParsePictureSize(mediaSettings.SmallProfilePictureSize, PictureSizeNames.SmallProfileImage));

            pictureSizes.UpdateOrInsertSize(PictureUtility.ParsePictureSize(mediaSettings.MediumProfilePictureSize, PictureSizeNames.MediumProfileImage));

            pictureSizes.UpdateOrInsertSize(PictureUtility.ParsePictureSize(mediaSettings.SmallCoverPictureSize, PictureSizeNames.SmallCover));

            pictureSizes.UpdateOrInsertSize(PictureUtility.ParsePictureSize(mediaSettings.MediumCoverPictureSize, PictureSizeNames.MediumCover));

            pictureSizes.UpdateOrInsertSize(PictureSizeNames.OriginalProfileImage, 0, 0);

            pictureSizes.UpdateOrInsertSize(PictureSizeNames.OriginalCover, 0, 0);

            pictureSizes.UpdateOrInsertSize(PictureSizeNames.OriginalImage, 0, 0);
        }
Exemple #5
0
        public void WritePictureBytes(Media picture, MediaSaveLocation pictureSaveLocation)
        {
            //we need to save the file on file system
            if (picture.Binary == null || !picture.Binary.Any())
            {
                throw new mobSocialException("Can't write empty bytes for picture");
            }

            if (pictureSaveLocation == MediaSaveLocation.FileSystem)
            {
                //get the directory path from the relative path
                var directoryPath = ServerHelper.GetLocalPathFromRelativePath(_mediaSettings.PictureSavePath);
                var fileExtension = PathUtility.GetFileExtensionFromContentType(picture.MimeType);

                if (string.IsNullOrEmpty(picture.SystemName))
                {
                    picture.SystemName = $"{Guid.NewGuid().ToString("n")}";
                }

                var proposedFileName = $"{picture.SystemName}{fileExtension}";
                var filePath         = PathUtility.GetFileSavePath(directoryPath, proposedFileName);

                var imageFormat = PictureUtility.GetImageFormatFromContentType(picture.MimeType);
                _imageProcessor.WriteBytesToImage(picture.Binary, filePath, imageFormat);

                //clear bytes
                picture.Binary    = null;
                picture.LocalPath = filePath;

                picture.ThumbnailPath = ServerHelper.GetRelativePathFromLocalPath(filePath);
            }
        }
Exemple #6
0
 private void InitializeForm(Staff staff)
 {
     //txtFullName.Text = staff.StaffName;
     //txtEmail.Text = staff.Email;
     //txtCode.Text = staff.StaffCode;
     //txtUserName.Text = staff.User!=null?staff.User.UserName:string.Empty;
     //txtPhone.Text = staff.Phone;
     //dtpBirthday.DateTime = staff.Birthday != null ? staff.Birthday.Value : DateTime.Today;
     //dtpBeginDate.DateTime = staff.BeginDate!=null? staff.BeginDate.Value:DateTime.Today;
     //txtAddress.Text = staff.Address;
     //cbbDepartment.SelectedValue = m_Staff.DepartmentId;
     //cbbUserGroup.SelectedValue = staff.UserGroup != null ? staff.UserGroup.UserGroupId : 0;
     //cbbPosition.SelectedValue = m_Staff.StaffPosition != null ? staff.StaffPosition.StaffPositionId : 0;
     CoverObjectUtility.SetAutoBindingData(this, staff);
     if (staff.Sex)
     {
         rbtnMale.Checked = true;
     }
     else
     {
         rbtnFemale.Checked = true;
     }
     if (!ValidationUtility.StringIsNull(staff.Avatar))
     {
         PictureUtility.BindImage(ptAvatar, staff.Avatar);
     }
     if (!ValidationUtility.StringIsNull(staff.SignaturePhoto))
     {
         PictureUtility.BindImage(ptSignature, staff.SignaturePhoto);
     }
 }
Exemple #7
0
        public string GetPictureUrl(Media picture, int width = 0, int height = 0, bool returnDefaultIfNotFound = false)
        {
            //check if picture is not null
            if (picture == null || picture.Id == 0)
            {
                return(string.Empty);
            }

            var expectedFile           = picture.LocalPath;
            var expectedFileSystemPath = ServerHelper.GetLocalPathFromRelativePath(expectedFile);

            if (!File.Exists(expectedFileSystemPath))
            {
                //we need to create the file with required dimensions
                var fileSystemPathForOriginalImage = ServerHelper.GetLocalPathFromRelativePath(picture.LocalPath);

                //image format
                var imageFormat = PictureUtility.GetImageFormatFromContentType(picture.MimeType);
                //save resized image
                _imageProcessor.WriteResizedImage(fileSystemPathForOriginalImage, expectedFileSystemPath, width, height, imageFormat);
            }
            var storeUrl = _webHelper.GetStoreLocation();
            //return the image url
            var imageServeUrl = expectedFile.Replace("~", storeUrl);

            return(imageServeUrl);
        }
Exemple #8
0
        public string GetPictureUrl(Media picture, string size, bool returnDefaultIfNotFound = false)
        {
            //parse size
            var parsedSize = PictureUtility.GetSize(size);

            return(GetPictureUrl(picture, parsedSize.Width, parsedSize.Height, returnDefaultIfNotFound));
        }
 private void AddProductToListView(IList<QuotationDetail> lstQuotationDetail)
 {
     ImageList imgList = new ImageList();
     foreach (QuotationDetail detail in lstQuotationDetail)
     {
         Image img = PictureUtility.GetImg(detail.Product.Photo);
         imgList.Images.Add(img);
         //img.Dispose();
     }
     listView1.View = System.Windows.Forms.View.LargeIcon;
     imgList.ImageSize = new Size(100, 100);
     listView1.LargeImageList = imgList;
     for (int i = 0; i < lstQuotationDetail.Count; i++)
     {
         ProductTag tag = new ProductTag();
         tag.ProductId = lstQuotationDetail[i].ProductId;
         tag.ProductCode = lstQuotationDetail[i].Product.ProductCode;
         tag.Photo = lstQuotationDetail[i].Product.PhotoPath;
         tag.Quantity = lstQuotationDetail[i].Quantity;
         //if (listView1.Items.ContainsKey(tag.ProductCode))
         //{
         //    listView1.Items.RemoveByKey(tag.ProductCode);
         //}
         ListViewItem item = new ListViewItem();
         item.ImageIndex = i;
         item.Name = tag.ProductCode;
         item.Text = tag.ProductCode;
         item.Tag = tag;
         listView1.Items.Add(item);
     }
 }
        public IHttpActionResult UploadPicture(int artistPageId, IEnumerable <HttpPostedFileBase> file)
        {
            //first get artist page
            var artistPage = _artistPageService.Get(artistPageId);

            if (!CanEdit(artistPage))
            {
                return(Response(new { Success = false, Message = "Unauthorized" }));
            }

            var files       = file.ToList();
            var newImageUrl = "";

            foreach (var fi in files)
            {
                Stream stream      = null;
                var    fileName    = "";
                var    contentType = "";

                if (file == null)
                {
                    throw new ArgumentException("No file uploaded");
                }

                stream      = fi.InputStream;
                fileName    = Path.GetFileName(fi.FileName);
                contentType = fi.ContentType;

                var fileBinary = new byte[stream.Length];
                stream.Read(fileBinary, 0, fileBinary.Length);

                var fileExtension = Path.GetExtension(fileName);
                if (!string.IsNullOrEmpty(fileExtension))
                {
                    fileExtension = fileExtension.ToLowerInvariant();
                }


                if (string.IsNullOrEmpty(contentType))
                {
                    contentType = PictureUtility.GetContentType(fileExtension);
                }

                var picture = new Media()
                {
                    Binary     = fileBinary,
                    MimeType   = contentType,
                    Name       = fileName,
                    SystemName = Guid.NewGuid().ToString("n")
                };
                _pictureService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation);

                _pictureService.AttachMediaToEntity(artistPage, picture);

                newImageUrl = _pictureService.GetPictureUrl(picture.Id);
            }

            return(Response(new { Success = true, Url = newImageUrl }));
        }
        public IHttpActionResult UploadPicture()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            var files = HttpContext.Current.Request.Files;

            // check if files are on the request.*/
            if (files.Count == 0)
            {
                return(Json(new { Success = false }));
            }

            try
            {
                var newImages = new List <object>();
                for (var index = 0; index < files.Count; index++)
                {
                    //the file
                    var file = files[index];

                    //and it's name
                    var fileName = file.FileName;

                    //stream to read the bytes
                    var stream       = file.InputStream;
                    var pictureBytes = new byte[stream.Length];
                    stream.Read(pictureBytes, 0, pictureBytes.Length);

                    //file extension and it's type
                    var fileExtension = Path.GetExtension(fileName);
                    if (!string.IsNullOrEmpty(fileExtension))
                    {
                        fileExtension = fileExtension.ToLowerInvariant();
                    }

                    var contentType = file.ContentType;

                    if (string.IsNullOrEmpty(contentType))
                    {
                        contentType = PictureUtility.GetContentType(fileExtension);
                    }
                    //save the picture now
                    var picture = _pictureService.InsertPicture(pictureBytes, contentType, null);

                    newImages.Add(new {
                        ImageUrl = _pictureService.GetPictureUrl(picture.Id),
                        ImageId  = picture.Id
                    });
                }

                return(Json(new { Success = true, Images = newImages }));
            }
            catch (Exception e)
            {
                return(Json(new { Success = false }));
            }
        }
Exemple #12
0
 private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (txtNamePart.ReadOnly)
     {
         return;
     }
     PictureUtility.OpenImage(PictureImage);
 }
Exemple #13
0
        void DisplayInformation(TreeNode nodeInformation)
        {
            TreeTagPart treetag = nodeInformation.Tag as TreeTagPart;

            if (treetag == null)
            {
                return;
            }
            if (treetag.NodeTye != TreeTagPart.Types.Part)
            {
                return;
            }
            Part selectPart;

            Model.Sourcing selectSouring;
            txtPricePart.ReadOnly   = true;
            txtNamePart.ReadOnly    = true;
            txtDescription.ReadOnly = true;
            cboSupplier.Enabled     = false;



            using (IUnitOfWork uow = new UnitOfWork())
            {
                selectPart    = uow.PartBaseRepository.Find(treetag.PartIDTag);
                selectSouring = uow.SourcingBaseRepository.FindPartByIDPart(treetag.PartIDTag);
                uow.Commit();
            }
            if (selectPart == null)
            {
                return;
            }
            if (selectSouring == null)
            {
                return;
            }



            txtNamePart.Text          = selectPart.PartName;
            txtPricePart.Text         = (selectPart.Pricespart) > 0 ? selectPart.Pricespart.ToString() : "0";
            txtDescription.Text       = selectPart.Description;
            cboSupplier.SelectedValue = selectSouring.SupplierID;
            currentSelecSupplier      = selectSouring.SupplierID;

            txtNamePart.Focus();
            txtNumberPart.Text      = selectPart.PartNumber;
            txtDescription.ReadOnly = true;
            lbTitle.Text            = "Information detail sourcing";
            PictureUtility.BindImage(PictureImage, selectPart.ImagePath);

            if (selectPart.ImagePath != null)
            {
                currentImagePath = selectPart.ImagePath;
            }
            txtNumberPart.ReadOnly = true;
            treeView1.Select();
        }
Exemple #14
0
        public IHttpActionResult UploadPictures()
        {
            var files = HttpContext.Current.Request.Files;

            if (files.Count == 0)
            {
                VerboseReporter.ReportError("No file uploaded", "upload_pictures");
                return(RespondFailure());
            }
            var newImages = new List <object>();

            for (var index = 0; index < files.Count; index++)
            {
                //the file
                var file = files[index];

                //and it's name
                var fileName = file.FileName;
                //stream to read the bytes
                var stream       = file.InputStream;
                var pictureBytes = new byte[stream.Length];
                stream.Read(pictureBytes, 0, pictureBytes.Length);

                //file extension and it's type
                var fileExtension = Path.GetExtension(fileName);
                if (!string.IsNullOrEmpty(fileExtension))
                {
                    fileExtension = fileExtension.ToLowerInvariant();
                }

                var contentType = file.ContentType;

                if (string.IsNullOrEmpty(contentType))
                {
                    contentType = PictureUtility.GetContentType(fileExtension);
                }

                var picture = new Media()
                {
                    Binary   = pictureBytes,
                    MimeType = contentType,
                    Name     = fileName
                };

                _mediaService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation);
                //save it
                _mediaService.Insert(picture);
                newImages.Add(new {
                    ImageUrl     = _mediaService.GetPictureUrl(picture.Id),
                    ThumbnailUrl = _mediaService.GetPictureUrl(picture.Id, PictureSizeNames.ThumbnailImage),
                    ImageId      = picture.Id,
                    MimeType     = contentType
                });
            }

            return(RespondSuccess(new { Images = newImages }));
        }
Exemple #15
0
        /// <summary>
        /// 判断登陆用户信息(如无则添加)
        /// </summary>
        /// <param name="md"></param>
        /// <returns></returns>
        public mjuserinfo AddUser(mjuserinfo md, GameSession session)
        {
            int           returnid = 0;
            mjuserinfoDAL dal      = new mjuserinfoDAL();
            mjuserinfo    model    = dal.GetModel(md.openid);
            login_logDAL  Ldal     = new login_logDAL();
            login_log     Lmodel   = new login_log();



            if (model == null)
            {
                try
                {
                    returnid   = dal.GetMaxID() + 1;
                    md.id      = returnid;
                    md.addtime = DateTime.Now;
                    string fileName = string.Empty;
                    string imgurl   = PictureUtility.SavePicture(md.headimg, out fileName); //将图片保存至本地返回详细路径和文件名
                    if (!string.IsNullOrEmpty(imgurl))                                      //验证是否保存成功
                    {
                        md.headimg = PutObjectSample.PutObjectFromFile(imgurl, fileName);
                    }
                    dal.Add(md);
                    Lmodel.id          = Ldal.GetMaxID() + 1;
                    Lmodel.login_state = 1;
                    Lmodel.login_time  = DateTime.Now;
                    Lmodel.openid      = md.openid;
                    Ldal.Add(Lmodel);
                }
                catch (Exception ex)
                {
                    session.Logger.Error(ex);
                }



                return(md);
            }
            else
            {
                try
                {
                    Lmodel.id          = Ldal.GetMaxID() + 1;
                    Lmodel.login_state = 1;
                    Lmodel.login_time  = DateTime.Now;
                    Lmodel.openid      = md.openid;
                    Ldal.Add(Lmodel);
                }
                catch (Exception)
                {
                    throw;
                }

                return(model);
            }
        }
Exemple #16
0
        public IHttpActionResult UploadPicture(int BattleId, BattleType BattleType, IEnumerable <HttpPostedFileBase> file)
        {
            //first get battle
            var videoBattle = _videoBattleService.GetById(BattleId);
            var sponsors    = _sponsorService.GetSponsors(_workContext.CurrentCustomer.Id, BattleId, BattleType,
                                                          SponsorshipStatus.Accepted);

            //only the battle owner or the sponsor can upload the picture
            if (!(sponsors.Any() || videoBattle.ChallengerId == _workContext.CurrentCustomer.Id))
            {
                return(Json(new { Success = false, Message = "Unauthorized" }));
            }

            var files     = file.ToList();
            var newImages = new List <object>();

            foreach (var fi in files)
            {
                Stream stream      = null;
                var    fileName    = "";
                var    contentType = "";

                if (file == null)
                {
                    throw new ArgumentException("No file uploaded");
                }

                stream      = fi.InputStream;
                fileName    = Path.GetFileName(fi.FileName);
                contentType = fi.ContentType;

                var fileBinary = new byte[stream.Length];
                stream.Read(fileBinary, 0, fileBinary.Length);

                var fileExtension = Path.GetExtension(fileName);
                if (!string.IsNullOrEmpty(fileExtension))
                {
                    fileExtension = fileExtension.ToLowerInvariant();
                }


                if (string.IsNullOrEmpty(contentType))
                {
                    contentType = PictureUtility.GetContentType(fileExtension);
                }

                var picture = _pictureService.InsertPicture(fileBinary, contentType, null);


                newImages.Add(new {
                    ImageUrl = _pictureService.GetPictureUrl(picture.Id),
                    ImageId  = picture.Id
                });
            }

            return(Json(new { Success = true, Images = newImages }));
        }
Exemple #17
0
        private void bootstrapButton1_Click(object sender, EventArgs e)
        {
            if (isInsert == false && isUpdate == false)
            {
                lblNotify1.SetText("không có thao tác", LabelNotify.EnumStatus.Failed);
                return;
            }

            if (isInsert)
            {
                if (ValidationUtility.FieldNotAllowNull(this) == false)
                {
                    return;
                }
                if (isCreateNew.SeriesPartID < 0)
                {
                    lblNotify1.SetText("thiếu thông tin về series ID", LabelNotify.EnumStatus.Failed);
                    return;
                }


                if (txtPricePart.Text == string.Empty)
                {
                }

                try
                {
                    decimal.Parse(txtPricePart.Text);
                }
                catch (Exception)
                {
                    lblNotify1.SetText("Chưa nhập giá hoặc giá không chính x", LabelNotify.EnumStatus.Failed);
                    txtPricePart.Focus();
                    return;
                }


                if (cboSupplier.SelectedValue == null)
                {
                    lblNotify1.SetText("Chưa nhập thông tin nhà cung cấp", LabelNotify.EnumStatus.Failed);
                }

                if (PictureImage.Tag != null)
                {
                    isCreateNew.ImagePath = PictureUtility.SaveImg(PictureImage.Tag.ToString());
                }



                SaveSourcing(isCreateNew);
            }
            else if (isUpdate)
            {
                Update();
            }
        }
Exemple #18
0
        public IHttpActionResult UploadPictures()
        {
            var files = HttpContext.Current.Request.Files;

            if (files.Count == 0)
            {
                return(Response(new { Success = false, Message = "No file uploaded" }));
            }

            var newImages = new List <object>();

            for (var index = 0; index < files.Count; index++)
            {
                //the file
                var file = files[index];

                //and it's name
                var fileName = file.FileName;
                //stream to read the bytes
                var stream       = file.InputStream;
                var pictureBytes = new byte[stream.Length];
                stream.Read(pictureBytes, 0, pictureBytes.Length);

                //file extension and it's type
                var fileExtension = Path.GetExtension(fileName);
                if (!string.IsNullOrEmpty(fileExtension))
                {
                    fileExtension = fileExtension.ToLowerInvariant();
                }

                var contentType = file.ContentType;

                if (string.IsNullOrEmpty(contentType))
                {
                    contentType = PictureUtility.GetContentType(fileExtension);
                }

                var picture = new Media()
                {
                    Binary   = pictureBytes,
                    MimeType = contentType,
                    Name     = fileName
                };

                _pictureService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation);

                newImages.Add(new {
                    ImageUrl      = _pictureService.GetPictureUrl(picture.Id),
                    SmallImageUrl = _pictureService.GetPictureUrl(picture.Id),
                    ImageId       = picture.Id,
                    MimeType      = contentType
                });
            }

            return(Json(new { Success = true, Images = newImages }));
        }
Exemple #19
0
        private void itemView_Click(object sender, EventArgs e)
        {
            string fullpath = PictureUtility.getImgLocation(ImgList[selectIndex]);

            if (string.IsNullOrWhiteSpace(fullpath))
            {
                return;
            }
            System.Diagnostics.Process.Start(fullpath);
        }
        Song SaveRemoteSongToDB(string songJson)
        {
            if (string.IsNullOrEmpty(songJson))
            {
                return(null);
            }

            var song = (JObject)JsonConvert.DeserializeObject(songJson);

            var songPage = new Song()
            {
                PageOwnerId      = _workContext.CurrentCustomer.IsAdmin() ? _workContext.CurrentCustomer.Id : 0,
                Description      = song["Description"].ToString(),
                Name             = song["Name"].ToString(),
                RemoteEntityId   = song["RemoteEntityId"].ToString(),
                RemoteSourceName = song["RemoteSourceName"].ToString(),
                PreviewUrl       = song["PreviewUrl"].ToString(),
                TrackId          = song["TrackId"].ToString(),
                RemoteArtistId   = song["ArtistId"].ToString(),
                Published        = true
            };

            _songService.Insert(songPage);

            //we can now download the image from the server and store it on our own server
            //use the json we retrieved earlier

            if (!string.IsNullOrEmpty(song["ImageUrl"].ToString()))
            {
                var imageUrl   = song["ImageUrl"].ToString();
                var imageBytes = HttpHelper.ExecuteGET(imageUrl);
                if (imageBytes != null)
                {
                    var fileExtension = Path.GetExtension(imageUrl);
                    if (!String.IsNullOrEmpty(fileExtension))
                    {
                        fileExtension = fileExtension.ToLowerInvariant();
                    }

                    var contentType = PictureUtility.GetContentType(fileExtension);

                    var picture     = _pictureService.InsertPicture(imageBytes, contentType, songPage.GetSeName(_workContext.WorkingLanguage.Id, true, false));
                    var songPicture = new SongPicture()
                    {
                        EntityId     = songPage.Id,
                        DateCreated  = DateTime.Now,
                        DateUpdated  = DateTime.Now,
                        DisplayOrder = 1,
                        PictureId    = picture.Id
                    };
                    _songService.InsertPicture(songPicture);
                }
            }
            return(songPage);
        }
Exemple #21
0
 private void btnViewDimension_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(txtDimension.FilePath))
     {
         string fullpath = PictureUtility.getImgLocation(txtDimension.FileName);
         if (string.IsNullOrWhiteSpace(fullpath))
         {
             return;
         }
         System.Diagnostics.Process.Start(fullpath);
     }
 }
Exemple #22
0
        ArtistPage SaveRemoteArtistToDB(string artistJson)
        {
            if (string.IsNullOrEmpty(artistJson))
            {
                return(null);
            }

            var        artist     = (JObject)JsonConvert.DeserializeObject(artistJson);
            ArtistPage artistPage = new ArtistPage()
            {
                PageOwnerId      = _workContext.CurrentCustomer.IsAdmin() ? _workContext.CurrentCustomer.Id : 0,
                Biography        = artist["Description"].ToString(),
                Name             = artist["Name"].ToString(),
                Gender           = artist["Gender"].ToString(),
                HomeTown         = artist["HomeTown"].ToString(),
                RemoteEntityId   = artist["RemoteEntityId"].ToString(),
                RemoteSourceName = artist["RemoteSourceName"].ToString(),
                ShortDescription = "",
            };

            _artistPageService.Insert(artistPage);

            //we can now download the image from the server and store it on our own server
            //use the json we retrieved earlier

            if (!string.IsNullOrEmpty(artist["ImageUrl"].ToString()))
            {
                var imageUrl   = artist["ImageUrl"].ToString();
                var imageBytes = HttpHelper.ExecuteGET(imageUrl);
                if (imageBytes != null)
                {
                    var fileExtension = Path.GetExtension(imageUrl);
                    if (!String.IsNullOrEmpty(fileExtension))
                    {
                        fileExtension = fileExtension.ToLowerInvariant();
                    }

                    var contentType = PictureUtility.GetContentType(fileExtension);

                    var picture       = _pictureService.InsertPicture(imageBytes, contentType, artistPage.GetSeName(_workContext.WorkingLanguage.Id, true, false));
                    var artistPicture = new ArtistPagePicture()
                    {
                        EntityId     = artistPage.Id,
                        DateCreated  = DateTime.Now,
                        DateUpdated  = DateTime.Now,
                        DisplayOrder = 1,
                        PictureId    = picture.Id
                    };
                    _artistPageService.InsertPicture(artistPicture);
                }
            }
            return(artistPage);
        }
        ArtistPage SaveRemoteArtistToDB(string artistJson)
        {
            if (string.IsNullOrEmpty(artistJson))
            {
                return(null);
            }

            var artist     = (JObject)JsonConvert.DeserializeObject(artistJson);
            var artistPage = new ArtistPage()
            {
                PageOwnerId      = ApplicationContext.Current.CurrentUser.IsAdministrator() ? ApplicationContext.Current.CurrentUser.Id : 0,
                Biography        = artist["Description"].ToString(),
                Name             = artist["Name"].ToString(),
                Gender           = artist["Gender"].ToString(),
                HomeTown         = artist["HomeTown"].ToString(),
                RemoteEntityId   = artist["RemoteEntityId"].ToString(),
                RemoteSourceName = artist["RemoteSourceName"].ToString(),
                ShortDescription = "",
            };

            _artistPageService.Insert(artistPage);

            //we can now download the image from the server and store it on our own server
            //use the json we retrieved earlier

            if (!string.IsNullOrEmpty(artist["ImageUrl"].ToString()))
            {
                var imageUrl   = artist["ImageUrl"].ToString();
                var imageBytes = HttpHelper.ExecuteGet(imageUrl);
                if (imageBytes != null)
                {
                    var fileExtension = Path.GetExtension(imageUrl);
                    if (!String.IsNullOrEmpty(fileExtension))
                    {
                        fileExtension = fileExtension.ToLowerInvariant();
                    }

                    var contentType = PictureUtility.GetContentType(fileExtension);
                    var picture     = new Media()
                    {
                        Binary   = imageBytes,
                        MimeType = contentType,
                        Name     = artistPage.Name
                    };
                    _pictureService.WritePictureBytes(picture, _mediaSettings.PictureSaveLocation);

                    _pictureService.AttachMediaToEntity(artistPage, picture);
                }
            }
            return(artistPage);
        }
Exemple #24
0
        public Media GetMediaInstance(IFormFile mediaFile, int userId)
        {
            byte[] fileBytes;
            using (var stream = new MemoryStream())
            {
                mediaFile.CopyTo(stream);
                fileBytes = stream.ToArray();
            }

            var saveDirectory = ServerHelper.MapPath(ApplicationConfig.MediaDirectory, true);
            var fileName      = SafeWriteBytesToFile(mediaFile.FileName, saveDirectory, fileBytes);

            //file extension and it's type
            var fileExtension = _localFileProvider.GetExtension(mediaFile.FileName);

            if (!string.IsNullOrEmpty(fileExtension))
            {
                fileExtension = fileExtension.ToLowerInvariant();
            }

            var contentType = mediaFile.ContentType;

            //an image?
            if (string.IsNullOrEmpty(contentType))
            {
                contentType = PictureUtility.GetContentType(fileExtension);
            }
            //no? a video?
            if (string.IsNullOrEmpty(contentType))
            {
                contentType = VideoUtility.GetContentType(fileExtension);
            }
            //no? let it be default one then
            if (string.IsNullOrEmpty(contentType))
            {
                contentType = "application/octet-stream";
            }
            var media = new Media()
            {
                MimeType        = contentType,
                UserId          = userId,
                Name            = mediaFile.FileName,
                CreatedOn       = DateTime.UtcNow,
                SystemName      = fileName,
                AlternativeText = mediaFile.FileName
            };

            media.ThumbnailPath = GetPictureUrl(media, 150, 150, true);
            media.LocalPath     = GetPictureUrl(media, 0, 0, true);
            return(media);
        }
Exemple #25
0
        private void itemAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.Filter = PictureUtility.filter;
            op.ShowDialog();
            if (ValidationUtility.StringIsNull(op.FileName))
            {
                return;
            }
            string name = PictureUtility.SaveImg(op.FileName);

            Add(name);
        }
Exemple #26
0
 public void Show(string[] imglst)
 {
     ImgList = imglst;
     if (ImgList == null)
     {
         return;
     }
     PictureUtility.BindImage(ptbMain, ImgList[0]);
     PictureUtility.BindImage(ptb0, ImgList[0]);
     PictureUtility.BindImage(ptb1, ImgList[1]);
     PictureUtility.BindImage(ptb2, ImgList[2]);
     PictureUtility.BindImage(ptb3, ImgList[3]);
     PictureUtility.BindImage(ptb4, ImgList[4]);
 }
Exemple #27
0
 private void ShowSelect(int index, PictureBox smallPictureBox)
 {
     if (ImgList == null)
     {
         return;
     }
     if (index < 0 || index > 4)
     {
         return;
     }
     PictureUtility.BindImage(ptbMain, ImgList[index]);
     //ptb0.BorderStyle = ptb1.BorderStyle = ptb2.BorderStyle = ptb3.BorderStyle = ptb4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     //smallPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
 }
Exemple #28
0
 private void SaveProduct()
 {
     if (!string.IsNullOrWhiteSpace(pictureBox2.PictureOriginPath))
     {
         PictureUtility.SaveImg(pictureBox2.PictureOriginPath);
     }
     if (!string.IsNullOrWhiteSpace(txtInstallGuide.FilePath))
     {
         FileUtility.SaveToServer(txtInstallGuide.FileName, txtInstallGuide.FilePath);
     }
     if (!string.IsNullOrWhiteSpace(txtDatasheet.Text))
     {
         FileUtility.SaveToServer(txtDatasheet.FileName, txtDatasheet.FilePath);
     }
     if (!string.IsNullOrWhiteSpace(txtCard3D.FilePath))
     {
         FileUtility.SaveToServer(txtCard3D.FileName, txtCard3D.FilePath);
     }
     if (!string.IsNullOrWhiteSpace(txtDimension.FilePath))
     {
         PictureUtility.SaveImg(txtDimension.FilePath);
     }
     using (IUnitOfWork uow = new UnitOfWork())
     {
         if (m_Product.ProductId == Guid.Empty)
         {
             uow.ProductRepository.Add(m_Product);
             gridUtility.AddNewRow <Product>(m_Product);
         }
         else
         {
             uow.ProductRepository.Update(m_Product);
             gridUtility.UpdateRow <Product>(m_Product);
         }
         if (displayMultiplePicture1.ImgList != null)
         {
             for (int i = 0; i < displayMultiplePicture1.ImgList.Length; i++)
             {
                 if (!string.IsNullOrWhiteSpace(displayMultiplePicture1.ImgList[i]))
                 {
                     ProductPicture picture = new ProductPicture();
                     picture.ProductId = m_Product.ProductId;
                     picture.Picture   = displayMultiplePicture1.ImgList[i];
                     uow.ProductPictureRepository.Add(picture);
                 }
             }
         }
         uow.Commit();
     }
 }
Exemple #29
0
        private void frmEditCustomer_Load(object sender, EventArgs e)
        {
            using (IUnitOfWork uow = new UnitOfWork())
            {
                _objEditCompany = uow.CompanyRepository.Find(_objEditCompany.CompanyId);
                uow.Commit();
            }
            cbSex.SelectedIndex = 0;

            txtCompanyCode.Text            = _objEditCompany.CompanyCode;
            txtCompanyName.Text            = _objEditCompany.CompanyName;
            txtTaxCode.Text                = _objEditCompany.Taxcode;
            txtAddree.Text                 = _objEditCompany.Address;
            txtSwich.Text                  = _objEditCompany.SwiftCode;
            txtNoBrach.Text                = (_objEditCompany.Branch != 0) ? _objEditCompany.Branch.ToString() : string.Empty;
            txtStaft.Text                  = (_objEditCompany.NumberOfEmployee != null) ? _objEditCompany.Branch.ToString() : string.Empty;
            txtWebsite.Text                = _objEditCompany.Website;
            txtNote.Text                   = _objEditCompany.Note;
            txtTargertValue.Text           = (_objEditCompany.TagetValue != 0) ? _objEditCompany.TagetValue.ToString() : string.Empty;
            cbClassCustormer.SelectedValue = _objEditCompany.ClassId;
            PictureUtility.BindImage(PictureSgnature, _objEditCompany.Photo);
            PictureUtility.BindImage(PictureLogo, _objEditCompany.PictureLogo);
            txtAccount.Text = _objEditCompany.Accountant;
            txtAccount.Text = _objEditCompany.AccountantPhone;
            using (IUnitOfWork uow = new UnitOfWork())
            {
                _objMain = uow.DeputyRepository.FindMainDeputy(_objEditCompany.CompanyId);
            }
            Users  user    = UtilityFunction.GetUser(_objMain);
            string account = user != null ? user.UserName : "";

            using (IUnitOfWork uow = new UnitOfWork())
            {
                userEdit = uow.UsersRepository.IsExist(account);
            }
            if (_objMain == null)
            {
                return;
            }
            txtNameContact.Text = _objMain.DeputyName;
            txtEmail.Text       = _objMain.Email;
            txtPhone.Text       = _objMain.Phone;
            cbSex.SelectedIndex = _objMain.Sex ? 0 : 1;
            if (userEdit == null)
            {
                return;
            }
            txtAccount.Text = userEdit.UserName;
        }
Exemple #30
0
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            TreeTagPart treetag = treeView1.SelectedNode.Tag as TreeTagPart;
            Part        selectPart;

            Model.Sourcing selectSouring;
            using (IUnitOfWork uow = new UnitOfWork())
            {
                selectPart    = uow.PartBaseRepository.Find(treetag.PartIDTag);
                selectSouring = uow.SourcingBaseRepository.FindPartByIDPart(treetag.PartIDTag);
                uow.Commit();
            }
            if (selectPart == null)
            {
                return;
            }
            if (selectSouring == null)
            {
                return;
            }

            txtNumberPart.Text       = selectPart.PartNumber;
            txtNamePart.Text         = selectPart.PartName;
            txtPricePart.Text        = (selectPart.Pricespart) > 0 ? selectPart.Pricespart.ToString() : "0";
            txtDescription.Text      = selectPart.Description;
            cboSupplier.SelectedItem = selectPart.SeriesPartID;
            lbTitle.Text             = "update sourcing";
            isUpdatePart             = selectPart;
            isSourcing = selectSouring;
            isInsert   = false;
            isUpdate   = true;

            objBackUp = new PartBackUp();

            objBackUp.PartName    = txtNamePart.Text;
            objBackUp.Description = txtDescription.Text;
            objBackUp.PartName    = txtNumberPart.Text;
            objBackUp.Pricespart  = txtPricePart.Text != string.Empty ? decimal.Parse(txtPricePart.Text) : 0;
            objBackUp.ImagePath   = currentImagePath;
            PictureUtility.BindImage(PictureImage, selectPart.ImagePath);
            txtNumberPart.ReadOnly  = true;
            txtPricePart.ReadOnly   = false;
            txtNamePart.ReadOnly    = false;
            txtDescription.ReadOnly = false;
            cboSupplier.Enabled     = true;
            mainUpdate = treetag;
            txtDescription.ReadOnly = false;
        }