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;

namespace Apple_Software
{
    public partial class AFWAdd : Form
    {
        public AFWAdd()
        {
            InitializeComponent();
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            Control.Focus(textBox3, e);
        }

        private void textBox3_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue.ToString() == "13") button3.Focus();
        }

        public static string PictureLocation = "";
        private void button3_Click(object sender, EventArgs e)
        {
            int a = Picture.Pic(this);
            pictureBox2.ImageLocation = Picture.Location;
            PictureLocation = Picture.Location;
            textBox6.Focus();
        }

        private void textBox6_KeyDown(object sender, KeyEventArgs e)
        {
            Control.Focus(textBox7, e);
        }

        private void textBox7_KeyDown(object sender, KeyEventArgs e)
        {
            Control.Focus(textBox8, e);
        }

        private void textBox8_KeyDown(object sender, KeyEventArgs e)
        {
            Control.Focus(textBox9, e);
        }

        private void textBox9_KeyDown(object sender, KeyEventArgs e)
        {
            Control.Focus(textBox10, e);
        }

        private void textBox10_KeyDown(object sender, KeyEventArgs e)
        {
            Control.Focus(textBox11, e);
        }

        private void textBox11_KeyDown(object sender, KeyEventArgs e)
        {
            Control.Focus(textBox12, e);
        }

        private void textBox12_KeyDown(object sender, KeyEventArgs e)
        {
            Control.Focus(textBox14, e);
        }

        private void textBox14_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue.ToString() == "13") button3.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "" || textBox3.Text == "" || PictureLocation == "")
            {
                DialogResult resualt;
                resualt = MessageBox.Show("!فیلدی را خالی گزاشته اید لطفا اطلاعات را کامل کنید", " ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                int a = 0;
                for (int i = 0; i < textBox7.Text.Length; i++)
                    if (!char.IsNumber(Convert.ToChar(textBox7.Text.Substring(i, 1))))
                        a = 1;
                for (int i = 0; i < textBox8.Text.Length; i++)
                    if (!char.IsNumber(Convert.ToChar(textBox8.Text.Substring(i, 1))))
                        a = 1;
                for (int i = 0; i < textBox9.Text.Length; i++)
                    if (!char.IsNumber(Convert.ToChar(textBox9.Text.Substring(i, 1))))
                        a = 1;
                for (int i = 0; i < textBox10.Text.Length; i++)
                    if (!char.IsNumber(Convert.ToChar(textBox10.Text.Substring(i, 1))))
                        a = 1;

                if (a == 1)
                {
                    MessageBox.Show("!لطفا در فیلد های تلفن یا موبایل عدد وارد کنید", " ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    try
                    {
                        DataManagement.DT = DataManagement.I_U_D("select * from Properties", "Insert Into Properties(Id,Tid,Name,Family,Job,Tell_1,Tell_2,Mobile_1,Mobile_2,Address_1,Address_2,Picture,Dis) Values(" + textBox1.Text.ToString() + ",'" + Tid + "','" + textBox2.Text.ToString() + "','" + textBox3.Text.ToString() + "','" + textBox6.Text.ToString() + "','" + textBox7.Text.ToString() + "','" + textBox8.Text.ToString() + "','" + textBox9.Text.ToString() + "','" + textBox10.Text.ToString() + "','" + textBox11.Text.ToString() + "','" + textBox12.Text.ToString() + "','" + PictureLocation.ToString() + "','" + textBox14.Text.ToString() + "')");
                        MessageBox.Show(".ثبت مشخصات کارگر جدید با موفقیت انجام شد", " ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    catch { }
                }
            }
        }

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

        public static string Tid = "";
        private void AFWAdd_Load(object sender, EventArgs e)
        {
            try
            {
                Tid = "";
                DataManagement.DT = DataManagement.Search("select Tid from properties where left(Tid,1)='W'");
                Tid = "W" + (DataManagement.DT.Rows.Count + 1).ToString();

                DataManagement.DT = DataManagement.Search("select Id from properties");
                textBox1.Text = (DataManagement.DT.Rows.Count + 1).ToString();
            }
            catch { }

            this.Height = 445;
            this.Width = 448;
        }

        private void AFWAdd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue.ToString() == "114")
                button3_Click(sender, e);
            if (e.KeyValue.ToString() == "113")
                button1_Click(sender, e);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("osk.exe");
        }
    }
}
