Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
4.3 KiB

  1. using System;
  2. using System.Data;
  3. using System.Collections;
  4. using System.Diagnostics;
  5. using System.Data.SqlClient;
  6. using System.Xml.Serialization;
  7. using UDDI;
  8. namespace UDDI.API.Business
  9. {
  10. public class Phone
  11. {
  12. [XmlAttribute("useType")]
  13. public string UseType;
  14. [XmlText]
  15. public string Value;
  16. public Phone()
  17. {
  18. }
  19. public Phone( string phone, string useType )
  20. {
  21. Value = phone;
  22. UseType = useType;
  23. }
  24. internal void Validate()
  25. {
  26. Utility.ValidateLength( ref UseType, "useType", UDDI.Constants.Lengths.UseType );
  27. Utility.ValidateLength( ref Value, "phone", UDDI.Constants.Lengths.Phone );
  28. }
  29. public void Save( long contactID )
  30. {
  31. //
  32. // Create a command object to invoke the stored procedure
  33. //
  34. SqlCommand cmd = new SqlCommand( "net_contact_phone_save", ConnectionManager.GetConnection() );
  35. cmd.Transaction = ConnectionManager.GetTransaction();
  36. cmd.CommandType = CommandType.StoredProcedure;
  37. //
  38. // Input parameters
  39. //
  40. cmd.Parameters.Add( new SqlParameter( "@contactID", SqlDbType.BigInt ) ).Direction = ParameterDirection.Input;
  41. cmd.Parameters.Add( new SqlParameter( "@phone", SqlDbType.NVarChar, UDDI.Constants.Lengths.Phone ) ).Direction = ParameterDirection.Input;
  42. cmd.Parameters.Add( new SqlParameter( "@useType", SqlDbType.NVarChar, UDDI.Constants.Lengths.UseType ) ).Direction = ParameterDirection.Input;
  43. //
  44. // Set parameter values
  45. //
  46. SqlParameterAccessor parmacc = new SqlParameterAccessor( cmd.Parameters );
  47. parmacc.SetLong( "@contactID", contactID );
  48. parmacc.SetString( "@phone", Value );
  49. parmacc.SetString( "@useType", UseType );
  50. cmd.ExecuteNonQuery();
  51. }
  52. }
  53. public class PhoneCollection : CollectionBase
  54. {
  55. internal void Validate()
  56. {
  57. foreach( Phone phone in this )
  58. {
  59. phone.Validate();
  60. }
  61. }
  62. public void Save( long contactID )
  63. {
  64. //
  65. // Walk collection and call save on individual contact instances
  66. //
  67. foreach( Phone phone in this )
  68. phone.Save( contactID );
  69. }
  70. public void Get( long contactID )
  71. {
  72. //
  73. // Create a command object to invoke the stored procedure net_get_contacts
  74. //
  75. SqlStoredProcedureAccessor cmd = new SqlStoredProcedureAccessor( "net_contact_phones_get" );
  76. //
  77. // Add parameters and set values
  78. //
  79. cmd.Parameters.Add( "@contactID", SqlDbType.BigInt, ParameterDirection.Input );
  80. cmd.Parameters.SetLong( "@contactID", contactID );
  81. //
  82. // Run the stored procedure
  83. //
  84. SqlDataReaderAccessor reader = cmd.ExecuteReader();
  85. try
  86. {
  87. Read( reader );
  88. #if never
  89. //
  90. // Phones for this contact will be contained in the resultset
  91. //
  92. while( rdr.Read() )
  93. {
  94. //
  95. // construct a new contact from the data in this row, fully populate contact and add to collection
  96. //
  97. this.Add( dracc.GetString( PhoneIndex ), dracc.GetString( UseTypeIndex ) );
  98. }
  99. #endif
  100. }
  101. finally
  102. {
  103. reader.Close();
  104. }
  105. }
  106. public void Read( SqlDataReaderAccessor reader )
  107. {
  108. const int UseTypeIndex = 0;
  109. const int PhoneIndex = 1;
  110. //
  111. // Phones for this contact will be contained in the resultset
  112. //
  113. while( reader.Read() )
  114. {
  115. //
  116. // construct a new contact from the data in this row, fully populate contact and add to collection
  117. //
  118. this.Add( reader.GetString( PhoneIndex ), reader.GetString( UseTypeIndex ) );
  119. }
  120. }
  121. public Phone this[int index]
  122. {
  123. get { return ( Phone )List[ index]; }
  124. set { List[ index ] = value; }
  125. }
  126. public int Add( Phone phoneObject )
  127. {
  128. return List.Add( phoneObject );
  129. }
  130. public int Add( string phone )
  131. {
  132. return( Add( phone, null ) );
  133. }
  134. public int Add( string phone, string useType )
  135. {
  136. return List.Add( new Phone( phone, useType ) );
  137. }
  138. public void Insert( int index, Phone value )
  139. {
  140. List.Insert( index, value );
  141. }
  142. public int IndexOf( Phone value )
  143. {
  144. return List.IndexOf( value );
  145. }
  146. public bool Contains( Phone value )
  147. {
  148. return List.Contains( value );
  149. }
  150. public void Remove( Phone value )
  151. {
  152. List.Remove( value );
  153. }
  154. public void CopyTo( Phone[] array, int index )
  155. {
  156. List.CopyTo( array, index );
  157. }
  158. }
  159. }