using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace The_Contacts
{
    public partial class Delete : Form
    {
        public Delete(String No,string name)
        {
            InitializeComponent();
            ctnNo = No;
            strName = name;
           
            label1.Text = label1.Text.Replace("X", name);
        }
        
        string ctnNo;
        string strName;
        SqlConnection objSqlConnection;
        SqlCommand objSQLcommand;
        String DataDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Pars Contacts\DataBase.mdf";
        private void Delete_Load(object sender, EventArgs e)
        {
            objSqlConnection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=" + DataDirectory + ";Integrated Security=True;User Instance=True");
            try
            {
                objSqlConnection.Open();
                objSQLcommand = new SqlCommand();
                objSQLcommand.Connection = objSqlConnection;

            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message, "Error");
                this.Close();
            }
        }
        void DeleteWithOutRec(string no)
        {
            try
            {
                objSQLcommand.CommandText = "Delete From Contact where No=" + no;
                objSQLcommand.ExecuteNonQuery();
            }
            catch
            {

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DeleteWithOutRec(ctnNo);
 
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
