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

namespace BimaryDetect
{
    public partial class frmDarooha : Form
    {
        public frmDarooha()
        {
            InitializeComponent();
        }

        private void frmDarooha_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'bimaryDetectDataSet.DarooTypes' table. You can move, or remove it, as needed.
            this.darooTypesTableAdapter.Fill(this.bimaryDetectDataSet.DarooTypes);
            // TODO: This line of code loads data into the 'bimaryDetectDataSet1.DarooHa' table. You can move, or remove it, as needed.
            this.darooHaTableAdapter.Fill(this.bimaryDetectDataSet1.DarooHa);
            labPos();
        }

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

        private void btnNew_Click(object sender, EventArgs e)
        {
            this.darooHaBindingSource.AddNew();
            btnInsert.Enabled = true;
            btnNew.Enabled = false;
            labPos();
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            this.darooHaTableAdapter.Insert(textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), int.Parse(comboBox1.SelectedValue.ToString()));
            // TODO: This line of code loads data into the 'bimaryDetectDataSet.DarooTypes' table. You can move, or remove it, as needed.
            this.darooTypesTableAdapter.Fill(this.bimaryDetectDataSet.DarooTypes);
            // TODO: This line of code loads data into the 'bimaryDetectDataSet1.DarooHa' table. You can move, or remove it, as needed.
            this.darooHaTableAdapter.Fill(this.bimaryDetectDataSet1.DarooHa);
            btnInsert.Enabled = false;
            btnNew.Enabled = true;
            labPos();
        }

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

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

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

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox4.Text != "")
            {
                this.darooHaTableAdapter.Delete(int.Parse(textBox4.Text.Trim()));
                
                // TODO: This line of code loads data into the 'bimaryDetectDataSet.DarooTypes' table. You can move, or remove it, as needed.
                this.darooTypesTableAdapter.Fill(this.bimaryDetectDataSet.DarooTypes);
                // TODO: This line of code loads data into the 'bimaryDetectDataSet1.DarooHa' table. You can move, or remove it, as needed.
                this.darooHaTableAdapter.Fill(this.bimaryDetectDataSet1.DarooHa);

                this.labPos();
                MessageBox.Show("دارو حذف شد");
            }
            else
            {
                MessageBox.Show("دارویی انتخاب نشده است");
            }
        }
    }
}