Guest User

Untitled

a guest
May 23rd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. namespace TagPort.Models
  2. {
  3. public class EPMConnection
  4. {
  5. public string epmServerMachine { get; set; }
  6. public string serverPort { get; set; }
  7. public string serverUser { get; set; }
  8. public string serverPwd { get; set; }
  9. }
  10. }
  11.  
  12. namespace TagPort.ViewModels
  13. {
  14. class ConnectionViewModel : INotifyPropertyChanged
  15. {
  16. public EPMConnection epmConnection;
  17. public ConnectionViewModel()
  18. {
  19. epmConnection = new EPMConnection { epmServerMachine = "Tteste2" };
  20. }
  21.  
  22. public event PropertyChangedEventHandler PropertyChanged;
  23.  
  24. protected void RaisePropertyChanged([CallerMemberName] String propertyName = "")
  25. {
  26. if (PropertyChanged != null)
  27. {
  28. PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  29. }
  30. }
  31.  
  32.  
  33.  
  34. public EPMConnection Connection
  35. {
  36. get { return epmConnection; }
  37. set
  38. {
  39. epmConnection = value;
  40. }
  41. }
  42. public string EpmServerMachine
  43. {
  44. get { return epmConnection.epmServerMachine; }
  45. set
  46. {
  47. if(epmConnection.epmServerMachine != value)
  48. {
  49. epmConnection.epmServerMachine = value;
  50. RaisePropertyChanged();
  51. }
  52. }
  53. }
  54. public string EpmServerPort
  55. {
  56. get { return epmConnection.serverPort; }
  57. set
  58. {
  59. if (epmConnection.serverPort != value)
  60. {
  61. epmConnection.serverPort = value;
  62. RaisePropertyChanged();
  63. }
  64. }
  65.  
  66. }
  67. public string EpmServerUser
  68. {
  69. get { return epmConnection.serverUser; }
  70. set
  71. {
  72. if (epmConnection.serverUser != value)
  73. {
  74. epmConnection.serverUser = value;
  75. RaisePropertyChanged();
  76. }
  77. }
  78.  
  79. }
  80. public string EpmServerPwd
  81. {
  82. get { return epmConnection.serverPwd; }
  83. set
  84. {
  85. if (epmConnection.serverPwd != value)
  86. {
  87. epmConnection.serverPwd = value;
  88. RaisePropertyChanged();
  89. }
  90. }
  91. }
  92. public string ConnectionToString()
  93. {
  94. string p1 = (" EpmServer:"+ EpmServerMachine + "n EpmPort:" + EpmServerPort + " n EpmUser:" + EpmServerUser + " n EpmPwd" + EpmServerPwd + "");
  95. return p1;
  96. }
  97. }
  98. }
  99.  
  100. <UserControl.Resources>
  101. <local:ConnectionViewModel x:Key="ConnectionVM"/>
  102. </UserControl.Resources>
  103.  
  104.  
  105. <Grid DataContext="{StaticResource ConnectionVM}">
  106. <Grid.ColumnDefinitions>
  107. <ColumnDefinition Width="180"></ColumnDefinition>
  108. <ColumnDefinition Width="*"></ColumnDefinition>
  109. </Grid.ColumnDefinitions>
  110. <Grid.RowDefinitions>
  111. <RowDefinition Height="34"></RowDefinition>
  112. <RowDefinition Height="34"></RowDefinition>
  113. <RowDefinition Height="34"></RowDefinition>
  114. <RowDefinition Height="34"></RowDefinition>
  115. <RowDefinition Height="34"></RowDefinition>
  116. </Grid.RowDefinitions>
  117. <Label Content="EPM Sever Machine:" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.Row="0"/>
  118. <Label Content="EPM Server Port:" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.Row="1"/>
  119. <Label Content="EPM Server User:" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.Row="2"/>
  120. <Label Content="EPM Server Password:" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="0" Grid.Row="3"/>
  121.  
  122. <TextBox TextWrapping="Wrap" Text="{Binding EpmServerMachine,UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" Height="23" Margin="0,0,4,0"/>
  123. <TextBox TextWrapping="Wrap" Text="{Binding EpmServerPort,UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" Height="23" Margin="0,0,4,0"/>
  124. <TextBox TextWrapping="Wrap" Text="{Binding EpmServerUser,UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" Height="23" Margin="0,0,4,0"/>
  125. <TextBox TextWrapping="Wrap" Text="{Binding EpmServerPwd,UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="3" VerticalAlignment="Center" Height="23" Margin="0,0,4,0"/>
  126.  
  127.  
  128.  
  129. <Button Content="Test Connection" Grid.Column="1" Grid.Row="4" Width="Auto" HorizontalAlignment="Right" Height="23" VerticalAlignment="Bottom" Margin="0,0,4,0" Click="TestConnection_Click"/>
  130.  
  131. </Grid>
  132.  
  133. public partial class EPMConnectionTab : UserControl
  134. {
  135. ConnectionViewModel _viewModel;
  136. public EPMConnectionTab()
  137. {
  138. InitializeComponent();
  139. _viewModel = new ConnectionViewModel();
  140. this.DataContext = _viewModel;
  141. }
  142.  
  143. private void TestConnection_Click(object sender, RoutedEventArgs e)
  144. {
  145.  
  146. MessageBox.Show(_viewModel.ConnectionToString());
  147. }
  148.  
  149. }
Add Comment
Please, Sign In to add comment