private void btnAddRoom_Click(object sender, EventArgs e) { if (!modify) { sqlcmd.Connection = sqlconn; sqlcmd.CommandType = CommandType.Text; sqlcmd.CommandText = "INSERT into Room (RoomNo, Floor, Capacity, Price) VALUES (@txtRoomNo, @txtFloor, @txtCapacity, @txtPrice)"; sqlcmd.Parameters.AddWithValue("@txtRoomNo", txtRoomNo.Text); sqlcmd.Parameters.AddWithValue("@txtFloor", txtFloor.Text); sqlcmd.Parameters.AddWithValue("@txtCapacity", txtCapacity.Text); sqlcmd.Parameters.AddWithValue("@txtPrice", txtPrice.Text); try { sqlconn.Open(); int recordsAffected = sqlcmd.ExecuteNonQuery(); if (recordsAffected > 0) { MessageBox.Show("New Room Added", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); MainMenu mainMenu = new MainMenu(); mainMenu.Closed += (s, args) => this.Close(); mainMenu.Show(); } } catch (SqlException) { MessageBox.Show("Unable to create new room", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sqlconn.Close(); } } else { sqlcmd.Connection = sqlconn; sqlcmd.CommandType = CommandType.Text; sqlcmd.CommandText = "UPDATE Room SET RoomNo = @txtRoomNo, Floor = @txtFloor, Capacity = @txtCapacity, Price = @txtPrice WHERE RoomNo = @newOldRoomNo"; sqlcmd.Parameters.AddWithValue("@txtRoomNo", txtRoomNo.Text); sqlcmd.Parameters.AddWithValue("@txtFloor", txtFloor.Text); sqlcmd.Parameters.AddWithValue("@txtCapacity", txtCapacity.Text); sqlcmd.Parameters.AddWithValue("@txtPrice", txtPrice.Text); sqlcmd.Parameters.AddWithValue("@newOldRoomNo", oldEmail); try { sqlconn.Open(); int recordsAffected = sqlcmd.ExecuteNonQuery(); if (recordsAffected > 0) { MessageBox.Show("Room Details Modiied", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); MainMenu mainMenu = new MainMenu(); mainMenu.Closed += (s, args) => this.Close(); mainMenu.Show(); } } catch (SqlException) { MessageBox.Show("Unable to Modify Room", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sqlconn.Close(); } } }
private void btnReserve_Click(object sender, EventArgs e) { if (!modify) { sqlcmd.Connection = sqlconn; sqlcmd.CommandType = CommandType.Text; sqlcmd.CommandText = "INSERT into Reservation (CheckIn, CheckOut, Price, Room, Email) VALUES (@txtCheckIn, @txtCheckOut, @txtPrice, @txtRoom, @txtEmail)"; sqlcmd.Parameters.AddWithValue("@txtCheckIn", dpCheckIn.Value.ToString("yyyy-MM-dd")); sqlcmd.Parameters.AddWithValue("@txtCheckOut", dpCheckOut.Value.ToString("yyyy-MM-dd")); sqlcmd.Parameters.AddWithValue("@txtPrice", txtPrice.Text); sqlcmd.Parameters.AddWithValue("@txtRoom", txtRoom.Text); sqlcmd.Parameters.AddWithValue("@txtEmail", txtEmail.Text); try { sqlconn.Open(); int recordsAffected = sqlcmd.ExecuteNonQuery(); if (recordsAffected > 0) { MessageBox.Show("New Reservation Added", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); MainMenu mainMenu = new MainMenu(); mainMenu.Closed += (s, args) => this.Close(); mainMenu.Show(); } } catch (SqlException) { MessageBox.Show("Unable to create new reservation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sqlconn.Close(); } } else { sqlcmd.Connection = sqlconn; sqlcmd.CommandType = CommandType.Text; sqlcmd.CommandText = "UPDATE Reservation SET CheckIn = @newCheckIn, CheckOut = @newCheckOut, Price = @newPrice, Room = @newRoom, Email = @newEmail WHERE Email = @newOldEmail"; sqlcmd.Parameters.AddWithValue("@newCheckIn", dpCheckIn.Value.ToString("yyyy-MM-dd")); sqlcmd.Parameters.AddWithValue("@newCheckOut", dpCheckOut.Value.ToString("yyyy-MM-dd")); sqlcmd.Parameters.AddWithValue("@newPrice", txtPrice.Text); sqlcmd.Parameters.AddWithValue("@newRoom", txtRoom.Text); sqlcmd.Parameters.AddWithValue("@newEmail", txtEmail.Text); sqlcmd.Parameters.AddWithValue("@newOldEmail", oldEmail); try { sqlconn.Open(); int recordsAffected = sqlcmd.ExecuteNonQuery(); if (recordsAffected > 0) { MessageBox.Show("Customer Details Modiied", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); MainMenu mainMenu = new MainMenu(); mainMenu.Closed += (s, args) => this.Close(); mainMenu.Show(); } } catch (SqlException) { MessageBox.Show("Unable to Modify Customer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sqlconn.Close(); } } }
private void btnCreate_Click(object sender, EventArgs e) { if (!modify) { sqlcmd.Connection = sqlconn; sqlcmd.CommandType = CommandType.Text; // sqlcmd.CommandText = @"insert into Customer (Name, Email, Company, Discount) values ('" + @txtName.Text + "','" + @txtEmail.Text + "','" + @txtCompany + "','" + @txtDiscount + "')"; sqlcmd.CommandText = "INSERT into Customer (Name, Email, Company, Discount) VALUES (@Name, @Email, @Company, @Discount)"; sqlcmd.Parameters.AddWithValue("@Name", txtName.Text); sqlcmd.Parameters.AddWithValue("@Email", txtEmail.Text); sqlcmd.Parameters.AddWithValue("@Company", txtCompany.Text); sqlcmd.Parameters.AddWithValue("@Discount", txtDiscount.Text); try { sqlconn.Open(); int recordsAffected = sqlcmd.ExecuteNonQuery(); if (recordsAffected > 0) { MessageBox.Show("New Customer Added", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); MainMenu mainMenu = new MainMenu(); mainMenu.Closed += (s, args) => this.Close(); mainMenu.Show(); } } catch (SqlException) { MessageBox.Show("Unable to create new customer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sqlconn.Close(); } } else { sqlcmd.Connection = sqlconn; sqlcmd.CommandType = CommandType.Text; sqlcmd.CommandText = "UPDATE Customer SET Name = @newName, Email = @newEmail, Company = @newCompany, Discount = @newDiscount WHERE Email = @newOldEmail"; sqlcmd.Parameters.AddWithValue("@newName", txtName.Text); sqlcmd.Parameters.AddWithValue("@newEmail", txtEmail.Text); sqlcmd.Parameters.AddWithValue("@newCompany", txtCompany.Text); sqlcmd.Parameters.AddWithValue("@newDiscount", txtDiscount.Text); sqlcmd.Parameters.AddWithValue("@newOldEmail", oldEmail); try { sqlconn.Open(); int recordsAffected = sqlcmd.ExecuteNonQuery(); if (recordsAffected > 0) { MessageBox.Show("Customer Details Modiied", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); MainMenu mainMenu = new MainMenu(); mainMenu.Closed += (s, args) => this.Close(); mainMenu.Show(); } } catch (SqlException) { MessageBox.Show("Unable to Modify Customer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sqlconn.Close(); } } }
private void btnSend_Click(object sender, EventArgs e) { sqlcmd.CommandText = "INSERT into Invoice (PaymentDate, Type, Description, Total, Status) VALUES (@txtPaymentDate, @txtType, @txtDescription, @txtTotal, @txtStatus)"; sqlcmd.Parameters.AddWithValue("@txtPaymentDate", lbDate.Text); sqlcmd.Parameters.AddWithValue("@txtType", ddType.Text); sqlcmd.Parameters.AddWithValue("@txtDescription", txtDesc.Text); sqlcmd.Parameters.AddWithValue("@txtTotal", txtTotal.Text); sqlcmd.Parameters.AddWithValue("@txtStatus", ddStatus.Text); try { sqlconn.Open(); int recordsAffected = sqlcmd.ExecuteNonQuery(); if (recordsAffected > 0) { MessageBox.Show("DONE", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); MainMenu mainMenu = new MainMenu(); mainMenu.Closed += (s, args) => this.Close(); mainMenu.Show(); } } catch (SqlException) { MessageBox.Show("Error Creating New Invoice", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sqlconn.Close(); } try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add(oldEmail); mail.Subject = "Invoice"; mail.IsBodyHtml = true; mail.Body = "<style type=\"text/css\">" + ".tg {border-collapse:collapse;border-spacing:0;}" + ".tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}" + ".tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}" + ".tg .tg-0lax{text-align:left;vertical-align:top}" + "</style>" + "<table class=\"tg\">" + " <tr>" + " <th class=\"tg-0lax\">Invoice Number</th>" + " <th class=\"tg-0lax\">" + lbInvoiceNumber.Text + "</th>" + " </tr>" + " <tr>" + " <td class=\"tg-0lax\">Payment Date</td>" + " <td class=\"tg-0lax\">" + lbDate.Text + "</td>" + " </tr>" + " <tr>" + " <td class=\"tg-0lax\">Type</td>" + " <td class=\"tg-0lax\">" + ddType.Text + "</td>" + " </tr>" + " <tr>" + " <td class=\"tg-0lax\">Description</td>" + " <td class=\"tg-0lax\">" + txtDesc.Text + "</td>" + " </tr>" + " <tr>" + " <td class=\"tg-0lax\">Total</td>" + " <td class=\"tg-0lax\">" + txtTotal.Text + "</td>" + " </tr>" + " <tr>" + " <td class=\"tg-0lax\">Status</td>" + " <td class=\"tg-0lax\">" + ddStatus.Text + "</td>" + " </tr>" + "</table>"; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("htmangmt", "H0tel4901"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); MessageBox.Show("Email Sent", "Congrats", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide(); MainMenu mainMenu = new MainMenu(); mainMenu.Closed += (s, args) => this.Close(); mainMenu.Show(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }