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

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

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

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
                {
                    emptyErorre ero = new emptyErorre();
                    ero.ShowDialog();
                    return;
               
                }
 
                int maxID;
                sqlDataAdapter1.SelectCommand.CommandText = "SELECT MAX(idRemember) AS idRemember FROM remembers";
                sqlConnection1.Open();
                maxID = Convert.ToInt16(sqlDataAdapter1.SelectCommand.ExecuteScalar()) + 1;
                sqlConnection1.Close();
                MMDClassLibrary.MDate MyDate = new MMDClassLibrary.MDate();
                sqlDataAdapter1.InsertCommand.Parameters.Clear();
                sqlDataAdapter1.InsertCommand.CommandText = "INSERT INTO [remembers] ([idRemember], [nameRemember], [familyRemember], [fatherName], [dateRemember], [addressRemember], [telRemember]) VALUES (@idRemember, @nameRemember, @familyRemember, @fatherName, @dateRemember, @addressRemember, @telRemember)";
                sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@idRemember", maxID);
                sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@nameRemember", textBox1.Text);
                sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@familyRemember", textBox2.Text);
                sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@fatherName", textBox3.Text);
                sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@telRemember", textBox4.Text);
                sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@addressRemember", textBox5.Text);
                sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@dateRemember", MyDate.Today());
                sqlConnection1.Open();
                sqlDataAdapter1.InsertCommand.ExecuteNonQuery();
                sqlConnection1.Close();

                MMDClassLibrary.MMessageBox p = new MMDClassLibrary.MMessageBox();
                p.ShowSaveDialog1();

                sqlDataAdapter1.SelectCommand.CommandText = "SELECT remembers.* FROM remembers";
                this.remembersTableAdapter.Fill(this.dataSet21.remembers);
            }
            catch
            {
                MMDClassLibrary.MMessageBox er = new MMDClassLibrary.MMessageBox();
                er.ShowMessage("در ورود داده ها دقت فرمایید ");
            }
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            textBox5.Text = "";
        }

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

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}