using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CarsRUS
{
public partial class Cars : Form
{
private SqlConnection conn;
private SqlDataAdapter daAddresses;
private DataSet dsAddresses;
private DataGrid dgAddresses;
private const string tableName = "CarRUS";
public class Customer
{
public Customer(string CustomerID, string Forename, string Surname, string Address, string PostCode)
{
this.customerID = CustomerID;
this.forename = Forename;
this.surname = Surname;
this.address = Address;
this.postcode = PostCode;
}
public string customerID;
public string forename;
public string surname;
public string address;
public string postcode;
}
//button for new customer
private void button1_Click(object sender, EventArgs e)
{
Customer c = new Customer(textBox1.Text, textBox2.Text, textBox5.Text, textBox6.Text, textBox9.Text);
customerQueue.Enqueue(c);
fillListBox(customerQueue);
textBox1.Text = "";//text box 1 will show the value that the user types in the customer id text box
textBox2.Text = "";//text box 2 will show the value that the user types in the forename text box
textBox5.Text = "";//text box 5 will show the value that the user types in the surname text box
textBox6.Text = "";//text box 6 will show the value that the user types in the address text box
textBox9.Text = "";//text box 9 will show the value that the user types in the postcode text box
textBox10.Text = "";//text box 10 will show the value that the user types in the telno text box
}
private void fillListBox(Queue<Customer> customers)//fill the listbox of the customer details
{
IEnumerator<Customer> myEnumerator = customerQueue.GetEnumerator();
listBox1.Items.Add("----Start of Customer Booking----");
//display the message above to show the start of the queue
while (myEnumerator.MoveNext())
{
listBox1.Items.Add(myEnumerator.Current.customerID + " " + myEnumerator.Current.forename + " " + myEnumerator.Current.surname + " " + myEnumerator.Current.address + " " + myEnumerator.Current.postcode);
}//list the details of the customer by customer id and then forename followed by the surname and then the address and then the postcode
}
private void Cars_Load(object sender, EventArgs e)
{
}
//Button to quit program
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
Queue<Customer> customerQueue = new Queue<Customer>();
public Cars()
{
InitializeComponent();
// fill dataset
Initdata();
// set up datagrid
dgAddresses = new DataGrid();
dgAddresses.Location = new Point(5, 5);
dgAddresses.Size = new Size(500, 500);
dgAddresses.DataSource = null;
dgAddresses.DataMember = null;
// create update button
Button btnUpdate = new Button();
btnUpdate.Text = "Update";
btnUpdate.Location = new Point(600, 150);
btnUpdate.Click += new EventHandler(btnUpdateClicked);
// make sure controls appear on form
Controls.AddRange(new Control[] { dgAddresses, btnUpdate });
}
// set up ADO.NET objects
public void Initdata()
{
try
{
conn = new SqlConnection(
"Data Source=.\\SQLEXPRESS;AttachDbFilename=G:\\CarRUS.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
}
catch (System.Exception ex)
{
MessageBox.Show("Exception" + ex.ToString());
}
// 1. instantiate a new DataSet
dsAddresses = new DataSet();
// 2. init SqlDataAdapter with select command and connection
daAddresses = new SqlDataAdapter("select CustomerID, Forename, Surname, Address, PostCod, TelNo from CarRUS", conn);
// 3. fill in insert, update, and delete commands
SqlCommandBuilder cmdBldr = new SqlCommandBuilder(daAddresses);
// 4. fill the dataset
//daAddresses.Fill(dsAddresses, tableName);
}
// Update button was clicked
public void btnUpdateClicked(object sender, EventArgs e)
{
// write changes back to DataBase
daAddresses.Update(dsAddresses, tableName);
}
private void button2_Click(object sender, EventArgs e)
{
}
private void GridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}//end
wiselka 0 Newbie Poster
DdoubleD 315 Posting Shark
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
DdoubleD 315 Posting Shark
sknake 1,622 Senior Poster Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.