frmClient.cs
上传用户:hkhxjs
上传日期:2008-11-25
资源大小:155k
文件大小:26k
源码类别:

Internet/网络编程

开发平台:

C#

  1. namespace Client // Copyright 2001 Dreamtech Software India Inc.
  2. { // All rights reserved
  3.     using System; // Provides the basic functionality of .NET
  4. using System.Drawing; // Provides the Drawing features, Used for cursors
  5. using System.Collections; // Provides the different type of class collections
  6. using System.ComponentModel;// Provides the facility of using components
  7. using System.Windows.Forms; // Provides the darwing of buttons, listviews etc
  8. using System.Net; // Provides the net related functionality 
  9. using System.Text; // Provides the text manipulation functions
  10. using System.IO; // Provides I/O features
  11. using WorkingWithXML; // Custom Class
  12. /// <summary>
  13. /// This structure is used for book keeping purpose
  14. /// The currently running listener list will be requsted
  15. /// by the server and server sends that list
  16. /// Each record in this structure represent the data for the single
  17. /// running listener
  18. /// </summary>
  19. public struct __CONNECTEDCOMPUTERS
  20. {
  21. /// <summary>
  22. /// Declares the string used to store the name of the listener
  23. /// This name is in human redable format
  24. /// </summary>
  25. public string sComputername;
  26. /// <summary>
  27. /// sIPAddress variable is used to store the IP address of 
  28. /// the listener
  29. /// </summary>
  30. public string sIPAddress;
  31. /// <summary>
  32. /// This will be 0 in starting and consequently filled
  33. /// by every search operation
  34. /// </summary>
  35. public int iFilesFound;
  36. }
  37. /// <summary>
  38.     ///    Summary description for frmClient class.
  39.     /// </summary>
  40.     public class frmClient : System.Windows.Forms.Form
  41.     {
  42. private System.ComponentModel.IContainer components;
  43. private System.Windows.Forms.Button btnViewFiles;
  44. private System.Windows.Forms.Button btnSearch;
  45. private System.Windows.Forms.ToolTip ToolTipText;
  46. private System.Windows.Forms.Button btnQuit;
  47. private System.Windows.Forms.Button btnRefresh;
  48. private System.Windows.Forms.Button btnOpen;
  49. /// <summary>
  50. /// The below declared variables are the user defined variables
  51. /// used within this class
  52. /// </summary>
  53. /// <summary>
  54. /// Stores the total number of listeners found 
  55. /// </summary>
  56. private int iConnectedComputers;
  57. /// <summary>
  58. /// Stores the number of search results found for 
  59. /// the matching criteria
  60. /// </summary>
  61. private int iSearchResult;
  62. /// <summary>
  63. /// Declares a xmlParser variable of type XMLParser (User defined class)
  64. /// </summary>
  65. private XMLParser   xmlParser;
  66. /// <summary>
  67. /// Declares a xmlServerComm variable of type ServerCommunication 
  68. /// (User defined class)
  69. /// </summary>
  70. private ServerCommunication xmlServerComm;
  71. /// <summary>
  72. /// Declares an object xmlStruct of type XMLSTRUCT (User defined class)
  73. /// </summary>
  74. private XMLSTRUCT xmlStruct;
  75. /// <summary>
  76. /// Declares an array of ConnectedComputers of type 
  77. /// __CONNECTEDCOMPUTERS structures
  78. /// </summary>
  79. private __CONNECTEDCOMPUTERS[] ConnectedComputers;
  80. private System.Windows.Forms.ListView lvComputers;
  81. private System.Windows.Forms.ColumnHeader clhComputername;
  82. private System.Windows.Forms.ColumnHeader clhIPAddress;
  83. private System.Windows.Forms.ColumnHeader clhObjects;
  84. private System.Windows.Forms.Label lblCopyright;
  85. /// <summary>
  86. /// declares sSubItems variable as an array of string
  87. /// </summary>
  88. private System.Windows.Forms.ListViewItem lvItems;
  89. /// <summary>
  90. /// This is the default constructor of the class
  91. /// </summary>
  92. public frmClient()
  93.         {
  94.             //
  95.             // Required for Windows Form Designer support
  96.             //
  97.             // Auto generated function by the IDE
  98. InitializeComponent();
  99. // Puts the Computer.ico as the form icon
  100. this.Icon = new System.Drawing.Icon(Application.StartupPath + "\Computer.ico");
  101. // Creates a new instance of XMLParser class
  102. xmlParser = new WorkingWithXML.XMLParser();
  103. // Creates a new instance of XMLSTRUCT structure
  104. xmlStruct = new WorkingWithXML.XMLSTRUCT();
  105. // Creates a new instance for ServerCommunication class
  106. xmlServerComm = new WorkingWithXML.ServerCommunication();
  107. // Assigns the global value for USERLISTXML
  108. xmlParser.USERLISTXML = Application.StartupPath + "\userlist.xml";
  109. // Assigns the global value for SERVERSEARCHXML
  110. xmlParser.SERVERSEARCHRESULTXML = Application.StartupPath + "\search.xml";
  111.   try
  112. {
  113. // Fills the List view with the values
  114. // these values are the response from the server
  115. if( 0 ==  PopulateList() )
  116. // Displays a message if no computer is connected to the network
  117. throw new Exception("No computer is connected to the network. The list will be empty"); 
  118. }
  119. // Hanldes every exceptions that is thrown 
  120. catch( Exception err ) { MessageBox.Show(err.Message,"Warning",MessageBoxButtons.OK, MessageBoxIcon.Warning); }
  121.         }
  122.         /// <summary>
  123.         ///    Clean up any resources being used.
  124.         ///    This is auto generated by the IDE
  125.         /// </summary>
  126.         public override void Dispose()
  127.         {
  128.             base.Dispose();
  129. components.Dispose();
  130.         }
  131.         /// <summary>
  132.         ///    Required method for Designer support - do not modify
  133.         ///    the contents of this method with the code editor.
  134.         ///     this code is generated automatically by the IDE
  135.         /// </summary>
  136.         private void InitializeComponent()
  137. {
  138. this.components = new System.ComponentModel.Container();
  139. this.ToolTipText = new System.Windows.Forms.ToolTip(this.components);
  140. this.btnSearch = new System.Windows.Forms.Button();
  141. this.btnQuit = new System.Windows.Forms.Button();
  142. this.btnViewFiles = new System.Windows.Forms.Button();
  143. this.btnRefresh = new System.Windows.Forms.Button();
  144. this.btnOpen = new System.Windows.Forms.Button();
  145. this.lvComputers = new System.Windows.Forms.ListView();
  146. this.clhComputername = new System.Windows.Forms.ColumnHeader();
  147. this.clhIPAddress = new System.Windows.Forms.ColumnHeader();
  148. this.clhObjects = new System.Windows.Forms.ColumnHeader();
  149. this.lblCopyright = new System.Windows.Forms.Label();
  150. this.SuspendLayout();
  151. // 
  152. // btnSearch
  153. // 
  154. this.btnSearch.BackColor = System.Drawing.Color.Chocolate;
  155. this.btnSearch.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  156. this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  157. this.btnSearch.ForeColor = System.Drawing.Color.White;
  158. this.btnSearch.Location = new System.Drawing.Point(137, 1);
  159. this.btnSearch.Name = "btnSearch";
  160. this.btnSearch.Size = new System.Drawing.Size(67, 35);
  161. this.btnSearch.TabIndex = 2;
  162. this.btnSearch.Text = "&Search";
  163. this.ToolTipText.SetToolTip(this.btnSearch, "Search on computers for filenames");
  164. this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
  165. // 
  166. // btnQuit
  167. // 
  168. this.btnQuit.BackColor = System.Drawing.Color.Chocolate;
  169. this.btnQuit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  170. this.btnQuit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  171. this.btnQuit.ForeColor = System.Drawing.Color.White;
  172. this.btnQuit.Location = new System.Drawing.Point(270, 1);
  173. this.btnQuit.Name = "btnQuit";
  174. this.btnQuit.Size = new System.Drawing.Size(67, 35);
  175. this.btnQuit.TabIndex = 3;
  176. this.btnQuit.Text = "&Quit";
  177. this.ToolTipText.SetToolTip(this.btnQuit, "Quit this application");
  178. this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click);
  179. // 
  180. // btnViewFiles
  181. // 
  182. this.btnViewFiles.BackColor = System.Drawing.Color.Chocolate;
  183. this.btnViewFiles.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  184. this.btnViewFiles.Enabled = false;
  185. this.btnViewFiles.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  186. this.btnViewFiles.ForeColor = System.Drawing.Color.White;
  187. this.btnViewFiles.Location = new System.Drawing.Point(203, 1);
  188. this.btnViewFiles.Name = "btnViewFiles";
  189. this.btnViewFiles.Size = new System.Drawing.Size(67, 35);
  190. this.btnViewFiles.TabIndex = 5;
  191. this.btnViewFiles.Text = "&View Files";
  192. this.ToolTipText.SetToolTip(this.btnViewFiles, "View the searched files");
  193. this.btnViewFiles.Click += new System.EventHandler(this.btnViewFiles_Click);
  194. // 
  195. // btnRefresh
  196. // 
  197. this.btnRefresh.BackColor = System.Drawing.Color.Chocolate;
  198. this.btnRefresh.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  199. this.btnRefresh.ForeColor = System.Drawing.Color.White;
  200. this.btnRefresh.Location = new System.Drawing.Point(70, 1);
  201. this.btnRefresh.Name = "btnRefresh";
  202. this.btnRefresh.Size = new System.Drawing.Size(67, 35);
  203. this.btnRefresh.TabIndex = 1;
  204. this.btnRefresh.Text = "&Refresh";
  205. this.ToolTipText.SetToolTip(this.btnRefresh, "Refresh the computer list");
  206. this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
  207. // 
  208. // btnOpen
  209. // 
  210. this.btnOpen.BackColor = System.Drawing.Color.Chocolate;
  211. this.btnOpen.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
  212. this.btnOpen.ForeColor = System.Drawing.Color.White;
  213. this.btnOpen.Location = new System.Drawing.Point(3, 1);
  214. this.btnOpen.Name = "btnOpen";
  215. this.btnOpen.Size = new System.Drawing.Size(67, 35);
  216. this.btnOpen.TabIndex = 0;
  217. this.btnOpen.Text = "&Open";
  218. this.ToolTipText.SetToolTip(this.btnOpen, "Connect to the selected computer");
  219. this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
  220. // 
  221. // lvComputers
  222. // 
  223. this.lvComputers.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  224.   this.clhComputername,
  225.   this.clhIPAddress,
  226.   this.clhObjects});
  227. this.lvComputers.Location = new System.Drawing.Point(3, 41);
  228. this.lvComputers.Name = "lvComputers";
  229. this.lvComputers.Size = new System.Drawing.Size(530, 146);
  230. this.lvComputers.TabIndex = 7;
  231. this.ToolTipText.SetToolTip(this.lvComputers, "Select a computer to connect");
  232. this.lvComputers.View = System.Windows.Forms.View.Details;
  233. this.lvComputers.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lvComputers_KeyPress);
  234. this.lvComputers.DoubleClick += new System.EventHandler(this.lvComputers_DoubleClick);
  235. this.lvComputers.SelectedIndexChanged += new System.EventHandler(this.lvComputers_SelectedIndexChanged);
  236. // 
  237. // clhComputername
  238. // 
  239. this.clhComputername.Text = "Computername";
  240. this.clhComputername.Width = 222;
  241. // 
  242. // clhIPAddress
  243. // 
  244. this.clhIPAddress.Text = "IP Address";
  245. this.clhIPAddress.Width = 142;
  246. // 
  247. // clhObjects
  248. // 
  249. this.clhObjects.Text = "No. of Objects found";
  250. this.clhObjects.Width = 112;
  251. // 
  252. // lblCopyright
  253. // 
  254. this.lblCopyright.Location = new System.Drawing.Point(348, 10);
  255. this.lblCopyright.Name = "lblCopyright";
  256. this.lblCopyright.Size = new System.Drawing.Size(192, 14);
  257. this.lblCopyright.TabIndex = 6;
  258. this.lblCopyright.Text = "