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 NewCD : Form
    {
        public NewCD()
        {
            InitializeComponent();
        }

        private void Form7_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 button1_Click(object sender, EventArgs e)
        {
            sqlDataAdapter1.Update(dataSet21);
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
        }



        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox3.Text == "" || textBox4.Text == "")
            {
                emptyErorre ee= new emptyErorre();
                ee.ShowDialog();
                return;
            }
            
            
            MMDClassLibrary.MMessageBox p = new MMDClassLibrary.MMessageBox();
            p.ShowSaveDialog2();
            int maxID;
            try
            {
                sqlDataAdapter1.SelectCommand.CommandText = "SELECT MAX(idCd) AS idCd FROM cd";
                sqlConnection1.Open();
                maxID = Convert.ToInt16(sqlDataAdapter1.SelectCommand.ExecuteScalar()) + 1;
                
            }
            catch
            {
                maxID = 1;
            }
            sqlConnection1.Close();
            sqlDataAdapter1.InsertCommand.Parameters.Clear();
            sqlDataAdapter1.InsertCommand.CommandText = "INSERT INTO cd VALUES (@id, @nameCd, @typeCd, @rateCd, @numberCd, @discription)";
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@id", maxID);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@nameCd", textBox1.Text);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@typeCd",comboBox1.Text);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@rateCd",Convert.ToInt32(textBox3.Text));
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@numberCd",Convert.ToInt32(textBox4.Text));
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@discription",textBox5.Text);
            sqlConnection1.Open();
            sqlDataAdapter1.InsertCommand.ExecuteNonQuery();
            sqlConnection1.Close();

            sqlDataAdapter1.SelectCommand.CommandText = "SELECT cd.* FROM cd";
            this.cdTableAdapter.Fill(this.dataSet21.cd);

            textBox1.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
      
        }

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

        }
    }
}