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

namespace TaxiTelphoni
{
    public partial class frmMachines : Form
    {
        public frmMachines()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            //this.bindingSource1.AddNew();
            this.machineNoowBindingSource.AddNew();
            button1.Enabled = false;
            button4.Enabled = true;
            btnCancel.Enabled = true;
            MessageBox.Show("لطفا مقادیر مورد نظر را وارد فرمائید");
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.machineNoowTableAdapter.Insert(textBox2.Text.Trim());
            //this.machineNoowTableAdapter.Update(textBox2.Text, int.Parse(textBox1.Text), int.Parse(textBox1.Text));
            button4.Enabled = false;
            button1.Enabled = true;
            btnCancel.Enabled = false;
            dataGridView1.Refresh();
            MessageBox.Show("رکورد مورد نظر ذخیره گردید");
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.machineNoowBindingSource.CancelEdit();
            button4.Enabled = false;
            button1.Enabled = true;
            btnCancel.Enabled = false;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != ""  || textBox2.Text != "")
            {
                this.machineNoowTableAdapter.Update(textBox2.Text, int.Parse(textBox1.Text), int.Parse(textBox1.Text));
                dataGridView1.Refresh();
            }
            else
            {
                MessageBox.Show("نام یا کد خودرو وارد نشده است");
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                this.machineNoowTableAdapter.Delete(int.Parse(textBox1.Text.Trim()));
                this.machineNoowTableAdapter.Fill(txdb1001DataSet.MachineNoow);
            }
            else
            {
                MessageBox.Show("کد خودرو وارد نشده است");
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (textBox3.Text != "")
            {
                this.machineNoowTableAdapter.FillBy(txdb1001DataSet.MachineNoow, "%" + textBox3.Text.Trim() + "%");
            }
            else
            {
                MessageBox.Show("نام  و یا بخشی از نام خودرو  در فیلد زرد رنگ وارد نشده است");
            }
            
        }

        protected void labPos()
        {
            this.label4.Text = this.machineNoowBindingSource.Position + 1 + " از " + this.machineNoowBindingSource.Count;
        }

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

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            this.machineNoowTableAdapter.Fill(txdb1001DataSet.MachineNoow);
        }

        private void btmNext_Click(object sender, EventArgs e)
        {
            if (this.machineNoowBindingSource.Position + 1 < this.machineNoowBindingSource.Count)
            {
                this.machineNoowBindingSource.MoveNext();
                this.labPos();
            }
        }

        private void btnPrevoiuse_Click(object sender, EventArgs e)
        {
            this.machineNoowBindingSource.MovePrevious();
            this.labPos();
        }

        private void btnLast_Click(object sender, EventArgs e)
        {
            this.machineNoowBindingSource.MoveLast();
            this.labPos();
        }

        private void btnFirst_Click(object sender, EventArgs e)
        {
            this.machineNoowBindingSource.MoveFirst();
            this.labPos();
        }


    }
}