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.Sql;
using System.Data.SqlClient;

namespace ShopBastani
{
    public partial class add : Form
    {
        public add()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox4.Text == "" || textBox5.Text == "" || textBox6.Text == "")
            {
                label7.Text = "لطفا جعبه متن ها را پر کنید ";
            }
            else
            {
                try
                {
                    string mos = (Convert.ToInt32(textBox4.Text) * Convert.ToInt32(textBox5.Text)).ToString();
                    SqlConnection scn = new SqlConnection();
                    SqlCommand scm = new SqlCommand();
                    scn.ConnectionString = @"Data Source=(local);Initial Catalog=DBCEMENT;Integrated Security=True";
                    scm.Connection = scn;
                    scm.CommandText = "INSERT INTO tbcement (sname,FATHER,SACKING,svalue,sdate,talab)VALUES(@p1,@p3,@p4,@p5,@p6,@talab)";
                    scm.Parameters.Clear();
                    scm.Parameters.AddWithValue("@p1", textBox2.Text + "-" + textBox1.Text);
                    scm.Parameters.AddWithValue("@p3", textBox3.Text);
                    scm.Parameters.AddWithValue("@p4", textBox4.Text);
                    scm.Parameters.AddWithValue("@p5", textBox5.Text);
                    scm.Parameters.AddWithValue("@p6", textBox6.Text);
                    scm.Parameters.AddWithValue("@talab", mos);
                    scn.Open();
                    scm.ExecuteNonQuery();
                    scn.Close();
                    scm.Dispose();
                    scn.Dispose();
                    textBox1.Text = string.Empty;
                    textBox2.Text = string.Empty;
                    textBox3.Text = string.Empty;
                    textBox4.Text = string.Empty;
                    textBox5.Text = string.Empty;
                    textBox6.Text = string.Empty;
                    textBox1.Focus();
                    label7.Text = string.Empty;
                }

                catch
                {
                    label7.Text = "با مشکل مواجه شدید";
                }
            }
            
        }

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