using ComPDFKit.PDFAnnotation; using ComPDFKitViewer.PdfViewer; using PDF_Office.Model; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel { class CustomCreateDialogViewModel : BindableBase, IDialogAware { public string Title => "."; public event Action RequestClose; public DelegateCommand CancelCommand { get; set; } public DelegateCommand CreateCommnad { get; set; } public DelegateCommand UpDataDynamicCommnad { get; set; } public DelegateCommand KeyDown { get; set; } private BitmapSource imageSource; public BitmapSource ImageSource { get { return imageSource; } set { SetProperty(ref imageSource, value); } } private string stampText = "Stamp Text"; public string StampText { get { return stampText; } set { SetProperty(ref stampText, value); } } private bool isCheckedDate; public bool IsCheckedDate { get { return isCheckedDate; } set { SetProperty(ref isCheckedDate, value); UpDataStamp(); } } private bool isCheckedTime; public bool IsCheckedTime { get { return isCheckedTime; } set { SetProperty(ref isCheckedTime, value); UpDataStamp(); } } private C_TEXTSTAMP_SHAPE shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT; public C_TEXTSTAMP_SHAPE Shape { get { return shape; } set { shape = value; } } private C_TEXTSTAMP_COLOR color = C_TEXTSTAMP_COLOR.TEXTSTAMP_RED; public C_TEXTSTAMP_COLOR Color { get { return color; } set { color = value; } } public void SetStampStyle(int index) { switch (index) { case 1: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_NONE; break; case 2: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_WHITE; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT; break; case 3: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT; break; case 4: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_RED; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT; break; case 5: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RECT; break; case 6: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_LEFT_TRIANGLE; break; case 7: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_RED; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_LEFT_TRIANGLE; break; case 8: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_BLUE; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_LEFT_TRIANGLE; break; case 9: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RIGHT_TRIANGLE; break; case 10: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_RED; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RIGHT_TRIANGLE; break; case 11: Color = C_TEXTSTAMP_COLOR.TEXTSTAMP_GREEN; Shape = C_TEXTSTAMP_SHAPE.TEXTSTAMP_RIGHT_TRIANGLE; break; default: break; } UpDataStamp(); } public CustomCreateDialogViewModel() { CancelCommand = new DelegateCommand(Cancel); CreateCommnad = new DelegateCommand(Create); UpDataDynamicCommnad = new DelegateCommand(UpDataStamp); KeyDown = new DelegateCommand(PreviewKeyDown); } private void Cancel() { RequestClose.Invoke(new DialogResult(ButtonResult.Cancel)); } private void Create() { } public bool CanCloseDialog() { return true; } public void OnDialogClosed() { return; } private void PreviewKeyDown(object e) { var args = e as KeyEventArgs; if (args == null) { return; } if (args.Key == Key.Enter) { StampText = (args.OriginalSource as TextBox).Text; UpDataStamp(); } } private void UpDataStamp() { string date = ""; string dateType = ""; if (IsCheckedDate) { dateType = "yyyy-MM-dd"; } if (IsCheckedTime) { dateType= dateType+ " HH:mm:ss"; } if (!String.IsNullOrEmpty(dateType)) { date = DateTime.Now.ToString(dateType); } var bytes = CPDFStampAnnotation.GetTempTextStampImage(StampText, date, Shape, Color, out int stampWidth, out int stampHeight, out int width, out int height); if (bytes.Length > 0) { PixelFormat fmt = PixelFormats.Bgra32; BitmapSource bps = BitmapSource.Create(width, height, 96, 96, fmt, null, bytes, (width * fmt.BitsPerPixel + 7) / 8); ImageSource = bps; } else { ImageSource = null; } } public void OnDialogOpened(IDialogParameters parameters) { UpDataStamp(); return; } } }