public static bool AddNew(HDS_User Usr)
 {
     try
     {
         ExamSystemManagerDBEntities exMana = new ExamSystemManagerDBEntities();
         exMana.AddToHDS_User(Usr);
         exMana.SaveChanges();
     }
     catch (Exception e)
     {
         errMsg = e.Message;
         return false;
     }
     errMsg = "";
     return true;
 }
 protected void btnlogin_Click(object sender, EventArgs e)
 {
     string role = "";
     if (HDS_UserBL.checkLogin(txtUserName.Text, txtPassword.Text, ref role))
     {
         HDS_User user = new HDS_User();
         user = HDS_UserBL.getByUsername(txtUserName.Text);
         Session["srcImg"] = user.Usr_Avata;
         Session["ad_user"] = txtUserName.Text;
         Session["ad_role"] = role;
         Session["Emp_ID"] = user.Emp_ID;
         Response.Redirect("~/admin/Default.aspx");
     }
     else
     {
         lblMsg.Visible = true;
     }
 }
        protected void btnsave_Click(object sender, EventArgs e)
        {
            HDS_User user = new HDS_User();

            user.Usr_Avata=txtImg.Text;
            user.Usr_Username=txtUserName.Text;
            user.Emp_ID= Int32.Parse(ddlEmp.SelectedValue);
            user.Usr_Role=ddlRole.SelectedValue;
            string strid = txtid.Text;

            if (strid.Trim() == "")
            {
                user.Usr_ID = Int32.Parse(txtid.Text);
                if (HDS_UserBL.AddNew(user))
                {
                    ShowMessage(1, "Data added successfully !");
                    gridBind();
                }
                else
                {
                    ShowMessage(0, "Data added fail : " + HDS_UserBL.errMsg);
                }
            }
            else
            {
                user.Usr_ID = Int32.Parse(strid);
                if (HDS_UserBL.Update(user))
                {
                    ShowMessage(1, "Data updated successfully ! ");
                    gridBind();

                }
                else
                {
                    ShowMessage(0, "Data updated fail : " + HDS_UserBL.errMsg);
                }
            }

            pnlAddnew.Visible = false;
            pnlData.Visible = true;
        }
 public static bool Update(HDS_User Usr)
 {
     try
     {
         ExamSystemManagerDBEntities exMana = new ExamSystemManagerDBEntities();
         HDS_User obj = exMana.HDS_User.First(temp => temp.Usr_ID == Usr.Usr_ID);
         obj.Emp_ID = Usr.Emp_ID;
         obj.Usr_Username = Usr.Usr_Username;
         obj.Usr_Password = Usr.Usr_Password;
         obj.Usr_Role = Usr.Usr_Role;
         obj.Usr_Avata = Usr.Usr_Avata;
         exMana.SaveChanges();
     }
     catch (Exception e)
     {
         errMsg = e.Message;
         return false;
     }
     errMsg = "";
     return true;
 }
 protected void gridEmp_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     int strId = Int32.Parse(e.CommandArgument.ToString());
     HDS_User obj = new HDS_User();
     switch (e.CommandName)
     {
         case "cmdEdit":
             pnlAddnew.Visible = true;
             pnlData.Visible = false;
             pnlMessage.Visible = true;
             obj = HDS_UserBL.getById(strId);
             txtid.Text = strId.ToString();
             txtImg.Text = obj.Usr_Avata;
             txtUserName.Text = obj.Usr_Username;
             ddlEmp.SelectedValue = obj.Emp_ID.ToString();
             ddlRole.SelectedValue = obj.Usr_Role;
             break;
         case "cmdView":
             pnlAddnew.Visible = true;
             pnlData.Visible = false;
             pnlMessage.Visible = true;
             obj = HDS_UserBL.getById(strId);
             txtid.Text = strId.ToString();
             txtImg.Text = obj.Usr_Avata;
             txtUserName.Text = obj.Usr_Username;
             ddlEmp.SelectedValue = obj.Emp_ID.ToString();
             ddlRole.SelectedValue = obj.Usr_Role;
             break;
         case "cmdDelete":
             string cusrent_user = Session["ad_user"].ToString();
             string cusrent_role = Session["ad_role"].ToString();
             if (HDS_UserBL.Delete(strId, Session["ad_user"].ToString(), cusrent_role))
             {
                 ShowMessage(1, "Data deleted successfully ! ");
                 gridBind();
             }
             else
             {
                 ShowMessage(0, "Data deleted fail : " + HDS_UserBL.errMsg);
             }
             break;
         default:
             break;
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the HDS_User EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToHDS_User(HDS_User hDS_User)
 {
     base.AddObject("HDS_User", hDS_User);
 }
 /// <summary>
 /// Create a new HDS_User object.
 /// </summary>
 /// <param name="usr_ID">Initial value of the Usr_ID property.</param>
 public static HDS_User CreateHDS_User(global::System.Int32 usr_ID)
 {
     HDS_User hDS_User = new HDS_User();
     hDS_User.Usr_ID = usr_ID;
     return hDS_User;
 }