📄 frmclient.cs
字号:
namespace Client // Copyright 2001 Dreamtech Software India Inc.
{ // All rights reserved
using System; // Provides the basic functionality of .NET
using System.Drawing; // Provides the Drawing features, Used for cursors
using System.Collections; // Provides the different type of class collections
using System.ComponentModel;// Provides the facility of using components
using System.Windows.Forms; // Provides the darwing of buttons, listviews etc
using System.Net; // Provides the net related functionality
using System.Text; // Provides the text manipulation functions
using System.IO; // Provides I/O features
using WorkingWithXML; // Custom Class
/// <summary>
/// This structure is used for book keeping purpose
/// The currently running listener list will be requsted
/// by the server and server sends that list
/// Each record in this structure represent the data for the single
/// running listener
/// </summary>
public struct __CONNECTEDCOMPUTERS
{
/// <summary>
/// Declares the string used to store the name of the listener
/// This name is in human redable format
/// </summary>
public string sComputername;
/// <summary>
/// sIPAddress variable is used to store the IP address of
/// the listener
/// </summary>
public string sIPAddress;
/// <summary>
/// This will be 0 in starting and consequently filled
/// by every search operation
/// </summary>
public int iFilesFound;
}
/// <summary>
/// Summary description for frmClient class.
/// </summary>
public class frmClient : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button btnViewFiles;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.ToolTip ToolTipText;
private System.Windows.Forms.Button btnQuit;
private System.Windows.Forms.Button btnRefresh;
private System.Windows.Forms.Button btnOpen;
/// <summary>
/// The below declared variables are the user defined variables
/// used within this class
/// </summary>
/// <summary>
/// Stores the total number of listeners found
/// </summary>
private int iConnectedComputers;
/// <summary>
/// Stores the number of search results found for
/// the matching criteria
/// </summary>
private int iSearchResult;
/// <summary>
/// Declares a xmlParser variable of type XMLParser (User defined class)
/// </summary>
private XMLParser xmlParser;
/// <summary>
/// Declares a xmlServerComm variable of type ServerCommunication
/// (User defined class)
/// </summary>
private ServerCommunication xmlServerComm;
/// <summary>
/// Declares an object xmlStruct of type XMLSTRUCT (User defined class)
/// </summary>
private XMLSTRUCT xmlStruct;
/// <summary>
/// Declares an array of ConnectedComputers of type
/// __CONNECTEDCOMPUTERS structures
/// </summary>
private __CONNECTEDCOMPUTERS[] ConnectedComputers;
private System.Windows.Forms.ListView lvComputers;
private System.Windows.Forms.ColumnHeader clhComputername;
private System.Windows.Forms.ColumnHeader clhIPAddress;
private System.Windows.Forms.ColumnHeader clhObjects;
private System.Windows.Forms.Label lblCopyright;
/// <summary>
/// declares sSubItems variable as an array of string
/// </summary>
private System.Windows.Forms.ListViewItem lvItems;
/// <summary>
/// This is the default constructor of the class
/// </summary>
public frmClient()
{
//
// Required for Windows Form Designer support
//
// Auto generated function by the IDE
InitializeComponent();
// Puts the Computer.ico as the form icon
this.Icon = new System.Drawing.Icon(Application.StartupPath + "\\Computer.ico");
// Creates a new instance of XMLParser class
xmlParser = new WorkingWithXML.XMLParser();
// Creates a new instance of XMLSTRUCT structure
xmlStruct = new WorkingWithXML.XMLSTRUCT();
// Creates a new instance for ServerCommunication class
xmlServerComm = new WorkingWithXML.ServerCommunication();
// Assigns the global value for USERLISTXML
xmlParser.USERLISTXML = Application.StartupPath + "\\userlist.xml";
// Assigns the global value for SERVERSEARCHXML
xmlParser.SERVERSEARCHRESULTXML = Application.StartupPath + "\\search.xml";
try
{
// Fills the List view with the values
// these values are the response from the server
if( 0 == PopulateList() )
// Displays a message if no computer is connected to the network
throw new Exception("No computer is connected to the network. The list will be empty");
}
// Hanldes every exceptions that is thrown
catch( Exception err ) { MessageBox.Show(err.Message,"Warning",MessageBoxButtons.OK, MessageBoxIcon.Warning); }
}
/// <summary>
/// Clean up any resources being used.
/// This is auto generated by the IDE
/// </summary>
public override void Dispose()
{
base.Dispose();
components.Dispose();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// this code is generated automatically by the IDE
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.ToolTipText = new System.Windows.Forms.ToolTip(this.components);
this.btnSearch = new System.Windows.Forms.Button();
this.btnQuit = new System.Windows.Forms.Button();
this.btnViewFiles = new System.Windows.Forms.Button();
this.btnRefresh = new System.Windows.Forms.Button();
this.btnOpen = new System.Windows.Forms.Button();
this.lvComputers = new System.Windows.Forms.ListView();
this.clhComputername = new System.Windows.Forms.ColumnHeader();
this.clhIPAddress = new System.Windows.Forms.ColumnHeader();
this.clhObjects = new System.Windows.Forms.ColumnHeader();
this.lblCopyright = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnSearch
//
this.btnSearch.BackColor = System.Drawing.Color.Chocolate;
this.btnSearch.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnSearch.ForeColor = System.Drawing.Color.White;
this.btnSearch.Location = new System.Drawing.Point(137, 1);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(67, 35);
this.btnSearch.TabIndex = 2;
this.btnSearch.Text = "&Search";
this.ToolTipText.SetToolTip(this.btnSearch, "Search on computers for filenames");
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// btnQuit
//
this.btnQuit.BackColor = System.Drawing.Color.Chocolate;
this.btnQuit.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnQuit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnQuit.ForeColor = System.Drawing.Color.White;
this.btnQuit.Location = new System.Drawing.Point(270, 1);
this.btnQuit.Name = "btnQuit";
this.btnQuit.Size = new System.Drawing.Size(67, 35);
this.btnQuit.TabIndex = 3;
this.btnQuit.Text = "&Quit";
this.ToolTipText.SetToolTip(this.btnQuit, "Quit this application");
this.btnQuit.Click += new System.EventHandler(this.btnQuit_Click);
//
// btnViewFiles
//
this.btnViewFiles.BackColor = System.Drawing.Color.Chocolate;
this.btnViewFiles.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnViewFiles.Enabled = false;
this.btnViewFiles.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnViewFiles.ForeColor = System.Drawing.Color.White;
this.btnViewFiles.Location = new System.Drawing.Point(203, 1);
this.btnViewFiles.Name = "btnViewFiles";
this.btnViewFiles.Size = new System.Drawing.Size(67, 35);
this.btnViewFiles.TabIndex = 5;
this.btnViewFiles.Text = "&View Files";
this.ToolTipText.SetToolTip(this.btnViewFiles, "View the searched files");
this.btnViewFiles.Click += new System.EventHandler(this.btnViewFiles_Click);
//
// btnRefresh
//
this.btnRefresh.BackColor = System.Drawing.Color.Chocolate;
this.btnRefresh.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnRefresh.ForeColor = System.Drawing.Color.White;
this.btnRefresh.Location = new System.Drawing.Point(70, 1);
this.btnRefresh.Name = "btnRefresh";
this.btnRefresh.Size = new System.Drawing.Size(67, 35);
this.btnRefresh.TabIndex = 1;
this.btnRefresh.Text = "&Refresh";
this.ToolTipText.SetToolTip(this.btnRefresh, "Refresh the computer list");
this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
//
// btnOpen
//
this.btnOpen.BackColor = System.Drawing.Color.Chocolate;
this.btnOpen.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnOpen.ForeColor = System.Drawing.Color.White;
this.btnOpen.Location = new System.Drawing.Point(3, 1);
this.btnOpen.Name = "btnOpen";
this.btnOpen.Size = new System.Drawing.Size(67, 35);
this.btnOpen.TabIndex = 0;
this.btnOpen.Text = "&Open";
this.ToolTipText.SetToolTip(this.btnOpen, "Connect to the selected computer");
this.btnOpen.Click += new System.EventHandler(this.btnOpen_Click);
//
// lvComputers
//
this.lvComputers.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.clhComputername,
this.clhIPAddress,
this.clhObjects});
this.lvComputers.Location = new System.Drawing.Point(3, 41);
this.lvComputers.Name = "lvComputers";
this.lvComputers.Size = new System.Drawing.Size(530, 146);
this.lvComputers.TabIndex = 7;
this.ToolTipText.SetToolTip(this.lvComputers, "Select a computer to connect");
this.lvComputers.View = System.Windows.Forms.View.Details;
this.lvComputers.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.lvComputers_KeyPress);
this.lvComputers.DoubleClick += new System.EventHandler(this.lvComputers_DoubleClick);
this.lvComputers.SelectedIndexChanged += new System.EventHandler(this.lvComputers_SelectedIndexChanged);
//
// clhComputername
//
this.clhComputername.Text = "Computername";
this.clhComputername.Width = 222;
//
// clhIPAddress
//
this.clhIPAddress.Text = "IP Address";
this.clhIPAddress.Width = 142;
//
// clhObjects
//
this.clhObjects.Text = "No. of Objects found";
this.clhObjects.Width = 112;
//
// lblCopyright
//
this.lblCopyright.Location = new System.Drawing.Point(348, 10);
this.lblCopyright.Name = "lblCopyright";
this.lblCopyright.Size = new System.Drawing.Size(192, 14);
this.lblCopyright.TabIndex = 6;
this.lblCopyright.Text = "
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -