Exemplo n.º 1
0
        // TODO: Use IEmployee
        void BindBarcode(EmployeeInfo employee)
        {
            labelBarcodeEmployeeName.Text = employee.FullName();

            // barcode image
            var barcodeWidth = UniversityConfig.Instance.Barcode.DefaultWidth;

            imageBarcode.ImageUrl = UniversityUrlHelper.FullUrl(string.Format(
                                                                    "/imagehandler.ashx?barcode=1&width={0}&height={1}&type=qrcode&encoding=UTF-8&content={2}",
                                                                    barcodeWidth, barcodeWidth,
                                                                    Server.UrlEncode(employee.VCard().ToString()
                                                                                     .Replace("+", "%2b")) // fix for "+" signs in phone numbers
                                                                    ));

            imageBarcode.ToolTip       = LocalizeString("imageBarcode.ToolTip");
            imageBarcode.AlternateText = LocalizeString("imageBarcode.AlternateText");
        }
        // TODO: Use IEmployee
        void BindBarcode(EmployeeInfo employee)
        {
            if (employee.ShowBarcode)
            {
                labelBarcodeEmployeeName.Text = employee.FullName;
                linkBarcode.Attributes.Add("data-target", "#employee-barcode-dialog-" + ModuleId);

                // barcode image
                var barcodeWidth = UniversityConfig.Instance.Barcode.DefaultWidth;
                imageBarcode.ImageUrl = UniversityUrlHelper.FullUrl(string.Format(
                                                                        "/imagehandler.ashx?barcode=1&width={0}&height={1}&type=qrcode&encoding=UTF-8&content={2}",
                                                                        barcodeWidth, barcodeWidth,
                                                                        Server.UrlEncode(employee.VCard.ToString()
                                                                                         .Replace("+", "%2b")) // fix for "+" signs in phone numbers
                                                                        ));

                imageBarcode.ToolTip       = LocalizeString("imageBarcode.ToolTip");
                imageBarcode.AlternateText = LocalizeString("imageBarcode.AlternateText");
            }
            else
            {
                linkBarcode.Visible = false;
            }
        }
        public static void Bind(IEmployee employee, Image imagePhoto, int photoWidth, bool listMode = false)
        {
            var image = default(IFileInfo);

            var photoFileId = GetPhotoFileId(employee, listMode);

            if (photoFileId != null && !Null.IsNull(photoFileId.Value))
            {
                image = FileManager.Instance.GetFile(photoFileId.Value);
            }

            var defaultWidth = listMode
                ? UniversityConfig.Instance.EmployeePhoto.ListDefaultWidth
                : UniversityConfig.Instance.EmployeePhoto.DefaultWidth;

            // TODO: Make PhotoWidth settings nullable
            photoWidth = (photoWidth > 0) ? photoWidth : defaultWidth;

            // if no photo specified (or not found), use fallback image
            var noPhotoUrl = default(string);

            if (image == null)
            {
                image        = new FileInfo();
                image.Width  = defaultWidth;
                image.Height = defaultWidth;
                noPhotoUrl   = UniversityGlobals.ASSETS_PATH + "/images/nophoto.png";
            }

            if (noPhotoUrl == null)
            {
                imagePhoto.ImageUrl = UniversityUrlHelper.FullUrl($"/imagehandler.ashx?fileid={image.FileId}&width={photoWidth}");
            }
            else
            {
                // files inside DesktopModules folder have no fileid
                imagePhoto.ImageUrl = UniversityUrlHelper.FullUrl($"/imagehandler.ashx?file={noPhotoUrl}&width={photoWidth}");
            }

            // apply CSS classes
            var imageWidth  = image.Width;
            var imageHeight = image.Height;

            if (Math.Abs(imageWidth - imageHeight) <= 1)
            {
                // for square and "almost" square images
                imagePhoto.CssClass += " rounded-circle";
            }
            else
            {
                imagePhoto.CssClass += " rounded";
            }

            if (noPhotoUrl != null)
            {
                imagePhoto.CssClass += " u8y-img-employee-nophoto";
            }

            // set alt & title
            var fullName = employee.FullName();

            imagePhoto.AlternateText = fullName;
            imagePhoto.ToolTip       = fullName;
        }
Exemplo n.º 4
0
        public static void Bind(IEmployee employee, Image imagePhoto, int photoWidth, bool square = false)
        {
            IFileInfo image       = null;
            var       imageHeight = 0;
            var       imageWidth  = 0;

            if (!TypeUtils.IsNull(employee.PhotoFileID))
            {
                image = FileManager.Instance.GetFile(employee.PhotoFileID.Value);
                if (image != null && square)
                {
                    // trying to get square image
                    var squareImage = FileManager.Instance.GetFile(
                        FolderManager.Instance.GetFolder(image.FolderId),
                        Path.GetFileNameWithoutExtension(image.FileName)
                        + UniversityConfig.Instance.EmployeePhoto.SquareSuffix
                        + Path.GetExtension(image.FileName));

                    if (squareImage != null)
                    {
                        image = squareImage;
                    }
                }
            }

            if (image != null)
            {
                imageHeight = image.Height;
                imageWidth  = image.Width;

                // do we need to scale image?
                if (!Null.IsNull(photoWidth) && photoWidth != imageWidth)
                {
                    imagePhoto.ImageUrl = UniversityUrlHelper.FullUrl(string.Format(
                                                                          "/imagehandler.ashx?fileid={0}&width={1}", image.FileId, photoWidth));
                }
                else
                {
                    // use original image
                    imagePhoto.ImageUrl = FileManager.Instance.GetUrl(image);
                }
            }
            else
            {
                // if not photo specified, or not found, use fallback image
                imageWidth  = square ? UniversityConfig.Instance.EmployeePhoto.SquareDefaultWidth : UniversityConfig.Instance.EmployeePhoto.DefaultWidth;
                imageHeight = square ? UniversityConfig.Instance.EmployeePhoto.SquareDefaultWidth : UniversityConfig.Instance.EmployeePhoto.DefaultWidth * 4 / 3;

                // TODO: Make fallback image resizable through image handler
                imagePhoto.ImageUrl = string.Format("/DesktopModules/MVC/R7.University/R7.University/images/nophoto_{0}{1}.png",
                                                    CultureInfo.CurrentCulture.TwoLetterISOLanguageName, square ?
                                                    UniversityConfig.Instance.EmployeePhoto.SquareSuffix : "");
            }

            // do we need to scale image dimensions?
            if (!Null.IsNull(photoWidth) && photoWidth != imageWidth)
            {
                imagePhoto.Width  = photoWidth;
                imagePhoto.Height = (int)(imageHeight * (float)photoWidth / imageWidth);
            }
            else
            {
                imagePhoto.Width  = imageWidth;
                imagePhoto.Height = imageHeight;
            }

            // set alt & title for photo
            var fullName = FormatHelper.FullName(employee.FirstName, employee.LastName, employee.OtherName);

            imagePhoto.AlternateText = fullName;
            imagePhoto.ToolTip       = fullName;
        }