protected void ShowData(string strFindStaff = "")
        {
            List <Staff> staffs = _db.Staffs.Include(s => s.Position).Where(s => s.FullName.Contains(strFindStaff)).ToList();

            GridViewStaff.DataSource = staffs;
            GridViewStaff.DataBind();
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (MasterDbContext db = new MasterDbContext())
            {
                if (Session["logined"] != null)
                {
                    DataTable     data = new DataTable();
                    SqlConnection con  = new SqlConnection(ConfigurationManager.ConnectionStrings["MasterDbContext"].ToString());

                    //find current user
                    int idUser = Convert.ToInt32(Session["logined"].ToString());;
                    var user   = db.Employees.Find(idUser);
                    if (user.Name != "Admin")
                    {
                        tagCreate.Visible = false;
                    }



                    try
                    {
                        con.Open();
                        string[] selectedCol = new string[] {
                            "st.ID AS ID",
                            "st.Name AS 'Name'",
                            "st.Phone AS 'Phone'",
                            "st.Address AS 'Address'",
                            "pos.Value AS 'Position'",
                            "st.Salary AS 'Salary'",
                            "st.CreatedTime AS 'Created Time'",
                            "st.UpdatedTime AS 'Updated Time'",
                        };
                        string         query   = "select " + String.Join(",", selectedCol) + " from Employees st INNER JOIN Positions pos ON st.PositionID = pos.ID where st.Active = 1";
                        SqlCommand     cmd     = new SqlCommand(query, con);
                        SqlDataAdapter adapter = new SqlDataAdapter(cmd);

                        adapter.Fill(data);

                        GridViewStaff.DataSource = data;
                        GridViewStaff.DataBind();
                    }
                    catch
                    {
                    }
                    finally
                    {
                        con.Close();
                    }
                }
                else
                {
                    Response.Redirect("~/Login.aspx");
                }
            }
        }
Beispiel #3
0
 private void BindData()
 {
     GridViewStaff.DataSource = Session["DSList"];
     GridViewStaff.DataBind();
 }