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

namespace WindowsApplication2
{
    public partial class DeleteCD : Form
    {
        public DeleteCD()
        {
            InitializeComponent();
        }

        private void Form16_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet21.cd' table. You can move, or remove it, as needed.
            this.cdTableAdapter.Fill(this.dataSet21.cd);
        }
        private void button2_Click(object sender, EventArgs e)
        {
 
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void fillBy6ToolStripButton_Click(object sender, EventArgs e)
        {
            try
            {
                this.cdTableAdapter.FillBy6(this.dataSet21.cd, nameToolStripTextBox.Text);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            MMDClassLibrary.MMessageBox p = new MMDClassLibrary.MMessageBox();
            if (p.ShowDeleteDialog())
            {
                sqlDataAdapter1.SelectCommand.Parameters.Clear();
                sqlDataAdapter1.DeleteCommand.Parameters.Clear();
                
                sqlDataAdapter1.DeleteCommand.CommandText = "DELETE FROM cd WHERE ((nameCd = @name) AND (typeCd = @type))";
                sqlDataAdapter1.DeleteCommand.Parameters.AddWithValue("@name", textBox1.Text);
                sqlDataAdapter1.DeleteCommand.Parameters.AddWithValue("@type", textBox2.Text);

                try
                {
                    sqlConnection1.Open();
                    sqlDataAdapter1.DeleteCommand.ExecuteNonQuery();
                    sqlConnection1.Close();
                    sqlDataAdapter1.SelectCommand.CommandText = "SELECT cd.* FROM  cd";
                    this.cdTableAdapter.Fill(this.dataSet21.cd);

                    pictureBox1.Visible = false;
                    pictureBox2.Visible = true;
                }
                catch
                {
                    dError dr = new dError();
                    dr.ShowDialog();
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            sqlDataAdapter1.Update(dataSet21);
            this.Close();
        }
    }
}