Просмотр исходного кода

填写与签名 - 文字日期属性面板

chenrongqian@kdanmobile.com 2 лет назад
Родитель
Сommit
65cf271047

+ 14 - 2
PDF Office/CustomControl/CompositeControl/CustomComboControl.xaml.cs

@@ -22,14 +22,20 @@ namespace PDF_Office.CustomControl.CompositeControl
     //默认:字体集合、IsValueContent为false、Value作为集合某项的值
 
 
-    public class ComboDataItem
+    public class ComboDataItem : Prism.Mvvm.BindableBase
     {
         //字符串类型的值
         public string ValueStr { get; private set; }
         //数字类型的值
         public double Value { get; private set; }
+        //public string Content { get; private set; }
         //下拉框显示的内容
-        public string Content { get; private set; }
+        private string _content = "";
+        public string Content
+        {
+            get { return _content; }
+            private set { SetProperty(ref _content, value); }
+        }
         //下拉框显示的内容+单位:限数字值的单位
         public string Unit { get; private set; }
         //数字类型
@@ -45,6 +51,11 @@ namespace PDF_Office.CustomControl.CompositeControl
             ValueStr = valueStr;
         }
 
+        public void SetContent(string content)
+        {
+            Content = content;
+        }
+
     }
     /// <summary>
     /// CustomComboControl.xaml 的交互逻辑
@@ -250,6 +261,7 @@ namespace PDF_Office.CustomControl.CompositeControl
                         {
                             control.Value = selectedItems.Value;
                         }
+                        control.title.Text = selectedItems.Content;
                     }
 
                     if (control.comBox.Items == null || control.comBox.Items.Count == 0)

+ 14 - 2
PDF Office/ViewModels/FillAndSign/FillAndSignContentViewModel.cs

@@ -447,7 +447,8 @@ namespace PDF_Office.ViewModels.FillAndSign
             annotAttribsList[AnnotAttrib.FontStyle] = freetextArgs.FontStyle;
             annotAttribsList[AnnotAttrib.FontWeight] = freetextArgs.FontWeight;
             annotAttribsList[AnnotAttrib.TextAlign] = textAlignment;
-            annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
+            annotAttribsList[AnnotAttrib.NoteText] = freetextArgs.TextContent;
+            annotAttribsList[AnnotAttrib.Text] = freetextArgs.TextContent;
 
             AddToPropertyPanel("FreetextAnnotProperty", "Freetext", selectedArgs, annotAttribsList);
             return freetextArgs;
@@ -499,6 +500,15 @@ namespace PDF_Office.ViewModels.FillAndSign
                 }
             }
 
+            if (toolTag == "Freetext")
+            {
+                propertyPanel.SetIsTextFill(true);
+            }
+            else
+            {
+                propertyPanel.SetIsTextFill(false);
+            }
+
             if (string.IsNullOrEmpty(viewContent) == false)
             {
 
@@ -1052,7 +1062,9 @@ namespace PDF_Office.ViewModels.FillAndSign
             switch (annot.EventType)
             {
 
-
+                case AnnotArgsType.AnnotFreeText:
+                    GetFreetext(e.AnnotItemsList);
+                    break;
 
                 case AnnotArgsType.AnnotFreehand:
                     GetFreehand(e.AnnotItemsList);

+ 143 - 2
PDF Office/ViewModels/PropertyPanel/AnnotPanel/FreetextAnnotPropertyViewModel.cs

@@ -35,6 +35,29 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             set => SetProperty(ref _basicVm, value);
         }
 
+        private bool _isFillFreeText = false;
+        public bool IsFillFreeTextAnnot
+        {
+            get { return _isFillFreeText; }
+            set => SetProperty(ref _isFillFreeText, value);
+        }
+
+        private bool _isCheckedTime = false;
+        public bool IsCheckedTime
+        {
+            get { return _isCheckedTime; }
+            set => SetProperty(ref _isCheckedTime, value);
+        }
+
+        private ComboDataItem _currrentDateFormat = new ComboDataItem("M/d", "format");
+        public ComboDataItem CurrrentDateFormat
+        {
+            get { return _currrentDateFormat; }
+            set => SetProperty(ref _currrentDateFormat, value);
+        }
+
+        public List<ComboDataItem> DateFormatItems { get; private set; }
+
         public AnnotAttribEvent AnnotEvent { get; set; }
         private FreeTextAnnotArgs Annot;
         private AnnotPropertyPanel PropertyPanel;
@@ -59,6 +82,9 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         public DelegateCommand ReDefineFontStyleCommand { get; set; }
         public DelegateCommand RestoreDefaultStyleCommand { get; set; }
 
+        public DelegateCommand DateFormatChangedCommand { get; set; }
+        public DelegateCommand ShowTimeCheckedChnagedCommand { get; set; }
+
         public event EventHandler<object> LoadPropertyHandler;
 
         public FreetextAnnotPropertyViewModel()
@@ -87,15 +113,43 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             //内容对齐
             TextAlignCheckedCommand = new DelegateCommand<object>(TextAlignChecked);
 
+            //填写与签名:日期
+            DateFormatChangedCommand = new DelegateCommand(DateFormatChanged);
+            ShowTimeCheckedChnagedCommand = new DelegateCommand(ShowTimeCheckedChnaged);
             //MVP不上
             LineModeCheckedCommand = new DelegateCommand<object>(LineMode_Checked);
             SelectedOpacityValueCommand = new DelegateCommand<object>(SelectedOpacityValue);
             InitVariable();
         }
 
+      
         private void InitVariable()
         {
-            
+            DateFormatItems = new List<ComboDataItem>();
+            DateFormatItems = TextFont.GetDateFormats();
+            UpdateDateFormatLists();
+
+
+        }
+
+        private void UpdateDateFormatLists()
+        {
+            string strTime = " HH:mm:ss";
+            foreach (var item in DateFormatItems)
+            {
+                if (IsCheckedTime)
+                    strTime = item.ValueStr + " HH:mm:ss";
+                else
+                    strTime = item.ValueStr;
+
+                string stadate = System.DateTime.Now.ToString(strTime);
+                item.SetContent(stadate);
+
+                if (CurrrentDateFormat != null && item.ValueStr == CurrrentDateFormat.ValueStr)
+                    CurrrentDateFormat.SetContent(stadate);
+            }
+
+            CurrrentDateFormat = new ComboDataItem(CurrrentDateFormat.ValueStr, CurrrentDateFormat.Content);
         }
 
      
@@ -318,6 +372,28 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
            // var item = FontStyleList.FirstOrDefault(temp => temp.mTag == CurrentPresetFont.ValueStr);
         }
 
+        private void DateFormatChanged()
+        {
+            if(CurrrentDateFormat != null)
+            {
+                if (IsCheckedTime)
+                    UpdateDateFormatLists();
+
+                PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
+            }
+
+        }
+
+        private void ShowTimeCheckedChnaged()
+        {
+            if (CurrrentDateFormat != null)
+            {
+                UpdateDateFormatLists();
+                PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
+            }
+        }
+
+
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;
@@ -326,6 +402,7 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
         public void OnNavigatedFrom(NavigationContext navigationContext)
         {
             BasicVm.IsMultiSelected = false;
+          //  IsCheckedTime = false;
         }
 
         public void OnNavigatedTo(NavigationContext navigationContext)
@@ -333,11 +410,13 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             navigationContext.Parameters.TryGetValue<AnnotPropertyPanel>(ParameterNames.PropertyPanelContentViewModel, out PropertyPanel);
             if (PropertyPanel != null)
             {
+               
                 AnnotEvent = PropertyPanel.AnnotEvent;
                 Annot = PropertyPanel.annot as FreeTextAnnotArgs;
                 LoadPropertyHandler?.Invoke(this, Annot);
                 BasicVm.AnnotTypeTitle = "文字";
                 BasicVm.IsMultiSelected = PropertyPanel.IsMultiSelected;
+                IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
                 if (BasicVm.IsMultiSelected)
                 {
                     IsAttributeEquals();
@@ -347,6 +426,8 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
                 {
                     GetAnnotProperty();
                 }
+
+                IsFillFreeTextAnnot = PropertyPanel.IsTextFill;
             }
         }
 
@@ -473,7 +554,10 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
             FontVm.GetCurrentFontFamily(Annot.FontFamily.ToString(), Annot.FontFamily.ToString());
             FontVm.GetFontWeights_Style(Annot.FontStyle, Annot.FontWeight);
 
-            string str = "";
+            GetTimeFormat();
+
+
+                string str = "";
             if (Annot.Align == TextAlignment.Left)
                 str = "AlignLeft";
             else if (Annot.Align == TextAlignment.Center)
@@ -489,6 +573,63 @@ namespace PDF_Office.ViewModels.PropertyPanel.AnnotPanel
 
         }
 
+        private void GetTimeFormat()
+        {
+            if (IsFillFreeTextAnnot == false)
+                return;
+
+            if(string.IsNullOrEmpty(Annot.TextContent))
+            {
+                if (CurrrentDateFormat != null)
+                {
+                    if (IsCheckedTime)
+                        UpdateDateFormatLists();
+
+                    PropertyPanel.UpdateAnnotAAttrib(AnnotAttrib.NoteText, CurrrentDateFormat.Content);
+                }
+                return;
+
+            }
+            DateTime dtDate;
+            bool isTime = false;
+            foreach (var item in DateFormatItems)
+            {
+                var strFormat = "";
+                var strArr = Annot.TextContent.Split(' ');
+                if (strArr != null && strArr.Count() == 2)
+                {
+                    strFormat = item.ValueStr + " HH:mm:ss";
+                }
+                else
+                {
+                    strFormat = item.ValueStr;
+                }
+
+                if (DateTime.TryParseExact(Annot.TextContent, strFormat, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AdjustToUniversal, out dtDate))
+                {
+                    if (strArr != null && strArr.Count() == 2)
+                    {
+                        isTime = true;
+                    }
+
+                    foreach (var item2 in DateFormatItems)
+                    {
+                        string stadate = System.DateTime.Now.ToString(strFormat);
+                        item.SetContent(stadate);
+
+                    }
+
+                    CurrrentDateFormat = new ComboDataItem(item.ValueStr, item.Content);
+
+                    break;
+
+                }
+            }
+
+
+            IsCheckedTime = isTime;
+        }
+
 
     }
 }

+ 2 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Layout.cs

@@ -56,6 +56,8 @@ namespace PDF_Office.ViewModels.Tools
                 }
             }
 
+            propertyPanel.SetIsTextFill(false);
+
             propertyPanel.AnnotEvent = AnnotAttribEvent.GetAnnotAttribEvent(annots[0], annots[0].GetAnnotAttrib());
             if (annots[0] is LinkAnnotArgs && annotAttribEvent != null)
             {

+ 7 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Properties.cs

@@ -24,9 +24,16 @@ namespace PDF_Office.ViewModels.Tools
     {
         public AnnotAttribEvent AnnotEvent { get; set; }
         public List<AnnotAttribEvent> AnnotEvents = new List<AnnotAttribEvent>();
+
         public AnnotHandlerEventArgs annot;
         public List<AnnotHandlerEventArgs> annotlists;
 
+        public bool IsTextFill { get; private set; }
+        public void SetIsTextFill(bool isTextFill)
+        {
+            IsTextFill = isTextFill;
+        }
+
         public event EventHandler<Dictionary<AnnotArgsType, object>> DataChanged;
 
         public event EventHandler<Dictionary<AnnotArgsType, object>> AnnotTypeChanged;

+ 27 - 1
PDF Office/Views/PropertyPanel/AnnotPanel/FreetextAnnotProperty.xaml

@@ -20,6 +20,7 @@
                 <ResourceDictionary Source="../../../Styles/CustomBtnStyle.xaml"/>
             </ResourceDictionary.MergedDictionaries>
             <Convert:InvertBoolToVisibleConvert x:Key="InvertBoolToVisibleConvert"/>
+            <Convert:BoolToVisible x:Key="BoolToVisible"/>
             <Convert:CheckToVisibleMutiConvert x:Key="CheckToVisibleMutiConvert"/>
             <Style x:Key="line1Style" TargetType="{x:Type Line}">
                 <Setter Property="Visibility">
@@ -417,7 +418,32 @@
             </Grid>
 
 
-<!--MVP不上-->
+            <StackPanel Visibility="{Binding IsFillFreeTextAnnot,Converter={StaticResource BoolToVisible}}">
+                <TextBlock Margin="0,8,0,8" Text="Date Type" Foreground="{StaticResource color.sys.text.neutral.lv2}" />
+                <CompositeControl:CustomComboControl
+                                x:Name="DateTimeBox"
+                                Width="228"
+                                Height="32"
+                                HorizontalAlignment="Left"
+                                IsValueContent="True"
+                                ItemSource="{Binding DateFormatItems,Mode=OneWay}"
+                                SelectedItems="{Binding CurrrentDateFormat, Mode=TwoWay}">
+                    <i:Interaction.Triggers>
+                        <i:EventTrigger EventName="ValueChanged">
+                            <i:InvokeCommandAction Command="{Binding DateFormatChangedCommand}"/>
+                        </i:EventTrigger>
+                    </i:Interaction.Triggers>
+                </CompositeControl:CustomComboControl>
+
+                <CheckBox x:Name="isShowTime" Margin="0,16,0,0" Content="Show Time" IsChecked="{Binding IsCheckedTime,Mode=TwoWay}"
+                      Command="{Binding ShowTimeCheckedChnagedCommand}"
+                      >
+
+                </CheckBox>
+
+            </StackPanel>
+        
+            <!--MVP不上-->
 
             <TextBlock x:Name="thicknessText" Visibility="Collapsed" FontFamily="Segoe UI Semibold" FontWeight="SemiBold" FontSize="14" LineHeight="20" Margin="12,14,0,0" >Thickness</TextBlock>