Fig. 22.17
Using the HugeInteger Web service. (Part 1 of 5.)
|
|
|
4 using System.Collections.Generic; |
5 using System.ComponentModel; |
|
|
|
9 using System.Windows.Forms; |
10 using System.Web.Services.Protocols; |
|
12 namespace UsingHugeIntegerWebService |
|
14 public partial class UsingHugeIntegerServiceForm : Form |
|
16 public UsingHugeIntegerServiceForm() |
|
18 InitializeComponent(); |
|
|
|
22 private localhost.HugeInteger remoteInteger; |
|
24 private char[] zeros = { '0' }; |
|
|
27 private void UsingHugeIntegerServiceForm_Load( object sender, |
|
|
|
31 remoteInteger = new localhost.HugeInteger(); |
|
|
|
35 private void addButton_Click( object sender, EventArgs e ) |
|
|
|
39 if ( firstTextBox.Text.Length > 100 || |
40 secondTextBox.Text.Length > 100 || |
41 ( firstTextBox.Text.Length == 100 && |
42 secondTextBox.Text.Length == 100) ) |
|
44 MessageBox.Show( "HugeIntegers must not be more " + |
45 "than 100 digits\r\nBoth integers cannot be " + |
46 "of length 100: this causes an overflow", "Error", |
47 MessageBoxButtons.OK, MessageBoxIcon.Information ); |
|
|
|
|
52 resultLabel.Text = remoteInteger.Add( |
53 firstTextBox.Text, secondTextBox.Text ).TrimStart( zeros ); |
|
|
|
57 private void subtractButton_Click( object sender, EventArgs e ) |
|
|
60 if ( SizeCheck( firstTextBox, secondTextBox ) ) |
|
|
|
|
|
66 string result = remoteInteger.Subtract( |
67 firstTextBox.Text, secondTextBox.Text ).TrimStart( zeros ); |
|
|
70 resultLabel.Text = "0"; |
|
72 resultLabel.Text = result; |
|
|
|
|
|
78 catch ( SoapException exception ) |
|
|
81 "First argument was smaller than the second" ); |
|
|
|
|
|
87 private void largerButton_Click( object sender, EventArgs e ) |
|
|
90 if ( SizeCheck( firstTextBox, secondTextBox ) ) |
|
|
|
|
95 if ( remoteInteger.Bigger( firstTextBox.Text, |
96 secondTextBox.Text ) ) |
97 resultLabel.Text = firstTextBox.Text.TrimStart( zeros ) + |
|
99 secondTextBox.Text.TrimStart( zeros ); |
|
101 resultLabel.Text = firstTextBox.Text.TrimStart( zeros ) + |
102 " is not larger than " + |
103 secondTextBox.Text.TrimStart( zeros ); |
|
|
|
|
108 private void smallerButton_Click( object sender, EventArgs e ) |
|
|
111 if ( SizeCheck( firstTextBox, secondTextBox ) ) |
|
|
|
|
116 if ( remoteInteger.Smaller( firstTextBox.Text, |
117 secondTextBox.Text ) ) |
118 resultLabel.Text = firstTextBox.Text.TrimStart( zeros ) + |
119 " is smaller than " + |
120 secondTextBox.Text.TrimStart( zeros ); |
|
122 resultLabel.Text = firstTextBox.Text.TrimStart( zeros ) + |
123 " is not smaller than " + |
124 secondTextBox.Text.TrimStart( zeros ); |
|
|
|
128 private void equalButton_Click( object sender, EventArgs e ) |
|
|
131 if ( SizeCheck( firstTextBox, secondTextBox ) ) |
|
|
|
135 if ( remoteInteger.EqualTo( firstTextBox.Text, |
136 secondTextBox.Text ) ) |
137 resultLabel.Text = firstTextBox.Text.TrimStart( zeros ) + |
138 " is equal to " + secondTextBox.Text.TrimStart( zeros ); |
|
140 resultLabel.Text = firstTextBox.Text.TrimStart( zeros ) + |
141 " is not equal to " + |
142 secondTextBox.Text.TrimStart( zeros ); |
|
|
|
146 private bool SizeCheck( TextBox first, TextBox second ) |
|
|
149 if ( ( first.Text.Length > 100 ) || |
150 ( second.Text.Length > 100 ) ) |
|
152 MessageBox.Show( "HugeIntegers must be less than 100 digits" , |
153 "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); |
|
|
|
|
|
|
|
|
|
|
|
|
|