|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using SharpUtils;
namespace Laptop_Backup
{
/// <summary>
/// Summary description for PortNumber.
/// </summary>
public class PortNumber : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button okButton;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private DebugLevel debugLevel;
private SimpleEventLog eventLog;
private QuickRegistry reg;
public PortNumber()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
debugLevel = new DebugLevel( DebugLevel.currentLevel );
eventLog = new SimpleEventLog( "Laptop Backup", false );
reg = new QuickRegistry();
if( reg.OpenKey( "HKEY_LOCAL_MACHINE", "Software\\Laptop Backup", true ) == false )
{
if( reg.Error == true )
{
if( debugLevel.TestDebugLevel( DebugLevelSet.Errors ) == true )
{
eventLog.WriteError( "PortNumber Error " + reg.ErrorMessage );
}
MessageBox.Show( "Error Opening the registry key for Laptop Backup " );
return;
}
}
string strTest = ( string )reg.GetValue( "PortNumber" );
if( reg.Error == true || strTest == null )
{
if( debugLevel.TestDebugLevel( DebugLevelSet.Errors ) == true )
{
eventLog.WriteError( "Unable to get the port number " + reg.ErrorMessage );
}
strTest = "8086";
}
textBox1.Text = strTest;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.cancelButton = new System.Windows.Forms.Button();
this.okButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
this.label1.Location = new System.Drawing.Point(8, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(272, 56);
this.label1.TabIndex = 0;
this.label1.Text = "Caution !! The default Port Number for this program is 8086. By changing it on th" +
"is computer you must change it on all other computers that run Laptop Backup";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 80);
this.label2.Name = "label2";
this.label2.TabIndex = 1;
this.label2.Text = "Port Number";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(136, 80);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 2;
this.textBox1.Text = "textBox1";
//
// cancelButton
//
this.cancelButton.Location = new System.Drawing.Point(208, 120);
this.cancelButton.Name = "cancelButton";
this.cancelButton.TabIndex = 3;
this.cancelButton.Text = "Cancel";
this.cancelButton.Click += new System.EventHandler(this.OnCancel);
//
// okButton
//
this.okButton.Location = new System.Drawing.Point(208, 160);
this.okButton.Name = "okButton";
this.okButton.TabIndex = 4;
this.okButton.Text = "O.K.";
this.okButton.Click += new System.EventHandler(this.OnOKButton);
//
// PortNumber
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 198);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.okButton,
this.cancelButton,
this.textBox1,
this.label2,
this.label1});
this.Name = "PortNumber";
this.Text = "Laptop Backup";
this.ResumeLayout(false);
}
#endregion
private void OnOKButton(object sender, System.EventArgs e)
{
bool bException = false;
try
{
/// check the entered port number is valid
Int32.Parse( textBox1.Text );
}
catch( ArgumentNullException argNullExp )
{
bException = true;
if( debugLevel.TestDebugLevel( DebugLevelSet.All ) == true )
{
eventLog.WriteInformation( "Exception thrown parsing " + argNullExp.Message );
}
}
catch( FormatException forExp )
{
bException = true;
if( debugLevel.TestDebugLevel( DebugLevelSet.All ) == true )
{
eventLog.WriteInformation( "Exception thrown parsing " + forExp.Message );
}
}
catch( OverflowException ofExp )
{
bException = true;
if( debugLevel.TestDebugLevel( DebugLevelSet.All ) == true )
{
eventLog.WriteInformation( "Exception thrown parsing " + ofExp.Message );
}
}
if( bException == false )
{
reg.SetValue( "PortNumber", textBox1.Text );
}
/// 7 September 2004
/// dialog result fix
///
DialogResult = DialogResult.OK;
this.Close();
}
private void OnCancel(object sender, System.EventArgs e)
{
/// 7 September 2004
/// dialog result fix
///
DialogResult = DialogResult.Cancel;
this.Close();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.