You are on page 1of 7

Abhinandan S

MDIform.cs
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 PartB_Blood
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void donorToolStripMenuItem_Click(object sender, EventArgs e)
{
new donor { MdiParent = this }.Show();
}
private void bloodGroupToolStripMenuItem_Click(object sender, EventArgs e)
{
new bloodGroup { MdiParent = this }.Show();
}
private void byGenderToolStripMenuItem_Click(object sender, EventArgs e)
{
new report { MdiParent = this }.Show();
}
private void byAgeWeightToolStripMenuItem_Click(object sender, EventArgs e)
{
new dispbyAge { MdiParent = this }.Show();
}
private void byBloodGroupToolStripMenuItem_Click(object sender, EventArgs e)
{
new dispByBgrp { MdiParent = this }.Show();
}
}
}
displayByBloodGrp.cs
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;
using MySql.Data;
using MySql.Data.MySqlClient;
using MySql;
namespace PartB_Blood
{

1RV14MCA01

Abhinandan S

1RV14MCA01

public partial class dispByBgrp : Form


{
MySqlConnection con;
MySqlCommand cmd;
string connection = "Server=localhost; Database=lab2; Uid=root; Pwd=mca;";
public dispByBgrp()
{
con = new MySqlConnection(connection);
InitializeComponent();
}
private void display_Click(object sender, EventArgs e)
{
try
{
cmd = con.CreateCommand();
con.Open();
MySqlDataAdapter ad = new MySqlDataAdapter("select * from donor where Bid='" + cbid.SelectedValue
+ "'", con);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
con.Close();
}
catch (Exception)
{
}
}
public void fillcomboBox()
{
con.Open();
MySqlDataAdapter ad = new MySqlDataAdapter("select * from BGroup", con);
DataTable dt = new DataTable("bid");
ad.Fill(dt);
cbid.DataSource = dt;
cbid.DisplayMember = "bgr";
cbid.ValueMember = "bid";
con.Close();
}
private void dispByBgrp_Load(object sender, EventArgs e)
{
fillcomboBox();
}
}
}
displayByAge.cs
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;
using MySql.Data;

Abhinandan S

1RV14MCA01

using MySql.Data.MySqlClient;
using MySql;
namespace PartB_Blood
{
public partial class dispbyAge : Form
{
MySqlConnection con;
MySqlCommand cmd;
string connection = "Server=localhost; Database=lab2; Uid=root; Pwd=mca;";
public dispbyAge()
{
con = new MySqlConnection(connection);
InitializeComponent();
}
private void display_Click(object sender, EventArgs e)
{
try
{
cmd = con.CreateCommand();
con.Open();
if (rmale.Checked)
{
MySqlDataAdapter ad = new MySqlDataAdapter("select *, year(CURDATE())-year(dob) as age from
donor where weight>45 and gender='male' and year(CURDATE())-year(dob)>18", con);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else
{
MySqlDataAdapter ad = new MySqlDataAdapter("select *, year(CURDATE())-year(dob) as age from
donor where weight>45 and gender='female' and year(CURDATE())-year(dob)>18", con);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
con.Close();
}
catch (Exception)
{
}
}
private void dispall_Click(object sender, EventArgs e)
{
try
{
cmd = con.CreateCommand();
con.Open();
MySqlDataAdapter ad = new MySqlDataAdapter("select *, year(CURDATE())-year(dob) as age from
donor ", con);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView2.DataSource = ds.Tables[0];
con.Close();
}
catch (Exception)

Abhinandan S
{
}
}
}
}
addBloodgrp.cs
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;
using MySql.Data;
using MySql.Data.MySqlClient;
using MySql;
namespace PartB_Blood
{
public partial class bloodGroup : Form
{
MySqlConnection con;
MySqlCommand cmd;
string connection = "Server=localhost; Database=lab2; Uid=root; Pwd=mca;";
public bloodGroup()
{
con = new MySqlConnection(connection);
InitializeComponent();
display();
}
private void save_Click(object sender, EventArgs e)
{
try
{
if (bgr.Text == "")
{
MessageBox.Show("Enter a BloodGroup");
}
else
{
cmd = con.CreateCommand();
con.Open();
cmd.CommandText = "insert into BGroup(Bgr) values(?bgr)";
cmd.Parameters.AddWithValue("bgr", bgr.Text);
cmd.ExecuteNonQuery();
display();
con.Close();
}
}
catch (Exception)
{
}
finally
{

1RV14MCA01

Abhinandan S

1RV14MCA01

bgr.Clear();
}
}
public void display()
{
MySqlDataAdapter ad = new MySqlDataAdapter("select * from BGroup", con);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
}
}
report.cs
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;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace PartB_Blood
{
public partial class report : Form
{
MySqlConnection con;
MySqlCommand cmd;
string connection = "Server=localhost; Database=lab2; Uid=root; Pwd=mca;";
public report()
{
con = new MySqlConnection(connection);
InitializeComponent();
}
private void Search_Click(object sender, EventArgs e)
{
try
{
cmd = con.CreateCommand();
con.Open();
if (rmale.Checked)
{
MySqlDataAdapter ad = new MySqlDataAdapter("select * from donor where gender='male'", con);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
else
{
MySqlDataAdapter ad = new MySqlDataAdapter("select * from donor where gender='female'", con);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];

Abhinandan S

1RV14MCA01

}
con.Close();
}
catch (Exception)
{
}
}
}
}
donor.cs
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;
using MySql.Data;
using MySql.Data.MySqlClient;
using MySql;
namespace PartB_Blood
{
public partial class donor : Form
{
MySqlConnection con;
MySqlCommand cmd;
string connection = "Server=localhost; Database=lab2; Uid=root; Pwd=mca;";
public donor()
{
con = new MySqlConnection(connection);
InitializeComponent();
display();
}
public void fillcomboBox()
{
con.Open();
MySqlDataAdapter ad = new MySqlDataAdapter("select * from BGroup", con);
DataTable dt = new DataTable("bid");
ad.Fill(dt);
cbid.DataSource = dt;
cbid.DisplayMember = "bgr";
cbid.ValueMember = "bid";
con.Close();
}
private void save_Click(object sender, EventArgs e)
{
try
{
if (did.Text == "" || dname.Text == "" || address.Text == "" || phno.Text == "" || dob.Text == "" ||
weight.Text == "" || cbid.Text == "")
{
MessageBox.Show("All Fields are mandatory");
}

Abhinandan S

1RV14MCA01

else
{
cmd = con.CreateCommand();
con.Open();
cmd.CommandText = "insert into donor(Did,Dname,address,phno,dob,gender,weight,Bid) values(?
Did,?Dname,?address,?phno,?dob,?gender,?weight,?bid)";
cmd.Parameters.AddWithValue("Did", did.Text);
cmd.Parameters.AddWithValue("Dname", dname.Text);
cmd.Parameters.AddWithValue("address", address.Text);
cmd.Parameters.AddWithValue("phno", phno.Text);
cmd.Parameters.AddWithValue("dob", dob.Value.Date);
if (male.Checked)
cmd.Parameters.AddWithValue("gender", "male");
else
cmd.Parameters.AddWithValue("gender", "female");
cmd.Parameters.AddWithValue("weight", weight.Text);
cmd.Parameters.AddWithValue("bid", cbid.SelectedValue);
cmd.ExecuteNonQuery();
display();
con.Close();
}
}
catch (Exception)
{
}
finally
{
did.Clear();
dname.Clear();
address.Clear();
phno.Clear();
weight.Clear();
}
}
public void display()
{
MySqlDataAdapter ad = new MySqlDataAdapter("select * from donor", con);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
private void donor_Load(object sender, EventArgs e)
{
fillcomboBox();
}
}
}

You might also like