EDN Admin
Well-known member
<span style="color:#333333; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; font-size:13px; line-height:16px
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<span style="font-style:inherit; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; color:#333333; font-size:13px; line-height:16px; padding:0px; margin:0px; border:0px initial initial Hi
everyone,<br/>
<br/>
Hope you can help me to solve this issue. <br/>
<br/>
Am getting this error when I try to run my application. NullReferenceException was unhandled: Object reference not set to an instance of an object.<br/>
<br/>
When I check the error is pointing to the following:
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<span style="font-style:inherit; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; color:#333333; font-size:13px; line-height:16px; padding:0px; margin:0px; border:0px initial initial <br/>
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial System.NullReferenceException was unhandled
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Message="Object reference not set to an instance of an object."
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Source="rough1"
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial StackTrace:
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at rough1.Form3.GetDataFromDataBase()
in C:UsersDeSaiDocumentsVisual Studio 2008Projectsrough1rough1Form3.cs:line 137
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at rough1.Form3..ctor() in C:UsersDeSaiDocumentsVisual
Studio 2008Projectsrough1rough1Form3.cs:line 64
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at rough1.Program.Main() in C:UsersDeSaiDocumentsVisual
Studio 2008Projectsrough1rough1Program.cs:line 18
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at System.AppDomain._nExecuteAssembly(Assembly
assembly, String[] args)
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at System.Threading.ThreadHelper.ThreadStart()
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial InnerException:
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial The code that I have is as follows:
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; using System.Data.SqlClient;
<span style="color:Blue; namespace rough1
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form3 : Form
{
List<Seat> list = <span style="color:Blue; new List<Seat>();
Button[] buttons = <span style="color:Blue; new Button[225];
<span style="color:Green; //int i = 0;
<span style="color:Blue; string connectionString = <span style="color:#A31515; "Data Source=DESAI-PC\SQLEXPRESS; Initial Catalog = RoughWork; Integrated Security = True;";
<span style="color:Blue; public Form3()
{
InitializeComponent();
<span style="color:Gray; ///<span style="color:Green; ////
<span style="color:Green; //Buttons (Seats) Creation
<span style="color:Gray; ///<span style="color:Green; ///
<span style="color:Green; //Button[] buttons = new Button[225];
<span style="color:Green; //list = new List<Seat>();
<span style="color:Green; //Constants 1:
<span style="color:Blue; char[] rows = <span style="color:#A31515; "ABCDEFGHIJKLMNO".ToCharArray();
<span style="color:Blue; int[] columns = Enumerable.Range(1, 15).ToArray();
<span style="color:Blue; int[] xy = <span style="color:Blue; new <span style="color:Blue; int[] { 0, 0 };
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < rows.Length; i++)
{
<span style="color:Blue; for (<span style="color:Blue; int j = 0; j < columns.Length; j++)
{
<span style="color:Green; // 1. add seat to a generic list<T>:
Seat s = <span style="color:Blue; new Seat();
s.Number = String.Concat(rows, columns[j]);
<span style="color:Green; //when creating seats set occupation on false (seat free)!
s.Occupied = <span style="color:Blue; false;
list.Add(s);
<span style="color:Green; // 2. create and position the button on form:
xy = PositioningSeat(j, i, xy[0], xy[1]);
buttons = <span style="color:Blue; new Button();
buttons.Name = String.Concat(rows, columns[j]);
buttons.Text = String.Concat(rows, columns[j]);
buttons.Size = <span style="color:Blue; new Size(35, 35);
buttons.Location = <span style="color:Blue; new Point(xy[0], xy[1]);
buttons.Click += <span style="color:Blue; new EventHandler(buttonSeats_Click);
buttons.BackColor = System.Drawing.Color.PowderBlue;
<span style="color:Green; //buttons.ForeColor = System.Drawing.Color.White;
<span style="color:Green; //buttons.FlatAppearance.BorderColor = System.Drawing.Color.Blue;
<span style="color:Green; //buttons.FlatAppearance.BorderSize = 0;
<span style="color:Green; //buttons.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
<span style="color:Blue; this.Controls.Add(buttons);
}
}
DataTable table = GetDataFromDataBase();
SetOccupiedSeats(table);
}
<span style="color:Blue; private <span style="color:Blue; int[] PositioningSeat(<span style="color:Blue; int column, <span style="color:Blue; int row, <span style="color:Blue; int x, <span style="color:Blue; int y)
{
<span style="color:Blue; if (column == 0 || column == 15)
{
x = 60; <span style="color:Green; // starting X position or reseting X to 1st column
<span style="color:Blue; if (row % 5 == 0)
{
y = y + 50; <span style="color:Green; //going to new sector of Y
}
<span style="color:Blue; else
{
y = y + 37; <span style="color:Green; // next seat for Y
}
}
<span style="color:Blue; else <span style="color:Blue; if (column % 5 == 0)
{
x = x + 70; <span style="color:Green; //going to new sector of X
}
<span style="color:Blue; else
{
x = x + 37; <span style="color:Green; // next seat for X
}
<span style="color:Blue; return <span style="color:Blue; new <span style="color:Blue; int[] { x, y };
}
<span style="color:Blue; private <span style="color:Blue; void buttonSeats_Click(<span style="color:Blue; object sender, EventArgs e)
{
Button seat = sender <span style="color:Blue; as Button;
Button selected = sender <span style="color:Blue; as Button;
<span style="color:Green; //MessageBox.Show(selected.Name);
<span style="color:Blue; if (list.Where(w => w.Number == seat.Text).Select(s => s.Occupied).Contains(<span style="color:Blue; true))
{
MessageBox.Show(<span style="color:#A31515; "Seat Number " + seat.Text + <span style="color:#A31515; " has already been taken!", <span style="color:#A31515; "Reservation Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
<span style="color:Blue; else
{
<span style="color:Blue; if (DialogResult.Yes == MessageBox.Show(<span style="color:#A31515; "Set number " + seat.Text + <span style="color:#A31515; " is free.nDo you want to reservate it?", <span style="color:#A31515; "New reservation", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
<span style="color:Green; //seat is being reserved...
list.Where(w => w.Number == seat.Text).Select(s => { s.Occupied = <span style="color:Blue; true; <span style="color:Blue; return s; }).ToList();
seat.BackColor = System.Drawing.Color.Red;
seat.BackColor = System.Drawing.Color.Red;
seat.FlatAppearance.BorderColor = System.Drawing.Color.Red;
seat.FlatAppearance.BorderSize = 0;
seat.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
MessageBox.Show(<span style="color:#A31515; "Reservation confirmed.nSeat number " + seat.Text + <span style="color:#A31515; " is now reserved.", <span style="color:#A31515; "Reservation confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
<span style="color:Blue; public <span style="color:Blue; class Seat
{
<span style="color:Blue; public <span style="color:Blue; string Number { <span style="color:Blue; get; <span style="color:Blue; set; }
<span style="color:Blue; public <span style="color:Blue; bool Occupied { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; private DataTable GetDataFromDataBase()
{
DataTable table = <span style="color:Blue; new DataTable();
<span style="color:Blue; using (SqlConnection cn = <span style="color:Blue; new SqlConnection(connectionString))
{
<span style="color:Blue; using (SqlDataAdapter da = <span style="color:Blue; new SqlDataAdapter())
{
da.SelectCommand.CommandText = <span style="color:#A31515; @"select * from SampleTable1";
da.SelectCommand.Connection = cn;
da.Fill(table);
}
}
<span style="color:Blue; return table;
}
<span style="color:Blue; private <span style="color:Blue; void SetOccupiedSeats(DataTable table)
{
<span style="color:Blue; foreach (DataRow row <span style="color:Blue; in table.Rows)
{
<span style="color:Blue; int seatNumber = <span style="color:Blue; int.Parse(row[<span style="color:#A31515; "SeatId"].ToString());
<span style="color:Blue; int seatOccupied = <span style="color:Blue; int.Parse(row[<span style="color:#A31515; "IsBooked"].ToString());
<span style="color:Blue; string seatNumbr = Convert.ToString(seatNumber);
<span style="color:Blue; if (seatOccupied == 1)
{
list.Where(w => w.Number == seatNumbr).Select(s => { s.Occupied = <span style="color:Blue; true; <span style="color:Blue; return s; }).ToList();
}
}
}
}
}
[/code]
<br/>
<br/>
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial <br/>
View the full article
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<span style="font-style:inherit; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; color:#333333; font-size:13px; line-height:16px; padding:0px; margin:0px; border:0px initial initial Hi
everyone,<br/>
<br/>
Hope you can help me to solve this issue. <br/>
<br/>
Am getting this error when I try to run my application. NullReferenceException was unhandled: Object reference not set to an instance of an object.<br/>
<br/>
When I check the error is pointing to the following:
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<span style="font-style:inherit; font-family:Segoe UI,Lucida Grande,Verdana,Arial,Helvetica,sans-serif; outline-width:0px; outline-style:initial; outline-color:initial; color:#333333; font-size:13px; line-height:16px; padding:0px; margin:0px; border:0px initial initial <br/>
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial System.NullReferenceException was unhandled
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Message="Object reference not set to an instance of an object."
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial Source="rough1"
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial StackTrace:
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at rough1.Form3.GetDataFromDataBase()
in C:UsersDeSaiDocumentsVisual Studio 2008Projectsrough1rough1Form3.cs:line 137
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at rough1.Form3..ctor() in C:UsersDeSaiDocumentsVisual
Studio 2008Projectsrough1rough1Form3.cs:line 64
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at rough1.Program.Main() in C:UsersDeSaiDocumentsVisual
Studio 2008Projectsrough1rough1Program.cs:line 18
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at System.AppDomain._nExecuteAssembly(Assembly
assembly, String[] args)
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial at System.Threading.ThreadHelper.ThreadStart()
<div style="font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial InnerException:
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial The code that I have is as follows:
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Collections.Generic;
<span style="color:Blue; using System.ComponentModel;
<span style="color:Blue; using System.Data;
<span style="color:Blue; using System.Drawing;
<span style="color:Blue; using System.Linq;
<span style="color:Blue; using System.Text;
<span style="color:Blue; using System.Windows.Forms;
<span style="color:Blue; using System.Data.SqlClient;
<span style="color:Blue; namespace rough1
{
<span style="color:Blue; public <span style="color:Blue; partial <span style="color:Blue; class Form3 : Form
{
List<Seat> list = <span style="color:Blue; new List<Seat>();
Button[] buttons = <span style="color:Blue; new Button[225];
<span style="color:Green; //int i = 0;
<span style="color:Blue; string connectionString = <span style="color:#A31515; "Data Source=DESAI-PC\SQLEXPRESS; Initial Catalog = RoughWork; Integrated Security = True;";
<span style="color:Blue; public Form3()
{
InitializeComponent();
<span style="color:Gray; ///<span style="color:Green; ////
<span style="color:Green; //Buttons (Seats) Creation
<span style="color:Gray; ///<span style="color:Green; ///
<span style="color:Green; //Button[] buttons = new Button[225];
<span style="color:Green; //list = new List<Seat>();
<span style="color:Green; //Constants 1:
<span style="color:Blue; char[] rows = <span style="color:#A31515; "ABCDEFGHIJKLMNO".ToCharArray();
<span style="color:Blue; int[] columns = Enumerable.Range(1, 15).ToArray();
<span style="color:Blue; int[] xy = <span style="color:Blue; new <span style="color:Blue; int[] { 0, 0 };
<span style="color:Blue; for (<span style="color:Blue; int i = 0; i < rows.Length; i++)
{
<span style="color:Blue; for (<span style="color:Blue; int j = 0; j < columns.Length; j++)
{
<span style="color:Green; // 1. add seat to a generic list<T>:
Seat s = <span style="color:Blue; new Seat();
s.Number = String.Concat(rows, columns[j]);
<span style="color:Green; //when creating seats set occupation on false (seat free)!
s.Occupied = <span style="color:Blue; false;
list.Add(s);
<span style="color:Green; // 2. create and position the button on form:
xy = PositioningSeat(j, i, xy[0], xy[1]);
buttons = <span style="color:Blue; new Button();
buttons.Name = String.Concat(rows, columns[j]);
buttons.Text = String.Concat(rows, columns[j]);
buttons.Size = <span style="color:Blue; new Size(35, 35);
buttons.Location = <span style="color:Blue; new Point(xy[0], xy[1]);
buttons.Click += <span style="color:Blue; new EventHandler(buttonSeats_Click);
buttons.BackColor = System.Drawing.Color.PowderBlue;
<span style="color:Green; //buttons.ForeColor = System.Drawing.Color.White;
<span style="color:Green; //buttons.FlatAppearance.BorderColor = System.Drawing.Color.Blue;
<span style="color:Green; //buttons.FlatAppearance.BorderSize = 0;
<span style="color:Green; //buttons.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
<span style="color:Blue; this.Controls.Add(buttons);
}
}
DataTable table = GetDataFromDataBase();
SetOccupiedSeats(table);
}
<span style="color:Blue; private <span style="color:Blue; int[] PositioningSeat(<span style="color:Blue; int column, <span style="color:Blue; int row, <span style="color:Blue; int x, <span style="color:Blue; int y)
{
<span style="color:Blue; if (column == 0 || column == 15)
{
x = 60; <span style="color:Green; // starting X position or reseting X to 1st column
<span style="color:Blue; if (row % 5 == 0)
{
y = y + 50; <span style="color:Green; //going to new sector of Y
}
<span style="color:Blue; else
{
y = y + 37; <span style="color:Green; // next seat for Y
}
}
<span style="color:Blue; else <span style="color:Blue; if (column % 5 == 0)
{
x = x + 70; <span style="color:Green; //going to new sector of X
}
<span style="color:Blue; else
{
x = x + 37; <span style="color:Green; // next seat for X
}
<span style="color:Blue; return <span style="color:Blue; new <span style="color:Blue; int[] { x, y };
}
<span style="color:Blue; private <span style="color:Blue; void buttonSeats_Click(<span style="color:Blue; object sender, EventArgs e)
{
Button seat = sender <span style="color:Blue; as Button;
Button selected = sender <span style="color:Blue; as Button;
<span style="color:Green; //MessageBox.Show(selected.Name);
<span style="color:Blue; if (list.Where(w => w.Number == seat.Text).Select(s => s.Occupied).Contains(<span style="color:Blue; true))
{
MessageBox.Show(<span style="color:#A31515; "Seat Number " + seat.Text + <span style="color:#A31515; " has already been taken!", <span style="color:#A31515; "Reservation Attention", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
<span style="color:Blue; else
{
<span style="color:Blue; if (DialogResult.Yes == MessageBox.Show(<span style="color:#A31515; "Set number " + seat.Text + <span style="color:#A31515; " is free.nDo you want to reservate it?", <span style="color:#A31515; "New reservation", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
<span style="color:Green; //seat is being reserved...
list.Where(w => w.Number == seat.Text).Select(s => { s.Occupied = <span style="color:Blue; true; <span style="color:Blue; return s; }).ToList();
seat.BackColor = System.Drawing.Color.Red;
seat.BackColor = System.Drawing.Color.Red;
seat.FlatAppearance.BorderColor = System.Drawing.Color.Red;
seat.FlatAppearance.BorderSize = 0;
seat.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
MessageBox.Show(<span style="color:#A31515; "Reservation confirmed.nSeat number " + seat.Text + <span style="color:#A31515; " is now reserved.", <span style="color:#A31515; "Reservation confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
<span style="color:Blue; public <span style="color:Blue; class Seat
{
<span style="color:Blue; public <span style="color:Blue; string Number { <span style="color:Blue; get; <span style="color:Blue; set; }
<span style="color:Blue; public <span style="color:Blue; bool Occupied { <span style="color:Blue; get; <span style="color:Blue; set; }
}
<span style="color:Blue; private DataTable GetDataFromDataBase()
{
DataTable table = <span style="color:Blue; new DataTable();
<span style="color:Blue; using (SqlConnection cn = <span style="color:Blue; new SqlConnection(connectionString))
{
<span style="color:Blue; using (SqlDataAdapter da = <span style="color:Blue; new SqlDataAdapter())
{
da.SelectCommand.CommandText = <span style="color:#A31515; @"select * from SampleTable1";
da.SelectCommand.Connection = cn;
da.Fill(table);
}
}
<span style="color:Blue; return table;
}
<span style="color:Blue; private <span style="color:Blue; void SetOccupiedSeats(DataTable table)
{
<span style="color:Blue; foreach (DataRow row <span style="color:Blue; in table.Rows)
{
<span style="color:Blue; int seatNumber = <span style="color:Blue; int.Parse(row[<span style="color:#A31515; "SeatId"].ToString());
<span style="color:Blue; int seatOccupied = <span style="color:Blue; int.Parse(row[<span style="color:#A31515; "IsBooked"].ToString());
<span style="color:Blue; string seatNumbr = Convert.ToString(seatNumber);
<span style="color:Blue; if (seatOccupied == 1)
{
list.Where(w => w.Number == seatNumbr).Select(s => { s.Occupied = <span style="color:Blue; true; <span style="color:Blue; return s; }).ToList();
}
}
}
}
}
[/code]
<br/>
<br/>
<strong style="font-weight:bold; font-style:inherit; font-family:inherit; outline-width:0px; outline-style:initial; outline-color:initial; padding:0px; margin:0px; border:0px initial initial <br/>
View the full article