/// D.A.Applic_ of Arthimatic Calculation by Taking 3 Operands Using Properties Concept.
/// Conditions:
/// 1. Operand1 should be in range -100 to 100.
/// 2. Operand2 should be lessthan Operand1 & should not be Zero.
/// 3. Operand1 & Operand2 are Wrie-Only Property whereas Operand3 is Read-Only Property
/// 4. Computation of Methods(Add,Sub,Mul,Div) should be in seperate Class file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Property_Calulator1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
Math obj = new Math();
private void btn_SetValues_Click_1(object sender, EventArgs e)
{
obj.Operand1 = int.Parse(txt_oper1.Text);
obj.Operand2 = int.Parse(txt_oper2.Text);
foreach (Control ctrl in this.Controls)
{
if (ctrl is Button)
ctrl.Enabled = true;
}
}
private void btn_GetValue_Click_1(object sender, EventArgs e)
{
txt_result.Text = obj.Result.ToString();
}
private void btn_Plus_Click_1(object sender, EventArgs e)
{
obj.Add();
}
private void btn_Subtact_Click_1(object sender, EventArgs e)
{
obj.Sub();
}
private void btn_Multiply_Click_1(object sender, EventArgs e)
{
obj.Mul();
}
private void btn_Division_Click_1(object sender, EventArgs e)
{
obj.Div();
}
int oper1, oper2;
private void txt_oper1_Validating(object sender, CancelEventArgs e)
{
//Validating for "Oper1"Textbox must be acceptable b/w the Range -100 to 100
if(txt_oper1.Text.Trim().Length!=0)
oper1 = Convert.ToInt32(txt_oper1.Text);
if (oper1 > -100 && oper1 < 100)
return;
else
{
MessageBox.Show("Operand1 value should be in -100 to 100 Range");
e.Cancel = true;
}
}
private void txt_oper2_Validating(object sender, CancelEventArgs e)
{
//Validating for "Oper2" value should be less than "Oper1" & Should not be zero
if (txt_oper2.Text.Trim().Length != 0)
oper2 = Convert.ToInt32(txt_oper2.Text);
if (oper2 < oper1 && oper2 != 0)
{
btn_SetValues.Enabled = true;
return;
}
else
{
MessageBox.Show("Operand2 value should be Lessthan Operand1 &
Operand2 should not be Zero");
e.Cancel = true;
}
}
private void Form2_Load(object sender, EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
//MessageBox.Show(ctrl.GetType().ToString());
if(!(ctrl is TextBox) && !(ctrl is Label))
ctrl.Enabled = false;
txt_result.Enabled = false;
}
}
private void txt_oper1_KeyPress(object sender, KeyPressEventArgs e)
{
//MessageBox.Show(Convert.ToInt32(e.KeyChar).ToString());
if (char.IsDigit(e.KeyChar)==false && Convert.ToInt32(e.KeyChar)!= 8
&& Convert.ToInt32(e.KeyChar) != 45)
{
MessageBox.Show("Enter Numeric Values Only..");
e.Handled = true;
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Property_Calulator1
{
class Math
{
/// Property Fields
private int _operand1;
private int _operand2;
private double _result;
/// Properties
public int Operand1
{
set { _operand1 = value; }
}
public int Operand2
{
set { _operand2 = value; }
}
public double Result
{
get { return _result; }
}
public double GetValue()
{
return Result; //return _result;
}
public void Add()
{
_result = _operand1 + _operand2;//Result = Operand1 + Operand2;
}
public void Sub()
{
_result = _operand1 - _operand2;
}
public void Mul()
{
_result = _operand1 * _operand2;
}
public void Div()
{
_result = _operand1 / _operand2;
}
}
}¬¬¬
Blog Archive
-
▼
2010
(11)
-
▼
September
(7)
- DELEGATES AND EVENTS
- Difference Between ToString() vs Convert.ToString(...
- The StringBuilder and String classes provide ways ...
- C# Code: SQL & MS-Access DB Connection Class
- C# Code: Arthimatic Calculation by Taking 3 Operan...
- C# Code:Arthimatic Calculation by Taking 3 Operand...
- C# Code for Arthimatic Calculation by Taking 3 Ope...
-
▼
September
(7)
My Links
- C# Snippets: 1
- C# Snippets: 2
- XMLFOX - CSHARP SAMPLES
- Q: Export your Crystal Report data to PDF
- Q: To create a Excel report wihtout using Excel object model Ex
- Q: Using C#, How to Save,Update Data to and from XML with out using the sql server database
- Q: upload excel to SQL using C#.net,VS2005
- Q: Export DataTable to Excel using c# with Formatting Styles
- Q: Crystal report in c# .Net
- Q: Import excel into Sql server 2005 Table
- Q: READ, UPDATE & DELETE XML FILE USING X-PATH
- Q: Export Data from Listview to Excel
- Q: About GridView Data To Excel C#
- Q: Simple way to convert excel sheet to sql table
- Q: How to send data from c# file(.cs) to xslt file
- Q: How to Export and import data from sqlserver to excel sheet in vb.net
- Q: Migration of data from access to excel and vice versa
- Q: How to insert the data from excel to Database in .Net?
- Q: How can we create excel sheet in c# using data grid
- Q: DateTime Value Manipulation
- Q: create an array from a txt file
- Q: HowtoOepnandReadanExcelSpreadsheetinaListViewin.NET
- Q: How to fill data to excel
- Q: Reading Image from Excel file using C# .Net
- C# / CSharp Tutorial
- stackoverflow.com/questions
- General .NET Projects
- Sample .NET Projects with source code
- CSharpArticles
- PHPManual
- phpmanual/en/install.windows
- ProtoPage
Wednesday, September 8, 2010
C# Code: Arthimatic Calculation by Taking 3 Operands Using Properties Concept -III
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment