Jelajahi Sumber

Проверка на вводимые данные в поля

Barsik Kato 2 tahun lalu
induk
melakukan
27d1aad0f4

+ 1 - 1
Session1/Windows/ChangePriority.xaml

@@ -8,7 +8,7 @@
         Title="Изменение приоритета" Height="181.968" Width="229.509">
     <Grid>
         <StackPanel>
-            <TextBox x:Name="priorityBox" Height="20" Width="180" Margin="0, 20"></TextBox>
+            <TextBox x:Name="priorityBox" Height="20" Width="180" Margin="0, 20" PreviewTextInput="priorityBox_PreviewTextInput"></TextBox>
             <Button x:Name="Save" Margin="10" Width="80" Click="Save_Click">Изменить</Button>
             <Button x:Name="Cancel" Width="80" Click="Cancel_Click">Отмена</Button>
         </StackPanel>

+ 7 - 0
Session1/Windows/ChangePriority.xaml.cs

@@ -49,5 +49,12 @@ namespace Session1
                 MessageBox.Show("Не удалось записать данные в базу");
             }
         }
+
+        private void priorityBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
+        {
+            char input = e.Text[0];
+            if (!Char.IsDigit(input))
+                e.Handled = true;
+        }
     }
 }

+ 3 - 3
Session1/Windows/EditAgent.xaml

@@ -28,16 +28,16 @@
                     <ComboBox x:Name="agentType" Width="150"></ComboBox>
                 </GroupBox>
                 <GroupBox Header="Приоритет">
-                    <TextBox x:Name="agentPriority" Width="150"></TextBox>
+                    <TextBox x:Name="agentPriority" Width="150" PreviewTextInput="PreviewTextInput"></TextBox>
                 </GroupBox>
                 <GroupBox Header="Адрес">
                     <TextBox x:Name="agentAddress" Width="150"></TextBox>
                 </GroupBox>
                 <GroupBox Header="ИНН">
-                    <TextBox x:Name="agentINN" Width="150"></TextBox>
+                    <TextBox x:Name="agentINN" Width="150" PreviewTextInput="PreviewTextInput"></TextBox>
                 </GroupBox>
                 <GroupBox Header="КПП">
-                    <TextBox x:Name="agentKPP" Width="150"></TextBox>
+                    <TextBox x:Name="agentKPP" Width="150" PreviewTextInput="PreviewTextInput"></TextBox>
                 </GroupBox>
                 <GroupBox Header="Директор">
                     <TextBox x:Name="agentDirector" Width="150"></TextBox>

+ 7 - 0
Session1/Windows/EditAgent.xaml.cs

@@ -109,5 +109,12 @@ namespace Session1
         {
             agentImg.Source = new BitmapImage(new Uri(imgPath.Text, UriKind.Relative));
         }
+
+        private void PreviewTextInput(object sender, TextCompositionEventArgs e)
+        {
+            char input = e.Text[0];
+            if (!Char.IsDigit(input))
+                e.Handled = true;
+        }
     }
 }