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

public partial class rl_admins_pg_AdminsList : System.Web.UI.Page
{
    //**********************************
    SqlConnection con;
    //**********************************
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            C_myClass.MenueItemsCreate(User, panelMenues);
            Label lblTitle = (Label)this.Master.FindControl("lblTitle");
            lblTitle.Text = "لیست کارمندان";
        }
        catch
        {
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "EditPress")
            {
                int adminId = Int32.Parse(e.CommandArgument.ToString());
                Response.Redirect("pg_EditAdmin.aspx?adminId=" + adminId.ToString() + "&returnUrl=pg_AdminsList.aspx");
            }
            else if (e.CommandName == "DeletePress")
            {
                try
                {
                    string conString = RamanConnectionString.LocalConnectionString();
                    con = new SqlConnection(conString);
                    con.Open();
                    SqlCommand cmd = con.CreateCommand();
                    int adminId = Int32.Parse(e.CommandArgument.ToString());
                    string userName = _UseFull.C_Usefull.FindStringWithIntegerShart(con, cmd, "t_Admins", "userName", "adminId", adminId);
                    cmd.CommandText = "delete from t_Admins Where adminId = " + adminId;
                    cmd.ExecuteNonQuery();
                    Membership.DeleteUser(userName, true);
                    GridView1.DataBind();
                }
                catch (Exception exc)
                {
                }
                finally
                {
                    con.Close();
                }
            }
        }
        catch
        {
        }
    }

    protected string FindImageUrl(object AdminId)
    {
        string url = "~/photoes/";
        string conString = RamanConnectionString.LocalConnectionString();
        SqlConnection con = new SqlConnection(conString);
        SqlCommand cmd = con.CreateCommand();
        string picUrl = "";
        try
        {
            int adminId = Int32.Parse(AdminId.ToString());
            con.Open();
            cmd.CommandText = "select adminPhotoUrl from t_Admins Where adminId = " + adminId;
            picUrl = (cmd.ExecuteScalar() != DBNull.Value ? cmd.ExecuteScalar().ToString() : "hhjg");
            string photoesFolderPath = Request.PhysicalApplicationPath + @"photoes\";
            if (!File.Exists(photoesFolderPath + picUrl))
            {
                picUrl = url + "noPersonalPhoto.gif";
            }
            else
            {
                picUrl = url + picUrl;
            }
        }
        catch
        {
            picUrl = "";
        }
        finally
        {
            if (con.State != ConnectionState.Closed)
                con.Close();
        }
        return picUrl;
    }
}
