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



        private void buttonX3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmkeraye_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet15.tblkeraye' table. You can move, or remove it, as needed.
            this.tblkerayeTableAdapter.Fill(this.dataSet15.tblkeraye);


            // TODO: This line of code loads data into the 'dataSet12.tblfilm' table. You can move, or remove it, as needed.
            this.tblfilmTableAdapter1.Fill(this.dataSet12.tblfilm);
            // TODO: This line of code loads data into the 'dataSet12.tblmoshtari' table. You can move, or remove it, as needed.
            this.tblmoshtariTableAdapter1.Fill(this.dataSet12.tblmoshtari);
            lblDate.Text = myfunction.convertDate(DateTime.Now.ToShortDateString(), myfunction.dataConvertMode.toPersian);

        }

        private void textBoxX1_TextChanged(object sender, EventArgs e)
        {
            tblmoshtariTableAdapter1.FillByfname(dataSet12.tblmoshtari, textBoxX1.Text);
        }

        private void textBoxX2_TextChanged(object sender, EventArgs e)
        {
            tblfilmTableAdapter1.FillBytitle(dataSet12.tblfilm, textBoxX2.Text);
        }

        private void buttonX4_Click(object sender, EventArgs e)
        {
            if (int.Parse(dataGridViewX2.SelectedRows[0].Cells[5].Value.ToString()) <= 0)
            {

                MessageBox.Show("تعداد امانت دادن این فیلم بیشتر از حد مجاز میباشد", "!!!اخطار", MessageBoxButtons.OK);


            }
            else
            {
                if (txtkeraye.Text == "")
                {

                    MessageBox.Show("لطفا مبلغ کرایه را وارد کنید", "!!!اخطار", MessageBoxButtons.OK);
                }
                else
                {
                    DateTime dt = Convert.ToDateTime(myfunction.convertDate(lblDate.Text, myfunction.dataConvertMode.toGregorian));
                    int mid = int.Parse(dataGridViewX1.SelectedRows[0].Cells[0].Value.ToString());
                    int fid = int.Parse(dataGridViewX2.SelectedRows[0].Cells[0].Value.ToString());

                    tblkerayeTableAdapter.InsertQuery(fid, mid, lblDate.Text, dt, Convert.ToDecimal(txtkeraye.Text));
                    
                    tblfilmTableAdapter1.Updatecount1(int.Parse(dataGridViewX2.SelectedRows[0].Cells[0].Value.ToString()));

                    this.tblkerayeTableAdapter.Fill(this.dataSet15.tblkeraye);

                    this.tblfilmTableAdapter1.Fill(this.dataSet12.tblfilm);

                }
            }
        }

        private void txtkeraye_Leave(object sender, EventArgs e)
        {
            string s = "";
            int k = 1;
            for (int i = txtkeraye.Text.Length - 1; i >= 0; i--)

                if (k < 3)
                {
                    s = txtkeraye.Text[i] + s;
                    k++;
                }
                else
                {
                    k = 1;
                    s = txtkeraye.Text[i] + s;
                    s = "," + s;

                }
            if (s[0] == ',')
            {
                s = s.Substring(1);
                txtkeraye.Text = s;

            }


        }

        private void dataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridViewX1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void txtkeraye_TextChanged(object sender, EventArgs e)
        {
            labelX5.Text = myfunction.numtostr(txtkeraye.Text);
        }
    }
















}

