0% found this document useful (0 votes)
3 views

shruti@249-Assignment2

The document outlines two C# WinForms assignments focused on creating applications that interact with an Oracle database. The first assignment involves developing a registration form with CRUD operations, while the second requires a user preferences application that allows file selection, font, and color customization. Both applications include detailed code snippets for establishing database connections and executing SQL commands for data manipulation.

Uploaded by

dogipab706
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

shruti@249-Assignment2

The document outlines two C# WinForms assignments focused on creating applications that interact with an Oracle database. The first assignment involves developing a registration form with CRUD operations, while the second requires a user preferences application that allows file selection, font, and color customization. Both applications include detailed code snippets for establishing database connections and executing SQL commands for data manipulation.

Uploaded by

dogipab706
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Name: vora shruti

Rollno : 249
Semester: 4
Division : D

C#.net Assignment-2

Question 1:-
Create a C# Winforms to create Registration form, stored in an
oracle database and perform CRUD
operation for the same.
Fields are:
Id, Name
Profile Image(OpenFileDialog)
Gender(Radio)
Country
State
Select Favorite color(ColorDialog)
Hobby
Additionally, you can add the field and controls by your choice
with proper UI design
Output
Code
using Oracle.ManagedDataAccess.Client;

using System.Data;

using System;

namespace question1

public partial class Form1 : Form

string orgcon = "User Id=SYSTEM;Password=vora;Data Source=localhost:1521;";

public Form1()

InitializeComponent();

private void connectionButton_Click(object sender, EventArgs e)

OracleConnection con1 = new OracleConnection(orgcon);

try

con1.Open();

MessageBox.Show("Connection estabilished successfully");

catch (Exception ex)

MessageBox.Show("Error : " + ex.Message);

}
}

private void displayButton_Click(object sender, EventArgs e)

string squery = "select * from student";

OracleDataAdapter dataAdapter = new OracleDataAdapter(squery, orgcon);

DataTable dataTable = new DataTable();

dataAdapter.Fill(dataTable);

dataGridView1.DataSource = dataTable;

private void insertButton_Click(object sender, EventArgs e)

string id = textBoxID.Text;

string name = textBoxName.Text;

string filepath = textBoxPath.Text;

string color = label8.BackColor.ToString();

string gender;

bool checked1 = radioButton1.Checked;

bool checked2 = radioButton2.Checked;

if (checked1)

gender = radioButton1.Text;

else

gender = radioButton2.Text;

string hobby;

if (checkBox1.Checked)
{

hobby = checkBox1.Text;

else if (checkBox2.Checked)

hobby = checkBox2.Text;

else if (checkBox3.Checked)

hobby = checkBox3.Text;

else

hobby = checkBox4.Text;

string country = (string)comboBox1.SelectedItem;

string state = (string)comboBox2.SelectedItem;

OracleConnection con2 = new OracleConnection(orgcon);

con2.Open();

string iquery = $@"INSERT INTO


student(id,name,filepath,gender,country,state,color,hobby)
VALUES('{id}','{name}','{filepath}','{gender}','{country}','{state}','{color}','{hobby}')";

OracleCommand cmd = new OracleCommand(iquery, con2);

cmd.ExecuteNonQuery();

con2.Close();

MessageBox.Show("Data inserted successfully");


loaddata();

private void label1_Click(object sender, EventArgs e)

OpenFileDialog dlg = new OpenFileDialog();

dlg.Title = "Open image";

dlg.Filter = "Image Files (*.jpg;*.jpeg;*.png)|*.jpg;*.jpeg;*.png";

if (dlg.ShowDialog() == DialogResult.OK)

pictureBox1.Image = new Bitmap(dlg.FileName);

textBoxPath.Text = dlg.FileName;

private void label8_Click(object sender, EventArgs e)

ColorDialog cd = new ColorDialog();

if (cd.ShowDialog() == DialogResult.OK)

label8.BackColor = cd.Color;

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

ArrayList countrylist = new ArrayList { comboBox1.Items };


string country = comboBox1.SelectedText;

ArrayList statelist = new ArrayList();

statelist.Clear();

if (comboBox1.SelectedItem.ToString() == "India")

statelist.AddRange(new string[] { "Maharashtra", "Gujarat", "Rajasthan", "Madhya


Pradesh" });

else if (comboBox1.SelectedItem.ToString() == "USA")

statelist.AddRange(new string[] { "Washington DC", "Texas", "Alaska", "California"


});

else

statelist.AddRange(new string[] { "London", "Cornwall", "Surrey", "Devon" });

comboBox2.DataSource = new ArrayList(statelist);

private void deleteButton_Click(object sender, EventArgs e)

OracleConnection con4 = new OracleConnection(orgcon);

con4.Open();

string id = textBoxID.Text;

string dquery = @"delete from student where id = :id";

using (OracleCommand cmd = new OracleCommand(dquery, con4))

{
cmd.Parameters.Add(":id", textBoxID.Text);

int d = cmd.ExecuteNonQuery();

if (d > 0)

MessageBox.Show("Record deleted successfully");

loaddata();

else

MessageBox.Show("No data found");

private void loaddata()

string squery = "select * from student";

OracleDataAdapter dataAdapter = new OracleDataAdapter(squery, orgcon);

DataTable dataTable = new DataTable();

dataAdapter.Fill(dataTable);

dataGridView1.DataSource = dataTable;

private void updateButton_Click(object sender, EventArgs e)

string uquery = @"UPDATE student SET name = :name WHERE id = :id";

using (OracleConnection con = new OracleConnection(orgcon))

using(OracleCommand cmd = new OracleCommand(uquery,con))


{

cmd.Parameters.Add(":name", textBoxName.Text);

cmd.Parameters.Add(":id", textBoxID.Text);

con.Open();

int ra = cmd.ExecuteNonQuery();

con.Close();

if (ra > 0)

MessageBox.Show("Record updated successfully");

else

MessageBox.Show("No record found with the given ID");

loaddata();

}
Question 2:-
Create a WinForms application where users can select a file using
OpenFileDialog,
choose a font using FontDialog, and pick a color using ColorDialog. These
preferences should

be stored in an Oracle Database and reloaded when the application starts.


Table:
UserPreferences:
UserID PRIMARY KEY,
FilePath,

FontName,
FontSize,
FontStyle,
ColorCode

Design a WinForms UI with the following controls:

● Button (btnOpenFile) → Opens an OpenFileDialog to select a file.


● Button (btnChangeFont) → Opens a FontDialog to select a font.
● Button (btnChangeColor) → Opens a ColorDialog to select a color.
● Label (lblPreview) → Displays the selected font and color.
● Button (btnSave) → Saves the selected values to the database.

● Button (btnLoad) → Loads the saved preferences from the database


output
using Oracle.ManagedDataAccess.Client;

using System.Data;

namespace question2

public partial class Form1 : Form

string orgcon = "User Id=system;Password=vora;Data Source=localhost:1521";

public Form1()

InitializeComponent();

OracleConnection con = new OracleConnection(orgcon);

con.Open();

private void insertButton_Click(object sender, EventArgs e)

string userid = textBox1.Text;

string filepath = textBox2.Text;

string fontname = label3.Font.Name;

var fontsize = label3.Font.Size;

string fontstyle = label3.Font.Style.ToString();

string color = label4.BackColor.ToArgb().ToString();

OracleConnection con1 = new OracleConnection(orgcon);

con1.Open();
string iquery = $@"insert into
prefer(userid,filepath,fontname,fontsize,fontstyle,color)
values('{userid}','{filepath}','{fontname}','{fontsize}','{fontstyle}',{color})";

using (OracleCommand cmd = new OracleCommand(iquery, con1))

cmd.ExecuteNonQuery();

con1.Close();

private void label2_Click(object sender, EventArgs e)

OpenFileDialog dlg = new OpenFileDialog();

dlg.Title = "Open image";

dlg.Filter = "Image Files (*.jpg;*.jpeg;*.png)|*.JPG;*.JPEG;*.PNG";

if (dlg.ShowDialog() == DialogResult.OK)

pictureBox1.Image = new Bitmap(dlg.FileName);

textBox2.Text = dlg.FileName;

private void label3_Click(object sender, EventArgs e)

FontDialog fontDialog = new FontDialog();

if (fontDialog.ShowDialog() == DialogResult.OK)

label3.Font = fontDialog.Font;

}
}

private void label4_Click(object sender, EventArgs e)

ColorDialog cd = new ColorDialog();

if (cd.ShowDialog() == DialogResult.OK)

label4.BackColor = cd.Color;

private void connectionButton_Click(object sender, EventArgs e)

OracleConnection con = new OracleConnection(orgcon);

con.Open();

string squery = "select * from prefer";

OracleDataAdapter dataAdapter = new OracleDataAdapter(squery, orgcon);

DataTable dataTable = new DataTable();

dataAdapter.Fill(dataTable);

dataGridView1.DataSource = dataTable;

private void displayButton_Click(object sender, EventArgs e)

string squery = "select * from prefer";

OracleDataAdapter dataAdapter = new OracleDataAdapter(squery, orgcon);

DataTable dataTable = new DataTable();


dataAdapter.Fill(dataTable);

dataGridView1.DataSource = dataTable;

You might also like