Exemple #1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                var dataAccess = new HeroicData();
                var result     = dataAccess.ExecuteNonQuery(
                    query: "DELETE FROM [User] WHERE ID = @id;",
                    parameters: new List <HeroicData.Parameters>
                {
                    new HeroicData.Parameters {
                        Name = "@id", Value = hidID.Value
                    }
                });

                if (result == 0)
                {
                    lbl.Text    = "Record not deleted";
                    lbl.Visible = true;
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            catch (Exception ex)
            {
                lbl.Text    = "Something went wrong, Message: " + ex.Message;
                lbl.Visible = true;
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var id = string.IsNullOrEmpty(Request.QueryString["id"]) ? 0 : Convert.ToInt32(Request.QueryString["id"]);
                if (id == 0)
                {
                    Response.Redirect("~/Default.aspx");
                }

                var dataAccess = new HeroicData();
                var user       = dataAccess.ExecuteTable <User>(
                    query: "SELECT * FROM [User] WHERE ID = @id",
                    parameters: new List <HeroicData.Parameters>
                {
                    new HeroicData.Parameters {
                        Name = "@id", Value = id
                    }
                }).FirstOrDefault();

                if (user == null)
                {
                    Response.Redirect("~/Default.aspx");
                }

                hidID.Value      = user.ID.ToString();
                txtUserName.Text = user.UserName;
                txtPassword.Text = user.Password;
                txtEmail.Text    = user.Email;
                txtMobile.Text   = user.Mobile;
            }
        }
Exemple #3
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                var dataAccess = new HeroicData();
                var result     = dataAccess.ExecuteNonQuery(
                    query: "UPDATE [User] SET UserName = @userName, Email = @email, Mobile = @mobile, Password = @password WHERE ID = @id;",
                    parameters: new List <HeroicData.Parameters>
                {
                    new HeroicData.Parameters {
                        Name = "@id", Value = hidID.Value
                    },
                    new HeroicData.Parameters {
                        Name = "@userName", Value = txtUserName.Text
                    },
                    new HeroicData.Parameters {
                        Name = "@email", Value = txtEmail.Text
                    },
                    new HeroicData.Parameters {
                        Name = "@mobile", Value = txtMobile.Text
                    },
                    new HeroicData.Parameters {
                        Name = "@password", Value = txtPassword.Text
                    },
                });

                if (result == 0)
                {
                    lbl.Text    = "Record not updated";
                    lbl.Visible = true;
                }
                else
                {
                    Response.Redirect("~/Default.aspx");
                }
            }
            catch (Exception ex)
            {
                lbl.Text    = "Something went wrong, Message: " + ex.Message;
                lbl.Visible = true;
            }
        }
Exemple #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var heroicData = new HeroicData();

                //var dataAccess = new DataAccess(connectionString: "YOUR_CONNECTION_STRING");

                //this.lv.DataSource = dataAccess.ExecuteTable<User>("SELECT * FROM [User]");
                //this.lv.DataBind();

                var users = heroicData.ExecuteTable("SELECT * FROM [User]");
                var count = heroicData.ExecuteScalar("SELECT COUNT(*) FROM [User]");

                litCount.Text = $"Showing {count} entries";

                this.lv.DataSource = users;
                this.lv.DataBind();
            }
        }
Exemple #5
0
        protected void txtSearch_TextChanged(object sender, EventArgs e)
        {
            var heroicData = new HeroicData();

            var dataSet = heroicData.ExecuteStoredProcedure(
                name: "usp_SearchUser",
                parameters: new List <HeroicData.Parameters>
            {
                new HeroicData.Parameters {
                    Name = "@search", Value = txtSearch.Text
                }
            }
                );

            var users       = heroicData.ToList <User>(dataSet.Tables[0]);
            var filterCount = Convert.ToInt32(dataSet.Tables[1].Rows[0][0]);
            var totalCount  = Convert.ToInt32(dataSet.Tables[2].Rows[0][0]);

            litCount.Text = $"Showing {filterCount} of {totalCount} entries";

            this.lv.DataSource = users;
            this.lv.DataBind();
        }