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

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

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

        private void button1_Click(object sender, EventArgs e)
        {
         //   Form15 f15 = new Form15();
         //   f15.ShowDialog();
            int maxID;
            sqlDataAdapter1.SelectCommand.CommandText = "SELECT     MAX(rank) AS rank FROM salecd";
            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 [salecd] ([rank], [idCd], [idRememmber], [dateSale], [idSeller], [rateSale]) VALUES (@rank, @idCd, @idRememmber, @dateSale, @idSeller, @rateSale)";
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@rank", maxID);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@idRememmber", textBox1.Text);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@idCd", textBox2.Text);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@idSeller", textBox3.Text);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@rateSale", textBox4.Text);
            sqlDataAdapter1.InsertCommand.Parameters.AddWithValue("@dateSale", MyDate.Today());
            sqlConnection1.Open();

            try
            {
                sqlDataAdapter1.InsertCommand.ExecuteNonQuery();
                MMDClassLibrary.MMessageBox p = new MMDClassLibrary.MMessageBox();
                p.ShowSaveDialog1();
            }
            catch
            {
                MMDClassLibrary.MMessageBox m = new MMDClassLibrary.MMessageBox();
                m.ShowAlertMessage("اطلاعات داده شده همخوانی ندارد ");
            }
            sqlConnection1.Close();
            sqlDataAdapter1.SelectCommand.CommandText = "SELECT saled.* FROM saled";
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
        }
    }
}