using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Car_wash
{
    internal class dbconnect
    {
        private SqlConnection cn = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\bib\Desktop\Projekt-CAR_WASH\Car-wash\Car-wash\DBCARwash.mdf;Integrated Security=True; Connect Timeout=30");
        SqlCommand cm = new SqlCommand();
        public SqlConnection getConnection()
        {
            return cn;
        }

        public void openConnection()
        {
            if (cn.State == System.Data.ConnectionState.Closed)
            {
                cn.Open();
            }
        }

        public void closeConnection()
        {
            if (cn.State == System.Data.ConnectionState.Open)
            {
                cn.Close();
            }

        }

        public void executeQuery(string query)
        {
            try { 
                openConnection();
                cm = new SqlCommand(query, cn);
                cm.ExecuteNonQuery();
                closeConnection();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Car wash Management System");
            }
            
        }
    }
}
