protected void btnsave_Click(object sender, EventArgs e)
        {
            string        CS    = ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;
            SqlConnection con   = new SqlConnection(CS);
            string        query = "Insert Into tblProducts Values(@productname,@quantity,@cp,@sp,@category)";
            SqlCommand    cmd   = new SqlCommand(query, con);

            cmd.Parameters.AddWithValue("productname", TxtProductName.Text.Trim());
            cmd.Parameters.AddWithValue("quantity", txtQuantity.Text.Trim());
            cmd.Parameters.AddWithValue("cp", txtcostprice.Text.Trim());
            cmd.Parameters.AddWithValue("sp", txtsellingprice.Text.Trim());

            cmd.Parameters.AddWithValue("category", txtQuantity.Text.Trim());
            bool olu;

            con.Open();
            olu = Convert.ToBoolean(cmd.ExecuteNonQuery());
            if (olu)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Message", "alert('Product Was Added Successfully')", true);
                Handler.Load("Select ProductName, Quantity, CostPrice, SellingPrice from tblProducts", GridviewProducts);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Message", "alert('There was an error, nothing was saved')", true);
                Handler.Load("Select ProductName, Quantity, CostPrice, SellingPrice from tblProducts", GridviewProducts);
            }
        }
        protected void btnadd_Click(object sender, EventArgs e)
        {
            string CS = ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;

            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlCommand cmd = new SqlCommand("Select CategoryName from tblCategory Where CategoryName =@categoryname", con);
                cmd.Parameters.AddWithValue("@categoryname", txtcategory.Text.Trim());

                con.Open();

                SqlDataReader dr = cmd.ExecuteReader();

                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        string categoryname = dr["CategoryName"].ToString();

                        if (txtcategory.Text == categoryname)
                        {
                            Lblresponse.ForeColor = System.Drawing.Color.Red;
                            Lblresponse.Text      = "There is already a category with this name.";
                        }
                    }
                }
                else
                {
                    Handler.Addcategory(txtcategory.Text, Lbluser);
                    Handler.Load("Select * from tblCategory", Gridview1);
                }
            }
        }
 protected void btncancel_Click(object sender, EventArgs e)
 {
     GridviewUpload.DataSource = null;
     GridviewUpload.DataBind();
     GridviewUpload.Visible   = false;
     GridviewProducts.Visible = true;
     btnupload.Text           = "Upload";
     lblupload.ForeColor      = System.Drawing.Color.Blue;
     lblupload.Text           = "Upload Multiple Product";
     btncancel.Visible        = false;
     Handler.Load("Select ProductName, Quantity, CostPrice, SellingPrice from tblProducts", GridviewProducts);
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         Handler.Load("Select * from tblCategory", Gridview1);
         LinkLogout.CausesValidation = false;
         if (User.Identity.IsAuthenticated)
         {
             Lbluser.Text = User.Identity.Name;
         }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            // get all user form the database

            if (!IsPostBack)
            {
                Handler.Load("Select Username, Email, Role, Locked, LastLoginDate from tblUsers", Gridview1);
                if (User.Identity.IsAuthenticated)
                {
                    Linklogout.CausesValidation = false;
                    Lbluser.Text = User.Identity.Name;
                    // ...
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtprofit.Text       = "0";
                txtcostprice.Text    = "0";
                txtsellingprice.Text = "0";

                GridviewProducts.EnableSortingAndPagingCallbacks = false;

                Handler.Load("Select ProductName, Quantity, CostPrice, SellingPrice from tblProducts", GridviewProducts);

                //Handler.FillDropdowunList("Select ProductName from tblProducts", dropdowncategory, "ProductName");
                Handler.FillDropdowunList("Select CategoryName from tblCategory", dropdowncategory, "CategoryName");

                if (User.Identity.IsAuthenticated)
                {
                    LinkLogout.CausesValidation = false;
                    Lbluser.Text = User.Identity.Name;
                    // ...
                }
            }
        }
        protected void btnadduser_Click(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                if (Page.IsValid)
                {
                    // Add user to database
                    string CS = ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;
                    using (SqlConnection con = new SqlConnection(CS))
                    {
                        SqlCommand cmd = new SqlCommand("Select Username, Email from tblUsers Where Username =@username or Email =@email", con);
                        cmd.Parameters.AddWithValue("@username", Txtusername.Text.Trim());
                        cmd.Parameters.AddWithValue("@email", Txtemail.Text.Trim());

                        con.Open();

                        SqlDataReader dr = cmd.ExecuteReader();

                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                string username = dr["Username"].ToString();
                                string email    = dr["Email"].ToString();

                                if (Txtusername.Text == username)
                                {
                                    Lblresponse.ForeColor = System.Drawing.Color.Red;
                                    Lblresponse.Text      = "Username already in use. Please choose a different one";
                                }

                                if (Txtemail.Text == email)
                                {
                                    Lblresponse.ForeColor = System.Drawing.Color.Red;
                                    Lblresponse.Text      = "Email already in use. Please choose a different one";
                                }
                            }
                        }
                        else
                        {
                            Handler.SaveUser(Txtusername.Text, txtpassword.Text, Txtemail.Text, txtrole.SelectedItem.Text, Lblresponse);
                            Handler.Load("Select Username, Email, Role, Locked, LastLoginDate from tblUsers", Gridview1);

                            using (SqlConnection conn = new SqlConnection(CS))
                            {
                                cmd = new SqlCommand("Select Id from tblUsers Where Username =@username", conn);
                                cmd.Parameters.AddWithValue("@username", Txtusername.Text.Trim());

                                conn.Open();

                                dr = cmd.ExecuteReader();
                                string Uid;
                                if (dr.HasRows)
                                {
                                    while (dr.Read())
                                    {
                                        Uid = dr["Id"].ToString();

                                        Handler.AddProfile(Uid);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }