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 frmBimary : Form
    {
        public frmBimary()
        {
            InitializeComponent();
        }

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

        private void frmBimary_Load(object sender, EventArgs e)
        {
            // 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);
            // TODO: This line of code loads data into the 'bimaryDetectDataSet2.Bimary' table. You can move, or remove it, as needed.
            this.bimaryTableAdapter.Fill(this.bimaryDetectDataSet2.Bimary);
            labPos();
        }

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

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

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

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

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

        private void btnInsert_Click(object sender, EventArgs e)
        {
            this.bimaryTableAdapter.Insert(textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), int.Parse(comboBox1.SelectedValue.ToString()));
            
            this.darooHaTableAdapter.Fill(this.bimaryDetectDataSet1.DarooHa);
            this.bimaryTableAdapter.Fill(this.bimaryDetectDataSet2.Bimary);

            btnInsert.Enabled = false;
            btnNew.Enabled = true;
            labPos();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox4.Text != "")
            {
                this.bimaryTableAdapter.Delete(int.Parse(textBox4.Text.Trim()));
                
                this.darooHaTableAdapter.Fill(this.bimaryDetectDataSet1.DarooHa);
                this.bimaryTableAdapter.Fill(this.bimaryDetectDataSet2.Bimary);


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