using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Class_tblDriver
/// </summary>
public class Class_tblDriver
{
    private int int_UserTypeID = 0;
    private String Str_UserName = String.Empty;
    private String Str_Password = String.Empty;
    private String Str_Name = String.Empty;
    private String Str_Family = String.Empty;
    private String Str_Tell = String.Empty;
    private String Str_Mobail = String.Empty;
    private String Str_Email = String.Empty;
    private String Str_Address = String.Empty;
    private Boolean Bln_IsLogedIn = Boolean.Parse("false");
    private String Str_UserTypeDescription = String.Empty;


    public Class_tblDriver(int _UserTypeID, String _UserName, String _Password, String _Name, String _Family, String _Tell, String _Mobail, String _Email, String _Address)
	{
        this.int_UserTypeID = _UserTypeID;
        this.Str_UserName = _UserName;
        this.Str_Password = _Password;
        this.Str_Name = _Name;
        this.Str_Family = _Family;
        this.Str_Tell = _Tell;
        this.Str_Mobail = _Mobail;
        this.Str_Email = _Email;
        this.Str_Address = _Address;
	}

    public Class_tblDriver(String _UserName, String _Password)
    {
        this.Str_UserName = _UserName;
        this.Str_Password = _Password;
    }

    public void UDF_Save()
    {
        LSCTamiratDataContext db = new LSCTamiratDataContext();
        tblDriver Driv = new tblDriver();
        Driv.UserTypeID = int_UserTypeID;
        Driv.DriverUserName = Str_UserName;
        Driv.DriverPassword = Str_Password;
        Driv.DriverName = Str_Name;
        Driv.DriverFamily = Str_Family;
        Driv.DriverTell = Str_Tell;
        Driv.DtiverMobail = Str_Mobail;
        Driv.DriverEmail = Str_Email;
        Driv.DriverAddress = Str_Address;

        db.tblDrivers.InsertOnSubmit(Driv);
        db.SubmitChanges();
    }

   
    //متد بررسی عدم تکراری بودن نام کاربری برای ثبت نام در سیستم
    public Boolean UDF_ReternUserName()
    {
        LSCTamiratDataContext db = new LSCTamiratDataContext();
        try
        {
            tblDriver Drv = db.tblDrivers.Single(n => n.DriverUserName.Trim() == Str_UserName.Trim());
            return true;
        }
        catch
        {
            return false;
        }
    }

    public void UDF_CheckUserValidation()
    {
        LSCTamiratDataContext db = new LSCTamiratDataContext();
        try
        {
            tblDriver Drivr = db.tblDrivers.Single(n => n.DriverUserName.Trim() == Str_UserName.Trim() && n.DriverPassword.Trim() == Str_Password.Trim());
            if (Drivr.DriverUserName == "")
            {
                Bln_IsLogedIn = Boolean.Parse("false");
            }
            else
            {//در این بخش در صورتی که مشخصات کاربری صحیح باشد برخی از اطلاعات کاربر در فیلدهای کلاس مقدار دهی می شوند
                Bln_IsLogedIn = Boolean.Parse("true");
                
                int_UserTypeID = Drivr.tblUserType.UserTypeID;
                Str_Password = String.Empty;
                Str_UserTypeDescription = Drivr.tblUserType.UserTypeDescription;
                Str_Name = Drivr.DriverName;
                Str_Family = Drivr.DriverFamily;
                Str_Email = Drivr.DriverEmail;
            }
        }
        catch
        {
            Bln_IsLogedIn = Boolean.Parse("false");
        }
    }

    public Boolean Is_LogedIn
    {
        get
        {
            return Bln_IsLogedIn;
        }
    }

    public int int_UserTypeIDD
    {
        get
        {
            return int_UserTypeID;
        }
    }

    public String Str_NameSname
    {
        get
        {
            return Str_Name + " " + Str_Family;
        }
    }

    public String Str_EmailAddress
    {
        get
        {
            return Str_Email;
        }
    }


}