Sunday, 5 January 2014

Continuous Fractions in C# Console Application

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
   
    {
        static void Main(string[] args)
        {
            int a, b, i = 0, m, d, j, si;
            int[] ar = new int[10];
            Console.WriteLine("ENTER THE dividend");
            a = int.Parse(Console.ReadLine());
            Console.WriteLine("ENTER THE divisor");
            b = int.Parse(Console.ReadLine());
            try
            {
                while (a > b)
                {
                    d = a / b;
                    ar[i] = d;
                    i++;
                    m = a % b;
                    a = b;
                    b = m;
                }
            }
            catch (Exception ee)
            {
            }           
            si = ar.Length;           
                for (j = 0; j < si; j++)
                {
                    Console.WriteLine("{0} +  1", ar[j]);
                    Console.WriteLine("   ________");
                }
                Console.WriteLine("   1");
           
        }
    }
}

Program Analyser in Asp.net

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    int a=0,i=0;
    protected void Page_Load(object sender, EventArgs e)
    {
        ten:
        {
            Response.Write("10->");
             a++;
             i++;
        }
    twenty:
        {
            Response.Write("20->");
            i++;
            if (a == 5)
            {
                goto sixty;
            }
        }
        thirty:
        {           
            Response.Write("30->");
            i++;
             a=a+2;
        }
        fourty:
        {
            Response.Write("40->");
            i++;
        }
        fifty:
        {
            Response.Write("50->");
            i++;
            goto twenty;
        }
        sixty:
        {
            Response.Write("60");
            i++;
        }
        Response.Write("<br>");
        Response.Write(i);
    }
}

Tuesday, 27 November 2012

Student Detail using Database in Windows Application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace windatabase
{
public partial class Form1 : Form
{
OleDbConnection dc = new OleDbConnection();
OleDbCommand dcmd = new OleDbCommand();
OleDbDataReader dr;


public Form1()
{
InitializeComponent();

}

private void clear_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}

private void Form1_Load(object sender, EventArgs e)
{

dc.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" + "Data Source=E:\\cla.mdb";
dc.Open();
dcmd.Connection = dc;


}

private void save_Click(object sender, EventArgs e)
{
//dataGridView1.Columns.




string name, clas;
int ID=40, age;
name = textBox1.Text;
clas = textBox2.Text;
age = Convert.ToInt16( textBox3.Text);

dcmd.CommandText = "INSERT INTO cla VALUES('"+ID+"','" + name + "','" + clas + "'," +age + ")";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("recordsaved");
}

private void delete_Click(object sender, EventArgs e)
{
int ag;
ag = Convert.ToInt16(textBox4.Text);
dcmd.CommandText = "DELETE * FROM cla WHERE age=" + ag + "";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("Record Deleted");

}

private void search_Click(object sender, EventArgs e)
{
int vv;
vv = Convert.ToInt16(textBox4.Text);
dcmd.CommandText = "SELECT * FROM cla WHERE age=" + vv + "";
dr = dcmd.ExecuteReader();
dr.Read();
string name = dr.GetString(1);
string clas = dr.GetString(2);
int age = dr.GetInt16(3);
textBox1.Text = name;
textBox2.Text = clas;
textBox3.Text = age.ToString();

dr.Close();
}
}
}

Program using List box

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace usinglistbox
{
public partial class Form1 : Form
{
int m1, m2, tot;
public Form1()
{
InitializeComponent();
}

private void clear_Click(object sender, EventArgs e)
{
textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
textBox4.Text="";
textBox5.Text = "";

}

private void add_Click(object sender, EventArgs e)
{
m1 = int.Parse(textBox4.Text);
m2 = int.Parse(textBox5.Text);
tot = m1 + m2;

listBox1.Items.Add(textBox1.Text);
listBox2.Items.Add(textBox2.Text);
listBox3.Items.Add(textBox3.Text);
listBox4.Items.Add(textBox4.Text);
listBox5.Items.Add(textBox5.Text);
listBox6.Items.Add(tot);
}

private void remove_Click(object sender, EventArgs e)
{
int x;
x = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(x);
listBox2.Items.RemoveAt(x);
listBox3.Items.RemoveAt(x);
listBox4.Items.RemoveAt(x);
listBox5.Items.RemoveAt(x);
listBox6.Items.RemoveAt(x);


}


}
}

Blood Bank Using Databse in Windoes Application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace examblood
{
public partial class Form1 : Form
{
int i = -1;
OleDbConnection con = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
OleDbDataReader dr;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
con.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=E:\\blood1.mdb";
con.Open();
cmd.CommandText = "select bgroup from blood1";
cmd.Connection = con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr.GetString(0));

}
//dr.Close();
con.Close();
/* con.Open();
cmd.CommandText = "select * from blood1";
cmd.Connection = con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = dr.GetInt16(0);
dataGridView1.Rows[i].Cells[1].Value = dr.GetString(1);
dataGridView1.Rows[i].Cells[2].Value = dr.GetInt16(2);
dataGridView1.Rows[i].Cells[3].Value = dr.GetString(3);
}
con.Close();*/
}

private void button1_Click(object sender, EventArgs e)
{

con.Open();

cmd.CommandText = "insert into blood1 values('" + textBox4.Text + "','" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
cmd.Connection = con;
dr = cmd.ExecuteReader();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
con.Close();

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
// cmd.CommandText
string s = comboBox1.SelectedItem.ToString();
textBox5.Text = s.ToString();
con.Open();
cmd.CommandText = "select * from blood1 where bgroup='"+s+"'";
cmd.Connection = con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = dr.GetInt16(0);
dataGridView1.Rows[i].Cells[1].Value = dr.GetString(1);
dataGridView1.Rows[i].Cells[2].Value = dr.GetInt16(2);
dataGridView1.Rows[i].Cells[3].Value = dr.GetString(3);
}
con.Close();
}

private void textBox5_TextChanged(object sender, EventArgs e)
{

}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
textBox5.Text = dataGridView1.SelectedCells[0].Value.ToString();

}

private void groupBox1_Enter(object sender, EventArgs e)
{

}
}
}

Bank Transaction Using Database in Windows Application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace bankdetails
{
public partial class Form1 : Form
{
int acc, amt,age,i=-1;
string name, branch, z;
OleDbConnection dc = new OleDbConnection();
OleDbCommand dcmd = new OleDbCommand();
OleDbDataReader dr;
public Form1()
{
InitializeComponent();
}

private void CLEAR_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
errorProvider1.Clear();

}

private void Form1_Load(object sender, EventArgs e)
{
dc.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" + "Data Source=E:\\bank.mdb";
dcmd.Connection = dc;
dc.Open();
dcmd.CommandText="SELECT acc FROM bank";
dr = dcmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr.GetInt16(0));
}
dr.Close();
}

private void SAVE_Click(object sender, EventArgs e)
{
if (textBox3.Text == "")
{
errorProvider1.SetError(textBox3, "fill it");
}
else
{

acc = Convert.ToInt16(textBox1.Text);
name = textBox2.Text;
age = Convert.ToInt16(textBox3.Text);
branch = textBox4.Text;
amt = Convert.ToInt16(textBox5.Text);
dcmd.CommandText = "INSERT INTO bank VALUES(" + acc + ",'" + name + "'," + age + ",'" + branch + "'," + amt + ")";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("Record Inserted Successfully");
}
}

private void DELETE_Click(object sender, EventArgs e)
{
z = comboBox1.SelectedItem.ToString();
dcmd.CommandText = "DELETE * FROM bank WHERE acc=" + z + "";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("Record Deleted");
}

private void UPDATE_Click(object sender, EventArgs e)
{
z = comboBox1.SelectedItem.ToString();
//dr.Read();
acc = Convert.ToInt16(textBox1.Text);
name = textBox2.Text;
age = Convert.ToInt16(textBox3.Text);
branch = textBox4.Text;
amt =Convert.ToInt16(textBox5.Text);
dcmd.CommandText = "UPDATE bank SET acc='" + acc + "',name='" + name + "',age=" + age + ",branch='" + branch + "',amt=" + amt + " WHERE acc=" + z + "";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("RECORD UPDATED SUCESSFULLY");
}

private void SEARCH_Click(object sender, EventArgs e)
{
z = comboBox1.SelectedItem.ToString();
dcmd.CommandText = "SELECT * FROM bank WHERE acc=" + z + "";
dr = dcmd.ExecuteReader();
dr.Read();
acc = dr.GetInt16(0);
name = dr.GetString(1);
age = dr.GetInt16(2);
branch = dr.GetString(3);
amt = dr.GetInt16(4);
textBox1.Text = acc.ToString();
textBox2.Text = name;
textBox3.Text = age.ToString();
textBox4.Text = branch;
textBox5.Text = amt.ToString();
dr.Close();


}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string s = comboBox1.SelectedItem.ToString();
dcmd.CommandText = "select * from bank where acc=" + s + "";
dr = dcmd.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = dr.GetInt16(0);
dataGridView1.Rows[i].Cells[1].Value = dr.GetString(1);
dataGridView1.Rows[i].Cells[2].Value = dr.GetInt16(2);
dataGridView1.Rows[i].Cells[3].Value = dr.GetString(3);
dataGridView1.Rows[i].Cells[4].Value = dr.GetInt16(4);
}
dr.Close();

}
}
}

Transpose Matrix

using System;
using System.Collections.Generic;
using System.Text;

namespace transpose_matrix
{
class mat
{
int[,] a = new int[20, 20];
int i,j,n,m;
public void get()
{
Console.WriteLine("TRANSPOSE MATRIX");
Console.WriteLine("*****************");
Console.WriteLine("Enter the Row Value");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Column Value");
m = int.Parse(Console.ReadLine());
Console.WriteLine("Enter The Elements One by One");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
a[i, j] = new int();
a[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("Given Matrix");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
Console.Write("{0}\t", a[i, j]);
}
Console.WriteLine();
}
}
public void cal()
{
Console.WriteLine("TRANSPOSE MATRIX");
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
Console.Write("{0}\t", a[j, i]);
}
Console.WriteLine();
}
}
}

class transpose
{
static void Main(string[] args)
{
mat q = new mat();
q.get();
q.cal();

}
}
}