Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace Hotel_Management_System
- {
- internal class DatabaseConnection :IDatabase
- {
- private SqlConnection conn = new SqlConnection("Data Source=DESKTOP-BHPJ89K\\SQLExpress;Initial Catalog=hotel;Integrated Security=True;TrustServerCertificate=True");
- public void openConnection()
- {
- if(this.conn.State == System.Data.ConnectionState.Closed)
- {
- this.conn.Open();
- }
- }
- public bool getConnectionState()
- {
- switch (this.conn.State)
- {
- case System.Data.ConnectionState.Open:
- return true;
- default:
- return false;
- }
- }
- public void closeConnection()
- {
- using (SqlConnection conn = this.getConnection())
- {
- if(this.conn.State == System.Data.ConnectionState.Open)
- {
- this.conn.Close();
- }
- }
- }
- public SqlConnection getConnection()
- {
- return this.conn;
- }
- public SqlCommand executeCommand(string command)
- {
- using (SqlConnection connection = this.conn)
- {
- if(connection.State == System.Data.ConnectionState.Closed)
- {
- this.openConnection();
- }
- using(SqlCommand cmd = new SqlCommand(command, conn))
- {
- return cmd;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement