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 FrmEditKala : Form
    {
        public int code = 0;
        public DbGymEntities2 database = new DbGymEntities2();


        public FrmEditKala()
        {
            InitializeComponent();
        }

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

        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_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 TxtPrice_TextChanged(object sender, EventArgs e)
        {
            Class1.ChangeNum(TxtPrice);
        }

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

        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
            {

                var query = (from kala in database.TblForooshgahs where kala.ID == code select kala).SingleOrDefault();
                query.KalaName = TxtName.Text;
                query.Mojudi = TxtTedad.Text;
                query.Price = TxtPrice.Text;

                database.SaveChanges();
                this.Close();



            }
        }

        private void FrmEditKala_Load(object sender, EventArgs e)
        {

        }
    }
}
