home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue71 / CSharp / CS / WinApp / Form1.cs < prev    next >
Encoding:
Text File  |  2001-05-20  |  7.0 KB  |  200 lines

  1. namespace WinApp
  2. {
  3.     using System;
  4.     using System.Drawing;
  5.     using System.Collections;
  6.     using System.ComponentModel;
  7.     using System.WinForms;
  8.     using System.Data;
  9.  
  10.     /// <summary>
  11.     ///    Summary description for Form1.
  12.     /// </summary>
  13.     public class Form1 : System.WinForms.Form
  14.     {
  15.         /// <summary>
  16.         ///    Required designer variable.
  17.         /// </summary>
  18.         private System.ComponentModel.Container components;
  19.         private System.WinForms.Label label2;
  20.         private System.WinForms.CheckedListBox clbOptions;
  21.         private System.WinForms.Label label1;
  22.         private System.WinForms.TextBox edtCost;
  23.         private System.WinForms.RadioButton rbBasic;
  24.         private System.WinForms.RadioButton rbProfessional;
  25.         private System.WinForms.RadioButton rbAdvanced;
  26.         private System.WinForms.GroupBox groupBox1;
  27.         private System.WinForms.Button btnCalculate;
  28.  
  29.         public Form1()
  30.         {
  31.             //
  32.             // Required for Windows Form Designer support
  33.             //
  34.             InitializeComponent();
  35.  
  36.             //
  37.             // TODO: Add any constructor code after InitializeComponent call
  38.             //
  39.         }
  40.  
  41.         /// <summary>
  42.         ///    Clean up any resources being used.
  43.         /// </summary>
  44.         public override void Dispose()
  45.         {
  46.             base.Dispose();
  47.             components.Dispose();
  48.         }
  49.  
  50.         /// <summary>
  51.         ///    Required method for Designer support - do not modify
  52.         ///    the contents of this method with the code editor.
  53.         /// </summary>
  54.         private void InitializeComponent()
  55.         {
  56.             this.components = new System.ComponentModel.Container ();
  57.             this.groupBox1 = new System.WinForms.GroupBox ();
  58.             this.rbProfessional = new System.WinForms.RadioButton ();
  59.             this.clbOptions = new System.WinForms.CheckedListBox ();
  60.             this.label1 = new System.WinForms.Label ();
  61.             this.btnCalculate = new System.WinForms.Button ();
  62.             this.rbBasic = new System.WinForms.RadioButton ();
  63.             this.rbAdvanced = new System.WinForms.RadioButton ();
  64.             this.edtCost = new System.WinForms.TextBox ();
  65.             this.label2 = new System.WinForms.Label ();
  66.             //@this.TrayHeight = 0;
  67.             //@this.TrayLargeIcon = false;
  68.             //@this.TrayAutoArrange = true;
  69.             groupBox1.Location = new System.Drawing.Point (8, 8);
  70.             groupBox1.TabIndex = 1;
  71.             groupBox1.TabStop = false;
  72.             groupBox1.Text = "Package Type";
  73.             groupBox1.Size = new System.Drawing.Size (104, 96);
  74.             rbProfessional.Location = new System.Drawing.Point (8, 72);
  75.             rbProfessional.Text = "Professional";
  76.             rbProfessional.Size = new System.Drawing.Size (88, 16);
  77.             rbProfessional.TabIndex = 2;
  78.             rbProfessional.CheckedChanged += new System.EventHandler (this.rbProfessional_CheckedChanged);
  79.             clbOptions.Location = new System.Drawing.Point (8, 128);
  80.             clbOptions.Size = new System.Drawing.Size (304, 79);
  81.             clbOptions.CheckOnClick = true;
  82.             clbOptions.TabIndex = 4;
  83.             clbOptions.SelectedIndexChanged += new System.EventHandler (this.clbOptions_SelectedIndexChanged);
  84.             clbOptions.Items.All = new object[5] {"Register UK domain name (e.g. .co.uk)", "Register US domain name (e.g. .com)", "Additional 50MB web space (Professional Package only)", "Easy-Secure: secure form-to-encrypted-email processing", "Pro-Secure: 20Mb of your own secure server space"};
  85.             label1.Location = new System.Drawing.Point (208, 80);
  86.             label1.Text = "Total Package Cost:";
  87.             label1.Size = new System.Drawing.Size (104, 16);
  88.             label1.TabIndex = 3;
  89.             btnCalculate.Location = new System.Drawing.Point (216, 32);
  90.             btnCalculate.Size = new System.Drawing.Size (80, 24);
  91.             btnCalculate.TabIndex = 0;
  92.             btnCalculate.Text = "Calculate";
  93.             btnCalculate.Click += new System.EventHandler (this.btnCalculate_Click);
  94.             rbBasic.Location = new System.Drawing.Point (8, 16);
  95.             rbBasic.Text = "Basic";
  96.             rbBasic.Size = new System.Drawing.Size (80, 23);
  97.             rbBasic.TabIndex = 3;
  98.             rbBasic.CheckedChanged += new System.EventHandler (this.rbBasic_CheckedChanged);
  99.             rbAdvanced.Location = new System.Drawing.Point (8, 46);
  100.             rbAdvanced.Text = "Advanced";
  101.             rbAdvanced.Size = new System.Drawing.Size (72, 16);
  102.             rbAdvanced.TabIndex = 1;
  103.             rbAdvanced.CheckedChanged += new System.EventHandler (this.rbAdvanced_CheckedChanged);
  104.             edtCost.Location = new System.Drawing.Point (208, 96);
  105.             edtCost.TabIndex = 2;
  106.             edtCost.Size = new System.Drawing.Size (80, 20);
  107.             label2.Location = new System.Drawing.Point (8, 112);
  108.             label2.Text = "Options:";
  109.             label2.Size = new System.Drawing.Size (56, 16);
  110.             label2.TabIndex = 5;
  111.             this.Text = "C# UI Delphi Calculator";
  112.             this.MaximizeBox = false;
  113.             this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
  114.             this.MinimizeBox = false;
  115.             this.ClientSize = new System.Drawing.Size (320, 213);
  116.             this.Activated += new System.EventHandler (this.Form1_Activated);
  117.             groupBox1.Controls.Add (this.rbBasic);
  118.             groupBox1.Controls.Add (this.rbProfessional);
  119.             groupBox1.Controls.Add (this.rbAdvanced);
  120.             this.Controls.Add (this.label2);
  121.             this.Controls.Add (this.clbOptions);
  122.             this.Controls.Add (this.label1);
  123.             this.Controls.Add (this.edtCost);
  124.             this.Controls.Add (this.groupBox1);
  125.             this.Controls.Add (this.btnCalculate);
  126.         }
  127.  
  128.         protected void rbAdvanced_CheckedChanged (object sender, System.EventArgs e)
  129.         {
  130.             clbOptions.SetItemCheckState(2, CheckState.Indeterminate);
  131.         }
  132.  
  133.         protected void rbBasic_CheckedChanged (object sender, System.EventArgs e)
  134.         {
  135.             clbOptions.SetItemCheckState(2, CheckState.Indeterminate);
  136.         }
  137.  
  138.         protected void rbProfessional_CheckedChanged (object sender, System.EventArgs e)
  139.         {
  140.             clbOptions.SetItemCheckState(2, CheckState.Unchecked);    
  141.         }
  142.  
  143.         protected void Form1_Activated (object sender, System.EventArgs e)
  144.         {
  145.             rbBasic.Checked = true;
  146.             clbOptions.SetItemCheckState(2, CheckState.Unchecked);    
  147.         }
  148.  
  149.         protected void clbOptions_SelectedIndexChanged (object sender, System.EventArgs e)
  150.         {
  151.             if  ((clbOptions.SelectedIndex == 2) && (!rbProfessional.Checked))
  152.             {
  153.                 clbOptions.SetItemCheckState(2, CheckState.Indeterminate);
  154.             }
  155.         }
  156.  
  157.         protected void btnCalculate_Click (object sender, System.EventArgs e)
  158.         {
  159.             // Create an instance of the Delphi TDMWebLib package calculator
  160.             TDMWebLib.Package obj = new TDMWebLib.Package();
  161.  
  162.             double dCost = 0;
  163.             int i, iOptions = 0;
  164.             
  165.             for (i=0;i<clbOptions.Items.Count;i++)
  166.             {
  167.                 if (clbOptions.GetItemChecked(i) && (clbOptions.GetItemCheckState(i)!=CheckState.Indeterminate))
  168.                 {
  169.                     iOptions = (1 << i) + iOptions;
  170.                 }
  171.             }
  172.             
  173.             if (rbBasic.Checked) 
  174.             {
  175.                 dCost = obj.Basic(iOptions);
  176.             }        
  177.             else
  178.             if (rbAdvanced.Checked) 
  179.             {
  180.                 dCost = obj.Advanced(iOptions);
  181.             }
  182.             else
  183.             if (rbProfessional.Checked) 
  184.             {
  185.                 dCost = obj.Professional(iOptions);
  186.             }
  187.             
  188.             edtCost.Text = 'รบ' + dCost.ToString();
  189.         }
  190.  
  191.         /// <summary>
  192.         /// The main entry point for the application.
  193.         /// </summary>
  194.         public static void Main(string[] args) 
  195.         {
  196.             Application.Run(new Form1());
  197.         }
  198.     }
  199. }
  200.