using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Globalization;



namespace GymSystem
{
    public partial class FrmTamdid : Form
    {

        public DbGymEntities2 database = new DbGymEntities2();
        public int Code = 0;
        public string CName = "";

        public FrmTamdid()
        {
            InitializeComponent();
        }

        private void FrmTamdid_Load(object sender, EventArgs e)
        {
            TxtMablaq.Text = Properties.Settings.Default.Shahrie.ToString();

           



        }

        private void BtnPardakht_Click(object sender, EventArgs e)
        {

            

            var query = (from ozvha in database.TblUsers where ozvha.ID == Code select ozvha).SingleOrDefault();
            query.EtebarDate = CmbYearEtebar.Text + "/" + CmbMonthEtebar.Text + "/" + CmbdayEtebar.Text;
            database.SaveChanges();


            TblTarakonesh tbl = new TblTarakonesh();

            DateTime today = DateTime.Now;
            PersianCalendar pc = new PersianCalendar();

            string TDate = pc.GetYear(today).ToString("0000") + "/" + pc.GetMonth(today).ToString("00") + "/" + pc.GetDayOfMonth(today).ToString("00");
            tbl.TarakoneshDate = TDate;
            tbl.TarakoneshKind = "پرداخت شهریه";
            tbl.Price = TxtMablaq.Text;
            tbl.CustomerID = Code.ToString();
            tbl.CustomerName = CName;

            database.TblTarakoneshes.Add(tbl);
            database.SaveChanges();


             


            Properties.Settings.Default.Shahrie = TxtMablaq.Text;
            Properties.Settings.Default.Save();


              FrmMessage fm = new FrmMessage();

               fm.Text = "پرداخت شهریه";
               fm.LblText.Text = "پرداخت شهریه با موفقیت انجام شد";
               fm.PicOk.Visible = true;
               fm.PicKhabar.Visible = true;

               fm.ShowDialog();




            this.Close();


        }

        private void TxtMablaq_KeyPress(object sender, KeyPressEventArgs e)
        {
            //MessageBox.Show((Convert.ToInt32(e.KeyChar)).ToString());

            if (Convert.ToInt32(e.KeyChar) >= 48 && Convert.ToInt32(e.KeyChar) <= 57 || Convert.ToInt32(e.KeyChar) >= 1776 && Convert.ToInt32(e.KeyChar) <= 1785 || Convert.ToInt32(e.KeyChar) == 8 )
            {

            }
            else
            {
                e.KeyChar = Convert.ToChar(Keys.None);
            }


        }

        private void TxtMablaq_TextChanged(object sender, EventArgs e)
        {
            Class1.ChangeNum(TxtMablaq);
        }
    }
}
