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

namespace Publishmentation
{
    public partial class NewCustomer : Form
    {
        public NewCustomer()
        {
            InitializeComponent();
        }
        FormCollection frm = new FormCollection();
        SqlCommand command = new SqlCommand();
        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void NewCustomer_Load(object sender, EventArgs e)
        {
            frm = Application.OpenForms;
            InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(CultureInfo.GetCultureInfo("fa"));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" & textBox2.Text != "" & textBox3.Text != "" & textBox4.Text != "")
            {
                Connector connection = new Connector();
                Customer newCustomer = new Customer();
                newCustomer.CustomerName = textBox1.Text;
                newCustomer.CustomerFamily = textBox2.Text;
                newCustomer.Tel = Convert.ToInt32(textBox3.Text);
                newCustomer.Address = textBox4.Text;
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter("@customerName", SqlDbType.NVarChar, 30));
                command.Parameters["@customerName"].Value = newCustomer.CustomerName;
                command.Parameters.Add(new SqlParameter("@customerFamily", SqlDbType.NVarChar, 50));
                command.Parameters["@customerFamily"].Value = newCustomer.CustomerFamily;
                command.Parameters.Add(new SqlParameter("@customertel", SqlDbType.Decimal));
                command.Parameters["@customertel"].Value = newCustomer.Tel;
                command.Parameters.Add(new SqlParameter("@customerAddress", SqlDbType.Text));
                command.Parameters["@customerAddress"].Value = newCustomer.Address;
                command.CommandText = "newCustomer";
                if (connection.storeProcedure(command))
                    MessageBox.Show("!مشتری با موفقیت ثبت شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                else
                    MessageBox.Show("ثبت مشتری با مشکل روبرو شد", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
                MessageBox.Show("!مقادیر وارد شده درست نمی باشند", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            this.Close();
        }

        private void NewCustomer_FormClosed(object sender, FormClosedEventArgs e)
        {
            frm["Form1"].Enabled = true;
            frm["Form1"].Show();
            frm["Form1"].Focus();
        }
    }
}