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 restooran
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {

        }

        private void txtcode_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.tbl_deser' table. You can move, or remove it, as needed.
            this.tbl_deserTableAdapter.Fill(this.dataSet1.tbl_deser);
            // TODO: This line of code loads data into the 'dataSet1.tbl_ghaza' table. You can move, or remove it, as needed.
            this.tbl_ghazaTableAdapter.Fill(this.dataSet1.tbl_ghaza);
            buttonX2.Enabled = false;
            buttonX5.Enabled = false; 

        }

        

        private void buttonX1_Click_1(object sender, EventArgs e)
        {
            try
            {
                tbl_ghazaTableAdapter.myinsert(txtcode.Text, txtsharh.Text, decimal.Parse(txtgheymat.Text));
                this.tbl_ghazaTableAdapter.Fill(this.dataSet1.tbl_ghaza);
                txtcode.Text = txtsharh.Text = txtgheymat.Text = "";
                txtcode.Focus();
            }
            catch { MessageBox.Show("error"); }
        }

        private void buttonX3_Click(object sender, EventArgs e)
        {
            
        }

        private void buttonX4_Click(object sender, EventArgs e)
        {
            try
            {
                tbl_deserTableAdapter.myinsert(txtcode1.Text, txtsharh1.Text, decimal.Parse(txtgheymat1.Text));
                this.tbl_deserTableAdapter.Fill(this.dataSet1.tbl_deser);
                txtcode1.Text = txtsharh1.Text = txtgheymat1.Text = "";
                txtcode1.Focus();
            }
            catch { MessageBox.Show("error"); }

        }

        private void buttonX6_Click(object sender, EventArgs e)
        {
        }

        private void اقفقToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                buttonX2.Enabled = true;
                txtcode.Text = dataGridViewX1.CurrentRow.Cells[0].Value.ToString();
                txtcode.Enabled = false;
                buttonX1.Enabled = false;
                txtsharh.Text = dataGridViewX1.CurrentRow.Cells[1].Value.ToString();
                txtgheymat.Text = dataGridViewX1.CurrentRow.Cells[2].Value.ToString();
            }
            catch { MessageBox.Show("error"); }
        }

        private void قلقلقToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("اطلاعات حذف شده قابل بازیابی نیست.آیا مطمئن هستید؟", "اخطار حذف", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    tbl_ghazaTableAdapter.mydelete(dataGridViewX1.CurrentRow.Cells[0].Value.ToString());
                    this.tbl_ghazaTableAdapter.Fill(this.dataSet1.tbl_ghaza);
                }
                else
                {
                }
            }
            catch { MessageBox.Show("error"); }
        }

        private void buttonX2_Click(object sender, EventArgs e)
        {
            try
            {
                tbl_ghazaTableAdapter.myupdate(txtcode.Text, txtsharh.Text, decimal.Parse(txtgheymat.Text));
                this.tbl_ghazaTableAdapter.Fill(this.dataSet1.tbl_ghaza);
                buttonX1.Enabled = true;
                txtcode.Enabled = true;
                txtcode.Text = txtsharh.Text = txtgheymat.Text = "";
                txtcode.Focus();
                buttonX2.Enabled = false;
            }
            catch { MessageBox.Show("error"); }

        }

        private void حذفToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if (MessageBox.Show("اطلاعات حذف شده قابل بازیابی نیست.آیا مطمئن هستید؟", "اخطار حذف", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                tbl_deserTableAdapter.mydelete(dataGridViewX2.CurrentRow.Cells[0].Value.ToString());
                this.tbl_deserTableAdapter.Fill(this.dataSet1.tbl_deser);
            }
            else
            {
            }
        }

        private void ویرایشToolStripMenuItem_Click(object sender, EventArgs e)
        {
            buttonX5.Enabled = true; 
            txtcode1.Text = dataGridViewX2.CurrentRow.Cells[0].Value.ToString();
            txtcode1.Enabled = false;
            buttonX4.Enabled = false;
            txtsharh1.Text = dataGridViewX2.CurrentRow.Cells[1].Value.ToString();
            txtgheymat1.Text = dataGridViewX2.CurrentRow.Cells[2].Value.ToString();
        }

        private void buttonX5_Click(object sender, EventArgs e)
        {
            try
            {
                tbl_deserTableAdapter.myupdate(txtcode1.Text, txtsharh1.Text, decimal.Parse(txtgheymat1.Text));
                this.tbl_deserTableAdapter.Fill(this.dataSet1.tbl_deser);
                txtcode1.Enabled = true;
                buttonX4.Enabled = true;
                txtcode1.Text = txtgheymat1.Text = txtsharh1.Text = "";
                txtcode1.Focus();
                buttonX5.Enabled = false;
            }
            catch { MessageBox.Show("error"); }
        }

        private void groupPanel1_Click(object sender, EventArgs e)
        {

        }
    }
}
