using System;
using System.Linq;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class AcceptNews : System.Web.UI.Page
{

    protected void grdFill()
    {
        FirstClass db = new FirstClass();
        DataTable dt = new DataTable();

        dt = db.dbOut(@"SELECT     tblKhaterat.NewsID, tblKhaterat.NewsTitle, tblKhaterehGroup.NewgGroupDescription, Users.UserName, 
                      Users.Name + N'  ' + Users.Sname AS Expr1, tblKhaterat.DateOfAdding, Users.EMail1 FROM tblKhaterat INNER JOIN
                      tblKhaterehGroup ON tblKhaterat.NewsGroupID = tblKhaterehGroup.NewsGroupID INNER JOIN
                      Users ON tblKhaterat.UserName = Users.UserName WHERE     (tblKhaterat.ShowPermiss = 0)");
        GridView1.DataSource = dt;
        GridView1.EmptyDataText = "هیچگونه ارسالی برای تائید موجود نمی باشد";
        GridView1.DataBind();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserName"] != null)
        {
            if (int.Parse(Session["UserTypeID"].ToString()) == 1)
            {
                grdFill();
            }
            else
            {
                Response.Redirect("Default.aspx?ID=NotHavePermission" + DateTime.Now.Ticks.ToString());
            }
        }
        else
        {
            Response.Redirect("Default.aspx?ID=NotHavePermission" + DateTime.Now.Ticks.ToString());
        }
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        String nwsEdtKey = GridView1.SelectedValue.ToString();
        LSC_KhateratDataContext db = new LSC_KhateratDataContext();
        tblKhaterat Khat = db.tblKhaterats.Single(n=> n.NewsID == int.Parse(nwsEdtKey));
        Khat.ShowPermiss = Boolean.Parse("True");

        db.SubmitChanges();
        grdFill();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        grdFill();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int nwsEdtKey = (int)GridView1.DataKeys[e.RowIndex].Value;
        LSC_KhateratDataContext db = new LSC_KhateratDataContext();
        tblKhaterat Khat = db.tblKhaterats.Single(n => n.NewsID == nwsEdtKey);

        db.tblKhaterats.DeleteOnSubmit(Khat);
        db.SubmitChanges();

        grdFill();
    }
}
