private void btnCreateBar_Click(object sender, EventArgs e) { barTable = new BarTable(); int startLeft = pnlRoom.Left; int startTop = pnlRoom.Top; barTable.TableNumber = 1; barTable.TablePositionX = startLeft; barTable.TablePositionY = startTop; Button button = new StayInsideButton(); button.Cursor = Cursors.Hand; button.Height = 30; button.Width = 200; button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = 0; button.BackColor = Color.Cyan; button.Tag = barTable; button.Text = "Bar"; button.Location = new Point(startLeft, startTop); pnlRoom.Controls.Add(button); button.MouseDown += button_MouseDown; button.MouseUp += button_MouseUp; button.MouseMove += button_MouseMove; btnSaveLayout.Enabled = true; lblMessage.Text = "Bar was successfully added."; btnCreateBar.Enabled = false; }
public void LoadBarTable() { BarTable oBarTable = BarTableDA.GetBarTableLayout(); if (oBarTable != null) { Button button = new StayInsideButton(); button.Cursor = Cursors.Hand; button.Height = 30; button.Width = 200; button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = 0; button.BackColor = Color.Cyan; button.Tag = oBarTable; button.Text = "Bar"; button.Location = new Point(oBarTable.TablePositionX, oBarTable.TablePositionY); pnlRoom.Controls.Add(button); } }
public static BarTable GetBarTableLayout() { SqlConnection connection = RestaurantConnection.GetConnection(); SqlCommand command = new SqlCommand(); SqlDataReader reader = null; BarTable barTable = null; command.CommandText = "Select * FROM barTable"; command.CommandType = CommandType.Text; command.Connection = connection; try { connection.Open(); reader = command.ExecuteReader(); while (reader.Read()) { barTable = new BarTable(); barTable.TableNumber = (int)reader["tableNumber"]; barTable.TablePositionX = (int)reader["tablePositionX"]; barTable.TablePositionY = (int)reader["tablePositionY"]; } } catch (SqlException ex) { MessageBox.Show(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } return(barTable); }
public static void SaveBarTableLayout(BarTable barTable) { SqlConnection connection = RestaurantConnection.GetConnection(); // Select statement to see if bar table exists. string selectStatement = "SELECT COUNT(*) " + "FROM barTable"; SqlCommand selectCommand = new SqlCommand(selectStatement, connection); //selectCommand.Parameters.AddWithValue("@tableNumber", SqlDbType.Int); // Insert Statement. string insertStatement = "INSERT INTO barTable " + "(tableNumber, tablePositionX, tablePositionY) " + "VALUES (@tableNumber, @tablePositionX, @tablePositionY)"; SqlCommand insertCommand = new SqlCommand(insertStatement, connection); insertCommand.Parameters.AddWithValue("@tableNumber", SqlDbType.Int); insertCommand.Parameters.AddWithValue("@tablePositionX", SqlDbType.Int); insertCommand.Parameters.AddWithValue("@tablePositionY", SqlDbType.Int); // Update Statement. string updateStatement = "UPDATE barTable " //+ "SET tableNumber = @tableNumber, " + "SET tablePositionX = @tablePositionX, " + "tablePositionY = @tablePositionY " + "WHERE tableNumber = @tableNumber"; SqlCommand updateCommand = new SqlCommand(updateStatement, connection); updateCommand.Parameters.AddWithValue("@tableNumber", SqlDbType.Int); //updateCommand.Parameters.AddWithValue("@numberOfSeats", SqlDbType.Int); updateCommand.Parameters.AddWithValue("@tablePositionX", SqlDbType.Int); updateCommand.Parameters.AddWithValue("@tablePositionY", SqlDbType.Int); //updateCommand.Parameters.AddWithValue("@movedTableNumber", SqlDbType.Int); connection.Open(); try { // Execute the select statement to see if the row exists. //selectCommand.Parameters["@tableNumber"].Value = barTable.TableNumber; int rowCount = (int)selectCommand.ExecuteScalar(); if (rowCount > 0) { // Update the row. updateCommand.Parameters["@tableNumber"].Value = barTable.TableNumber; //updateCommand.Parameters["@numberOfSeats"].Value = table.NumberOfSeats; updateCommand.Parameters["@tablePositionX"].Value = barTable.TablePositionX; updateCommand.Parameters["@tablePositionY"].Value = barTable.TablePositionY; //updateCommand.Parameters["@movedTableNumber"].Value = table.TableNumber; updateCommand.ExecuteNonQuery(); } else { // Insert the row. insertCommand.Parameters["@tableNumber"].Value = barTable.TableNumber; insertCommand.Parameters["@tablePositionX"].Value = barTable.TablePositionX; insertCommand.Parameters["@tablePositionY"].Value = barTable.TablePositionY; insertCommand.ExecuteNonQuery(); } } catch (SqlException ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } }
public void LoadTables() { // Load Tables tables = TableDA.GetTableLayout(); if (!(Utility.IsNullOrEmpty(tables))) { foreach (Table eachTable in tables) { table = eachTable; RoundButton button = new RoundButton(); button.Cursor = Cursors.Hand; button.Height = 50; button.Width = 50; button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = 0; button.BackColor = Color.Cyan; button.Tag = table; button.Text = Convert.ToString(table.TableNumber) + "\n" + Convert.ToString(table.NumberOfSeats) + " seats"; button.Location = new Point(table.TablePositionX, table.TablePositionY); pnlRoom.Controls.Add(button); button.MouseDown += button_MouseDown; button.MouseUp += button_MouseUp; button.MouseMove += button_MouseMove; } txtTableNumber.Text = Convert.ToString(Table.TotalTables); } //Load BarSeats. barSeats = BarSeatDA.GetBarSeatLayout(); if (!(Utility.IsNullOrEmpty(barSeats))) { foreach (BarSeat eachBarSeat in barSeats) { barSeat = eachBarSeat; RoundButton button = new RoundButton(); button.Cursor = Cursors.Hand; button.Height = 30; button.Width = 30; button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = 0; button.BackColor = Color.Cyan; button.Tag = barSeat; button.Text = "B" + Convert.ToString(barSeat.TableNumber); button.Location = new Point(barSeat.TablePositionX, barSeat.TablePositionY); pnlRoom.Controls.Add(button); button.MouseDown += button_MouseDown; button.MouseUp += button_MouseUp; button.MouseMove += button_MouseMove; } txtBarSeatNumber.Text = Convert.ToString(BarSeat.TotalTables); } // Load BarTable. barTable = BarTableDA.GetBarTableLayout(); if (barTable != null) { StayInsideButton button = new StayInsideButton(); button.Cursor = Cursors.Hand; button.Height = 30; button.Width = 200; button.FlatStyle = FlatStyle.Flat; button.FlatAppearance.BorderSize = 0; button.BackColor = Color.Cyan; button.Tag = barTable; button.Text = "Bar"; button.Location = new Point(barTable.TablePositionX, barTable.TablePositionY); pnlRoom.Controls.Add(button); button.MouseDown += button_MouseDown; button.MouseUp += button_MouseUp; button.MouseMove += button_MouseMove; } lblMessage.Text = "Seating layout successfully loaded!"; }