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;

namespace GymSystem
{
    public partial class FrmSabtKala : Form
    {
        DbGymEntities2 database = new DbGymEntities2();


        public FrmSabtKala()
        {
            InitializeComponent();
        }

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

        private void TxtPrice_TextChanged(object sender, EventArgs e)
        {
            Class1.ChangeNum(TxtPrice);
        }

        private void TxtTedad_TextChanged(object sender, EventArgs e)
        {
            Class1.ChangeNum(TxtTedad);
        }

        private void TxtPrice_KeyPress(object sender, KeyPressEventArgs e)
        {
            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 TxtTedad_KeyUp(object sender, KeyEventArgs e)
        {

        }

        private void TxtTedad_KeyPress(object sender, KeyPressEventArgs e)
        {
            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 PicSave_Click(object sender, EventArgs e)
        {

            FrmMessage fm = new FrmMessage();

            if (string.IsNullOrWhiteSpace(TxtName.Text) || string.IsNullOrWhiteSpace(TxtPrice.Text) || string.IsNullOrWhiteSpace(TxtTedad.Text))
            {
               
                fm.Text = "ثبت کالا";
                fm.LblText.Text = "همه فیلدها تکمیل نشده اند.";
                fm.PicOk.Visible = true;
                fm.PicHoshdar.Visible = true;

                fm.ShowDialog();

            }
            else
            {
                TblForooshgah tbl = new TblForooshgah();
                tbl.KalaName = TxtName.Text;
                tbl.Mojudi = TxtTedad.Text;
                tbl.Price = TxtPrice.Text;

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

                this.Close();

            }



        }
    }
}
