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

        private void tabStrip1_SelectedTabChanged(object sender, DevComponents.DotNetBar.TabStripTabChangedEventArgs e)
        {

        }

        private void frmmain_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.tblmoshtari' table. You can move, or remove it, as needed.
           this.tblmoshtariTableAdapter.Fill(this.dataSet1.tblmoshtari);
            // TODO: This line of code loads data into the 'dataSet1.tblfilm' table. You can move, or remove it, as needed.
          this.tblfilmTableAdapter1.Fill(this.dataSet1.tblfilm);

        }

        private void گزارشToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmdaramad d = new frmdaramad();
            
               
                d.Show();

            
        }

        private void امانتدادنفیلمToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmkeraye c = new frmkeraye();
            c.ShowDialog();
        }

        private void برگشتفیلمToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmbargasht g = new frmbargasht();
           g.ShowDialog();
        }

        private void گزارشToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmreport q = new frmreport();
            q.ShowDialog();
        }

        private void خروجToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult a = MessageBox.Show("آیا میخواهید خارج شوید؟", "خروج", MessageBoxButtons.YesNoCancel);
            if (a == DialogResult.Yes)
                Application.Exit();
        }

        private void ثبتفیلمToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tabControl1.SelectTab(0);
        }

        private void ثبتمشتریToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tabControl1.SelectTab(1);
        }

        private void btnaddf_Click(object sender, EventArgs e)
        {
            frmaddfilm w = new frmaddfilm();
            w.Show();
          
        }

        private void btndelf_Click(object sender, EventArgs e)
        {

            try
            {
                int a = int.Parse(dgvsabtfilm.SelectedRows[0].Cells[4].Value.ToString());


                if (MessageBox.Show("آیا می خواهید حذف کنید؟", "اخطار", MessageBoxButtons.YesNoCancel) == System.Windows.Forms.DialogResult.Yes)
                {

                    tblfilmTableAdapter1.DeleteQuery(a);
                    updatefill();
                }
                else
                {
                    updatefill();

                }
            }

            catch
            {
                MessageBox.Show(".فیلدی برای حذف کردن یافت نشد", "اخطار", MessageBoxButtons.OK);
            }
        }

        private void btnaddm_Click(object sender, EventArgs e)
        {
            frmaddmoshtari r = new frmaddmoshtari();
            r.Show();
        }

        private void frmmain_Activated(object sender, EventArgs e)
        {
            updatefill();
        }
        public void updatefill()
        {
            this.tblmoshtariTableAdapter.Fill(this.dataSet1.tblmoshtari);
            // TODO: This line of code loads data into the 'dataSet11.tblfilm' table. You can move, or remove it, as needed.
            this.tblfilmTableAdapter1.Fill(this.dataSet1.tblfilm);
        }

        private void btndelm_Click(object sender, EventArgs e)
        {
            try
            {
                int b = int.Parse(dgvsabtmoshtari.SelectedRows[0].Cells[3].Value.ToString());
                DialogResult dr = (MessageBox.Show("آیا می خواهید حذف کنید؟", "اخطار", MessageBoxButtons.YesNoCancel));
                if (dr == DialogResult.Yes)
                {
                    tblmoshtariTableAdapter.DeleteQuery(b);
                    updatefill();
                }
                else if (dr == DialogResult.No)
                {
                    updatefill();
                }
                else
                {
                }
            }
            catch
            {
                MessageBox.Show(".فیلدی برای حذف کردن یافت نشد", "اخطار", MessageBoxButtons.OK);

            }
        }

        private void txtsearch_TextChanged(object sender, EventArgs e)
        {
            tblmoshtariTableAdapter.FillByfname(dataSet1.tblmoshtari, txtsearch.Text);

        }



        private void txtsearchfilm_TextChanged(object sender, EventArgs e)
        {
            tblfilmTableAdapter1.FillBytitle(dataSet1.tblfilm, txtsearchfilm.Text);

        }

        private void dgvsabtfilm_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            /*   try
               {
                   if (MessageBox.Show("آیا می خواهید حذف کنید؟", "اخطار", MessageBoxButtons.YesNoCancel) == System.Windows.Forms.DialogResult.Yes)
                   {
                      tblfilmTableAdapter.DeleteQuery(int.Parse(dgvsabtfilm.SelectedRows[0].Cells[4].Value.ToString()));
                       updatefill();
                    
                   }
                   else
                   {
                       updatefill();
                   }
               }
               catch
               {
                   MessageBox.Show(".فیلدی برای حذف کردن یافت نشد", "اخطار", MessageBoxButtons.OK);

               }*/

        }

        private void dgvsabtmoshtari_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            /*
            try
            {
                if (MessageBox.Show("آیا می خواهید حذف کنید؟", "اخطار", MessageBoxButtons.YesNoCancel) == System.Windows.Forms.DialogResult.Yes)
                {
                    tblmoshtariTableAdapter.DeleteQuery(int.Parse(dgvsabtmoshtari.SelectedRows[0].Cells[0].Value.ToString()));
                    updatefill();
                }
                else
                {
                    updatefill();
                }
            }
            catch
            {
                MessageBox.Show(".فیلدی برای حذف کردن یافت نشد", "اخطار", MessageBoxButtons.OK);

            }*/
        }

        private void btneditmoshtari_Click(object sender, EventArgs e)
        {
            frmeditmoshtari f = new frmeditmoshtari();
            f.txtnamemoshtari.Text = dgvsabtmoshtari.SelectedRows[0].Cells[0].Value.ToString();
            f.txtfamilymoshtari.Text = dgvsabtmoshtari.SelectedRows[0].Cells[1].Value.ToString();
            f.txttellmoshtari.Text = dgvsabtmoshtari.SelectedRows[0].Cells[2].Value.ToString();
            f.txtmid.Text = dgvsabtmoshtari.SelectedRows[0].Cells[3].Value.ToString();

            f.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            frmeditfilm f = new frmeditfilm();
            f.txtnam.Text = dgvsabtfilm.SelectedRows[0].Cells[0].Value.ToString();
            f.txtcontry.Text = dgvsabtfilm.SelectedRows[0].Cells[1].Value.ToString();
           
            f.txtyear.Text = dgvsabtfilm.SelectedRows[0].Cells[3].Value.ToString();
            f.txtfid.Text = dgvsabtfilm.SelectedRows[0].Cells[4].Value.ToString();
            f.txtcount.Text = dgvsabtfilm.SelectedRows[0].Cells[5].Value.ToString();
            f.Show();
        }

        private void dgvsabtfilm_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            //  tblfilmTableAdapter1.UpdateQuery(dgvsabtfilm.SelectedRows[0].Cells[1].Value.ToString(), dgvsabtfilm.SelectedRows[0].Cells[2].Value.ToString(), dgvsabtfilm.SelectedRows[0].Cells[3].Value.ToString(), dgvsabtfilm.SelectedRows[0].Cells[4].Value.ToString(), int.Parse(dgvsabtfilm.SelectedRows[0].Cells[0].Value.ToString()));
        }

        private void dgvsabtmoshtari_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            tblmoshtariTableAdapter.UpdateQuery(dgvsabtmoshtari.SelectedRows[0].Cells[1].Value.ToString(), dgvsabtmoshtari.SelectedRows[0].Cells[2].Value.ToString(), dgvsabtmoshtari.SelectedRows[0].Cells[3].Value.ToString(), int.Parse(dgvsabtmoshtari.SelectedRows[0].Cells[0].Value.ToString()));
        }

        private void gsgfgsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tabControl1.SelectTab(2);
        }

        
        private void frmmain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void اطلاعاتکاربریToolStripMenuItem_Click(object sender, EventArgs e)
        {
            new frmedituser().Show();
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }
    }
}