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

        private void frmUserLogIn_Load(object sender, EventArgs e)
        {
            LSC_RadioLogyDataContext db = new LSC_RadioLogyDataContext();
            var Query = from Row in db.tblUsers
                        where Row.UsersName.Trim() == Class_GlobalVar.Str_LogedUserName
                        select new
                        {
                           Row.UsersID ,
                           Row.UsersName ,
                           Row.UsersPass ,
                           Row.UserFName ,
                           Row.UsersSName ,
                           Row.UserTypeID ,
                           Row.UserTell ,
                           Row.UserMobail ,
                           Row.UserBanBit 
                        };
          foreach (var Row in Query )
          {
              Txt_UserID.Text = Row.UsersID.ToString();
              Txt_UserName.Text = Row.UsersName;
              Txt_Password.Text = Row.UsersPass;
              Txt_Name.Text = Row.UserFName;
              Txt_Family.Text = Row.UsersSName;
              Txt_UserType.Text = Row.UserTypeID.ToString();
              Txt_Tell.Text = Row.UserTell;
              Txt_Mobail.Text = Row.UserMobail;
              Chb_BanBit.Checked = Row.UserBanBit;
          }
           
        }

        private void Btn_Edit_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("آیا نسبت به ویرایش مشخصات کاربری خود اطمینان دارید؟" , "اخطار ویرایش مشخصات کاربری" , MessageBoxButtons.OKCancel ,MessageBoxIcon.Warning);
            if (dr == DialogResult.OK)
            {
                LSC_RadioLogyDataContext db = new LSC_RadioLogyDataContext();
                tblUser user = db.tblUsers.Single(n => n.UsersID == int.Parse(Txt_UserID.Text.Trim()));
                //user.UsersName = Txt_UserName.Text.Trim();
                user.UsersPass = Txt_Password.Text.Trim();
                user.UserFName = Txt_Name.Text.Trim();
                user.UsersSName = Txt_Family.Text.Trim();
                user.UserTypeID = int.Parse(Txt_UserType.Text.Trim()); 
                user.UserTell = Txt_Tell.Text.Trim();
                user.UserMobail = Txt_Mobail.Text.Trim();
                
                db.SubmitChanges();
            }

        }
    }
}
