diff --git a/Chapter6/Chapter6.csproj b/Chapter6/Chapter6.csproj index 40481cf..896ee03 100644 --- a/Chapter6/Chapter6.csproj +++ b/Chapter6/Chapter6.csproj @@ -46,14 +46,26 @@ - - Form + + Form - - Form1.cs + + frmCalculate.cs + + + Form + + + frmSummary.cs + + frmCalculate.cs + + + frmSummary.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/Chapter6/Form1.Designer.cs b/Chapter6/Form1.Designer.cs deleted file mode 100644 index 572a7c8..0000000 --- a/Chapter6/Form1.Designer.cs +++ /dev/null @@ -1,40 +0,0 @@ -namespace Chapter6 -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} \ No newline at end of file diff --git a/Chapter6/Form1.cs b/Chapter6/Form1.cs deleted file mode 100644 index 91ae81e..0000000 --- a/Chapter6/Form1.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Chapter6 -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/Chapter6/Program.cs b/Chapter6/Program.cs index bf754c9..af940e1 100644 --- a/Chapter6/Program.cs +++ b/Chapter6/Program.cs @@ -16,7 +16,7 @@ namespace Chapter6 { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new Form1()); + Application.Run(new frmCalculate()); } } } \ No newline at end of file diff --git a/Chapter6/frmCalculate.Designer.cs b/Chapter6/frmCalculate.Designer.cs new file mode 100644 index 0000000..2c6b29c --- /dev/null +++ b/Chapter6/frmCalculate.Designer.cs @@ -0,0 +1,247 @@ +using System.ComponentModel; + +namespace Chapter6 +{ + partial class frmCalculate + { + /// + /// Required designer variable. + /// + private IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btnCalc = new System.Windows.Forms.Button(); + this.lblOut = new System.Windows.Forms.Label(); + this.txtDiscount = new System.Windows.Forms.TextBox(); + this.txtPrice = new System.Windows.Forms.TextBox(); + this.txtQuantity = new System.Windows.Forms.TextBox(); + this.lblDisQuantity = new System.Windows.Forms.Label(); + this.lblDisPrice = new System.Windows.Forms.Label(); + this.lblDisDiscount = new System.Windows.Forms.Label(); + this.miniToolStrip = new System.Windows.Forms.MenuStrip(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuMain = new System.Windows.Forms.MenuStrip(); + this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuFileExit = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuEdit = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuEditCalculate = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuEditSSummary = new System.Windows.Forms.ToolStripMenuItem(); + this.windowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.miniToolStrip.SuspendLayout(); + this.mnuMain.SuspendLayout(); + this.SuspendLayout(); + // + // btnCalc + // + this.btnCalc.Location = new System.Drawing.Point(235, 189); + this.btnCalc.Name = "btnCalc"; + this.btnCalc.Size = new System.Drawing.Size(125, 34); + this.btnCalc.TabIndex = 0; + this.btnCalc.Text = "Calculate"; + this.btnCalc.UseVisualStyleBackColor = true; + this.btnCalc.Click += new System.EventHandler(this.btnCalc_Click); + // + // lblOut + // + this.lblOut.BackColor = System.Drawing.SystemColors.Info; + this.lblOut.Location = new System.Drawing.Point(234, 154); + this.lblOut.Name = "lblOut"; + this.lblOut.Size = new System.Drawing.Size(125, 25); + this.lblOut.TabIndex = 1; + // + // txtDiscount + // + this.txtDiscount.Location = new System.Drawing.Point(235, 110); + this.txtDiscount.Name = "txtDiscount"; + this.txtDiscount.Size = new System.Drawing.Size(125, 20); + this.txtDiscount.TabIndex = 2; + // + // txtPrice + // + this.txtPrice.Location = new System.Drawing.Point(234, 84); + this.txtPrice.Name = "txtPrice"; + this.txtPrice.Size = new System.Drawing.Size(125, 20); + this.txtPrice.TabIndex = 3; + // + // txtQuantity + // + this.txtQuantity.Location = new System.Drawing.Point(235, 58); + this.txtQuantity.Name = "txtQuantity"; + this.txtQuantity.Size = new System.Drawing.Size(125, 20); + this.txtQuantity.TabIndex = 4; + // + // lblDisQuantity + // + this.lblDisQuantity.Location = new System.Drawing.Point(81, 61); + this.lblDisQuantity.Name = "lblDisQuantity"; + this.lblDisQuantity.Size = new System.Drawing.Size(148, 19); + this.lblDisQuantity.TabIndex = 5; + this.lblDisQuantity.Text = "Quantity:"; + this.lblDisQuantity.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // lblDisPrice + // + this.lblDisPrice.Location = new System.Drawing.Point(81, 84); + this.lblDisPrice.Name = "lblDisPrice"; + this.lblDisPrice.Size = new System.Drawing.Size(148, 19); + this.lblDisPrice.TabIndex = 6; + this.lblDisPrice.Text = "Price:"; + this.lblDisPrice.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // lblDisDiscount + // + this.lblDisDiscount.Location = new System.Drawing.Point(81, 110); + this.lblDisDiscount.Name = "lblDisDiscount"; + this.lblDisDiscount.Size = new System.Drawing.Size(148, 19); + this.lblDisDiscount.TabIndex = 7; + this.lblDisDiscount.Text = "Discount (%):"; + this.lblDisDiscount.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // miniToolStrip + // + this.miniToolStrip.AutoSize = false; + this.miniToolStrip.Dock = System.Windows.Forms.DockStyle.None; + this.miniToolStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem1 }); + this.miniToolStrip.Location = new System.Drawing.Point(131, 2); + this.miniToolStrip.Name = "miniToolStrip"; + this.miniToolStrip.Size = new System.Drawing.Size(800, 24); + this.miniToolStrip.TabIndex = 8; + this.miniToolStrip.Visible = false; + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(125, 20); + this.toolStripMenuItem1.Text = "toolStripMenuItem1"; + this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); + // + // mnuMain + // + this.mnuMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.mnuEdit, this.windowToolStripMenuItem, this.helpToolStripMenuItem }); + this.mnuMain.Location = new System.Drawing.Point(0, 0); + this.mnuMain.Name = "mnuMain"; + this.mnuMain.Size = new System.Drawing.Size(800, 24); + this.mnuMain.TabIndex = 9; + this.mnuMain.Text = "menuStrip1"; + // + // fileToolStripMenuItem + // + this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mnuFileExit }); + this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; + this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); + this.fileToolStripMenuItem.Text = "File"; + // + // mnuFileExit + // + this.mnuFileExit.Name = "mnuFileExit"; + this.mnuFileExit.Size = new System.Drawing.Size(93, 22); + this.mnuFileExit.Text = "Exit"; + // + // mnuEdit + // + this.mnuEdit.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.mnuEditCalculate, this.mnuEditSSummary }); + this.mnuEdit.Name = "mnuEdit"; + this.mnuEdit.Size = new System.Drawing.Size(39, 20); + this.mnuEdit.Text = "Edit"; + // + // mnuEditCalculate + // + this.mnuEditCalculate.Name = "mnuEditCalculate"; + this.mnuEditCalculate.Size = new System.Drawing.Size(157, 22); + this.mnuEditCalculate.Text = "Calculate"; + this.mnuEditCalculate.Click += new System.EventHandler(this.mnuEditCalculate_Click); + // + // mnuEditSSummary + // + this.mnuEditSSummary.Name = "mnuEditSSummary"; + this.mnuEditSSummary.Size = new System.Drawing.Size(157, 22); + this.mnuEditSSummary.Text = "Show Summary"; + this.mnuEditSSummary.Click += new System.EventHandler(this.mnuEditSSummary_Click); + // + // windowToolStripMenuItem + // + this.windowToolStripMenuItem.Name = "windowToolStripMenuItem"; + this.windowToolStripMenuItem.Size = new System.Drawing.Size(63, 20); + this.windowToolStripMenuItem.Text = "Window"; + // + // helpToolStripMenuItem + // + this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; + this.helpToolStripMenuItem.Size = new System.Drawing.Size(44, 20); + this.helpToolStripMenuItem.Text = "Help"; + // + // frmCalculate + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.Control; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.lblDisDiscount); + this.Controls.Add(this.lblDisPrice); + this.Controls.Add(this.lblDisQuantity); + this.Controls.Add(this.txtQuantity); + this.Controls.Add(this.txtPrice); + this.Controls.Add(this.txtDiscount); + this.Controls.Add(this.lblOut); + this.Controls.Add(this.btnCalc); + this.Controls.Add(this.miniToolStrip); + this.Controls.Add(this.mnuMain); + this.Location = new System.Drawing.Point(15, 15); + this.MainMenuStrip = this.mnuMain; + this.Name = "frmCalculate"; + this.miniToolStrip.ResumeLayout(false); + this.miniToolStrip.PerformLayout(); + this.mnuMain.ResumeLayout(false); + this.mnuMain.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + } + + private System.Windows.Forms.MenuStrip miniToolStrip; + private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem mnuEdit; + private System.Windows.Forms.ToolStripMenuItem mnuEditCalculate; + private System.Windows.Forms.ToolStripMenuItem mnuEditSSummary; + private System.Windows.Forms.ToolStripMenuItem windowToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem mnuFileExit; + + private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; + + private System.Windows.Forms.MenuStrip mnuMain; + + private System.Windows.Forms.TextBox txtDiscount; + private System.Windows.Forms.TextBox txtPrice; + private System.Windows.Forms.TextBox txtQuantity; + private System.Windows.Forms.Label lblDisQuantity; + private System.Windows.Forms.Label lblDisPrice; + private System.Windows.Forms.Label lblDisDiscount; + + private System.Windows.Forms.Button btnCalc; + private System.Windows.Forms.Label lblOut; + + #endregion + } +} \ No newline at end of file diff --git a/Chapter6/frmCalculate.cs b/Chapter6/frmCalculate.cs new file mode 100644 index 0000000..bd76515 --- /dev/null +++ b/Chapter6/frmCalculate.cs @@ -0,0 +1,114 @@ +using System; +using System.Windows.Forms; + +namespace Chapter6 +{ + public partial class frmCalculate : Form + { + + public static decimal decDiscountAmt, decTotalPrice, decTotalAmnt = 0; + public static int intTotalQuantity = 0; + + public frmCalculate() + { + InitializeComponent(); + } + + private void lblDisQuantity_Click(object sender, EventArgs e) + { + // throw new System.NotImplementedException(); + } + + private decimal Calculate(int quantity, decimal price, decimal discount) + { + + return (quantity * price) * (1 - (discount - 100)); + + } + + private void btnCalc_Click(object sender, EventArgs e) + { + int intQuantity = 0; + decimal decPrice = 0; + decimal decDiscount = 0; + + try + { + + + intQuantity = int.Parse(txtQuantity.Text); + + try + { + + + decPrice = int.Parse(txtPrice.Text); + + try + { + + + decDiscount = int.Parse(txtDiscount.Text); + + lblOut.Text = Calculate(intQuantity, decPrice, decDiscount).ToString("C"); + + } + catch (Exception exception) + { + //discount error + } + + + } + catch (Exception exception) + { + //price error + } + + + } + catch (Exception exception) + { + //quantity Error + } + } + + private void toolStripMenuItem1_Click(object sender, EventArgs e) + { + // throw new System.NotImplementedException(); + } + + private void mnuEditCalculate_Click(object sender, EventArgs e) + { + if (mnuEditCalculate.Checked) + { + mnuEdit.Checked = false; + } + else + { + mnuEditCalculate.Checked = true; + } + } + + + + + + private void mnuEditSSummary_Click(object sender, EventArgs e) + { + + if (mnuEditSSummary.Checked) + { + mnuEditSSummary.Checked = false; + } + else + { + mnuEditSSummary.Checked = true; + frmSummary frm = new frmSummary(); + frm.Show(); + frm.Focus(); + } + + } + } +} \ No newline at end of file diff --git a/Chapter6/frmCalculate.resx b/Chapter6/frmCalculate.resx new file mode 100644 index 0000000..69bce91 --- /dev/null +++ b/Chapter6/frmCalculate.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 135, 17 + + \ No newline at end of file diff --git a/Chapter6/frmSummary.Designer.cs b/Chapter6/frmSummary.Designer.cs new file mode 100644 index 0000000..a5ee762 --- /dev/null +++ b/Chapter6/frmSummary.Designer.cs @@ -0,0 +1,147 @@ +using System.ComponentModel; + +namespace Chapter6 +{ + partial class frmSummary + { + /// + /// Required designer variable. + /// + private IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lblQuantity = new System.Windows.Forms.Label(); + this.lblPrice = new System.Windows.Forms.Label(); + this.lblDiscount = new System.Windows.Forms.Label(); + this.lblTotal = new System.Windows.Forms.Label(); + this.lblDisTotal = new System.Windows.Forms.Label(); + this.lblDisDiscount = new System.Windows.Forms.Label(); + this.lblDisPrice = new System.Windows.Forms.Label(); + this.lblDisQuantity = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // lblQuantity + // + this.lblQuantity.BackColor = System.Drawing.SystemColors.Info; + this.lblQuantity.Location = new System.Drawing.Point(298, 137); + this.lblQuantity.Name = "lblQuantity"; + this.lblQuantity.Size = new System.Drawing.Size(128, 29); + this.lblQuantity.TabIndex = 0; + this.lblQuantity.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // lblPrice + // + this.lblPrice.BackColor = System.Drawing.SystemColors.Info; + this.lblPrice.Location = new System.Drawing.Point(298, 166); + this.lblPrice.Name = "lblPrice"; + this.lblPrice.Size = new System.Drawing.Size(128, 29); + this.lblPrice.TabIndex = 1; + this.lblPrice.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // lblDiscount + // + this.lblDiscount.BackColor = System.Drawing.SystemColors.Info; + this.lblDiscount.Location = new System.Drawing.Point(298, 195); + this.lblDiscount.Name = "lblDiscount"; + this.lblDiscount.Size = new System.Drawing.Size(128, 29); + this.lblDiscount.TabIndex = 2; + this.lblDiscount.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // lblTotal + // + this.lblTotal.BackColor = System.Drawing.SystemColors.Info; + this.lblTotal.Location = new System.Drawing.Point(298, 224); + this.lblTotal.Name = "lblTotal"; + this.lblTotal.Size = new System.Drawing.Size(128, 29); + this.lblTotal.TabIndex = 3; + this.lblTotal.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // lblDisTotal + // + this.lblDisTotal.BackColor = System.Drawing.SystemColors.Control; + this.lblDisTotal.Location = new System.Drawing.Point(146, 224); + this.lblDisTotal.Name = "lblDisTotal"; + this.lblDisTotal.Size = new System.Drawing.Size(128, 29); + this.lblDisTotal.TabIndex = 7; + this.lblDisTotal.Text = "Total Sale"; + this.lblDisTotal.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // lblDisDiscount + // + this.lblDisDiscount.Location = new System.Drawing.Point(146, 195); + this.lblDisDiscount.Name = "lblDisDiscount"; + this.lblDisDiscount.Size = new System.Drawing.Size(128, 29); + this.lblDisDiscount.TabIndex = 6; + this.lblDisDiscount.Text = "Discount"; + this.lblDisDiscount.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // lblDisPrice + // + this.lblDisPrice.Location = new System.Drawing.Point(146, 166); + this.lblDisPrice.Name = "lblDisPrice"; + this.lblDisPrice.Size = new System.Drawing.Size(128, 29); + this.lblDisPrice.TabIndex = 5; + this.lblDisPrice.Text = "Price"; + this.lblDisPrice.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // lblDisQuantity + // + this.lblDisQuantity.Location = new System.Drawing.Point(146, 137); + this.lblDisQuantity.Name = "lblDisQuantity"; + this.lblDisQuantity.Size = new System.Drawing.Size(128, 29); + this.lblDisQuantity.TabIndex = 4; + this.lblDisQuantity.Text = "Quantity"; + this.lblDisQuantity.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + // + // frmSummary + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.lblDisTotal); + this.Controls.Add(this.lblDisDiscount); + this.Controls.Add(this.lblDisPrice); + this.Controls.Add(this.lblDisQuantity); + this.Controls.Add(this.lblTotal); + this.Controls.Add(this.lblDiscount); + this.Controls.Add(this.lblPrice); + this.Controls.Add(this.lblQuantity); + this.Name = "frmSummary"; + this.Text = "frmSummary"; + this.ResumeLayout(false); + } + + private System.Windows.Forms.Label lblDisTotal; + private System.Windows.Forms.Label lblDisDiscount; + private System.Windows.Forms.Label lblDisPrice; + private System.Windows.Forms.Label lblDisQuantity; + + private System.Windows.Forms.Label lblQuantity; + private System.Windows.Forms.Label lblPrice; + private System.Windows.Forms.Label lblDiscount; + private System.Windows.Forms.Label lblTotal; + + #endregion + } +} \ No newline at end of file diff --git a/Chapter6/frmSummary.cs b/Chapter6/frmSummary.cs new file mode 100644 index 0000000..60c4d2a --- /dev/null +++ b/Chapter6/frmSummary.cs @@ -0,0 +1,22 @@ +using System; +using System.Windows.Forms; + +namespace Chapter6 +{ + public partial class frmSummary : Form + { + public frmSummary() + { + InitializeComponent(); + // this.FormClosing += new FormClosingEventHandler(FrmSummary_FormClosing); + this.Activated += new EventHandler(frmSummary_Activated); + } + + private void frmSummary_Activated(object sender, EventArgs e) + { + + + + } + } +} \ No newline at end of file diff --git a/Chapter6/frmSummary.resx b/Chapter6/frmSummary.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Chapter6/frmSummary.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file