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

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] != null)
        {
        }
        else
        {
            Response.Redirect("Default.aspx?ID=NotRegistered_or_Not_LogedIn" + DateTime.Now.Ticks.ToString());
        }
    }

    protected void Btn_Insert_Click(object sender, EventArgs e)
    {
        Lbl_Err.Text = "";
        LSC_KhateratDataContext db = new LSC_KhateratDataContext();
        tblKhateratPrivate tblKhat = new tblKhateratPrivate();

        tblKhat.KhaterehID = int.Parse(Drp_Khaterat.SelectedValue.ToString());
        tblKhat.UserID = int.Parse(Drp_UserNames.SelectedValue.ToString());
        tblKhat.UserAdmName = Session["UserName"].ToString();

        try
        {
            db.tblKhateratPrivates.InsertOnSubmit(tblKhat);
            db.SubmitChanges();
            Grd_KhateratPermiss.DataBind();
            Lbl_Err.Visible = true;
            Lbl_Err.Text = "سطح دسترسی اعمال شد";
        }
        catch
        {
            Lbl_Err.Visible = true;
            Lbl_Err.Text = "رکورد وارد شده تکراری می باشد";
        }

    }
    protected void Grd_KhateratPermiss_SelectedIndexChanged(object sender, EventArgs e)
    {
        Decimal Dec_KhatereId = Decimal.Parse(Grd_KhateratPermiss.SelectedDataKey.Value.ToString());
        LSC_KhateratDataContext db = new LSC_KhateratDataContext();
        try
        {
            tblKhateratPrivate tblKhat = db.tblKhateratPrivates.Single(n => n.RowID == Dec_KhatereId);
            db.tblKhateratPrivates.DeleteOnSubmit(tblKhat);
            db.SubmitChanges();
            Grd_KhateratPermiss.DataBind();
        }
        catch
        { }

    }
}