public Tuple <ImageUploadStatus, string> UploadImg()
        {
            if (!IsValid())
            {
                return(new Tuple <ImageUploadStatus, string>(UploadStatus, _statusMsg));
            }


            string newName = GetUploadFileNewName();
            string dirPath = $"{WebRootPath}/{UploadPath}/{DateTime.Now:yyyyMMdd}";

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            string savePath = $"{WebRootPath}/{UploadPath}/{DateTime.Now:yyyyMMdd}/{newName}";

            try
            {
                _uploadFile.SaveAs(savePath);
                UploadStatus = ImageUploadStatus.Success;
                _statusMsg   = $"{UploadPath}/{DateTime.Now:yyyyMMdd}/{newName}";;
            }
            catch (Exception e)
            {
                UploadStatus = ImageUploadStatus.Failed;
                _statusMsg   = "保存时错误";
            }
            return(new Tuple <ImageUploadStatus, string>(UploadStatus, _statusMsg));
        }
        private void browseSrcSmallLogoBtn_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog imgofDialog = new OpenFileDialog();

            imgofDialog.Filter      = "Image Files|*.jpg;*.bmp;*.png";
            imgofDialog.FilterIndex = 1;

            if (imgofDialog.ShowDialog() == true)
            {
                string filePath = imgofDialog.FileName;
                srcSmallLogoTxtBox.Text = filePath.Length >= 30 ? filePath.Shorten() : filePath;

                alSmallLogoImg.Source = new BitmapImage(new Uri(filePath));
                smallLogoPath         = filePath;

                removeSmallLogoBtn.Visibility = Visibility.Visible;
                switch (smallLogoStatus)
                {
                case ImageUploadStatus.Remain:
                    smallLogoStatus = ImageUploadStatus.New;
                    break;

                case ImageUploadStatus.New:
                    smallLogoStatus = ImageUploadStatus.Remain;
                    break;

                case ImageUploadStatus.Remove:
                    smallLogoStatus = ImageUploadStatus.New;
                    break;
                }
            }
        }
        private void removeSmallLogoBtn_Click(object sender, RoutedEventArgs e)
        {
            removeSmallLogoBtn.Visibility = Visibility.Hidden;
            alSmallLogoImg.Source         = new BitmapImage(new Uri(@"..\NoImg.jpg", UriKind.RelativeOrAbsolute));
            srcSmallLogoTxtBox.Text       = string.Empty;
            switch (smallLogoStatus)
            {
            case ImageUploadStatus.Remain:
                smallLogoStatus = ImageUploadStatus.Remove;
                break;

            case ImageUploadStatus.New:
                smallLogoStatus = ImageUploadStatus.Remain;
                break;
            }
        }
        private bool IsValid()
        {
            if (_uploadFile == null)
            {
                UploadStatus = ImageUploadStatus.NoFile;
                _statusMsg   = "没有可上传的文件";
                return(false);
            }

            UploadStatus = ImageUploadStatus.NoMatchTypes;
            _statusMsg   = "图片类型不匹配,至支持gif,jpg,jpeg,png,bmp格式图片";
            string fileType = _uploadFile.ContentType;

            foreach (string type in FileTypes.Split(','))
            {
                if (fileType.Contains(type))
                {
                    UploadStatus = ImageUploadStatus.WaittingUpload;
                    break;
                }
            }
            if (UploadStatus == ImageUploadStatus.NoMatchTypes)
            {
                return(false);
            }


            if (_uploadFile.ContentLength > SizeLimit)
            {
                UploadStatus = ImageUploadStatus.SizeLimitError;
                _statusMsg   = "图片过大,图片大小应小于1M";
                return(false);
            }

            UploadStatus = ImageUploadStatus.WaittingUpload;
            _statusMsg   = "";
            return(true);
        }