Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Request.IsAuthenticated)
            {
                Response.Redirect("~/Login.aspx");
            }

            else
            {
                int sect_id = Convert.ToInt32(RouteData.Values["sect_id"]);
                if (!IsPostBack)
                {
                    if (sect_id > 0)  // if there is a section id
                    {
                        lbtnUpdate.Text = "Update";
                        SectionCS mt = new SectionCS(sect_id);
                        txtName.Text        = mt.Sect_Name;
                        txtDescription.Text = mt.Sect_Desc;
                        chkIsActive.Checked = mt.Sect_Active;
                    }
                    else  // if no section id go to add
                    {
                        lbtnUpdate.Text     = "Add";
                        txtName.Text        = String.Empty;
                        txtDescription.Text = String.Empty;
                        chkIsActive.Checked = false;
                    }
                }
            }
        }
Esempio n. 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int       sect_id = Convert.ToInt32(RouteData.Values["sect_id"]);
            SectionCS mt      = new SectionCS(sect_id);

            lblSect_ID.Text     = String.Concat("Sect_ID: ", mt.Sect_ID).ToString();
            lblSect_Name.Text   = String.Concat("Sect_Name: ", mt.Sect_Name).ToString();
            lblSect_Desc.Text   = String.Concat("Sect_Desc: ", mt.Sect_Desc).ToString();
            lblSect_Active.Text = String.Concat("Sect_Active: ", mt.Sect_Active).ToString();
        }
Esempio n. 3
0
        public static bool UpdateSectionItems(SectionCS sr)
        {
            //declare return variable
            bool blnSuccess = false;
            //connection object -> ConfigurationManager namespace
            //access web.config setting -> connection strings & key values
            SqlConnection cn = new SqlConnection(
                ConfigurationManager.ConnectionStrings["SE256_MurilloConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("sections_update", cn);

            // Mark the Command -> Stored Procedure
            cmd.CommandType = CommandType.StoredProcedure;

            // Add Parameters -> Stored Procedure
            cmd.Parameters.Add(
                "@sect_id", SqlDbType.Int).Value = sr.Sect_ID;
            cmd.Parameters.Add(
                "@sect_name", SqlDbType.VarChar).Value = sr.Sect_Name;
            cmd.Parameters.Add(
                "@sect_desc", SqlDbType.VarChar).Value = sr.Sect_Desc;
            cmd.Parameters.Add(
                "@sect_active", SqlDbType.Bit).Value = sr.Sect_Active;

            // Open database connection -> execute command
            try
            {
                cn.Open();
                cmd.ExecuteNonQuery();
                blnSuccess = true;
            }
            catch (Exception exc)
            {
                //error -> notify user
                exc.ToString();
                blnSuccess = false;
            }
            finally
            {
                cn.Close();
            }
            return(blnSuccess);
        }
Esempio n. 4
0
        protected void lbtnUpdate_Click(object sender, EventArgs e)
        {
            string updateBUTTON = lbtnUpdate.Text;

            if (updateBUTTON == "Update")
            {
                SectionCS sr = new SectionCS();
                if (RouteData.Values["sect_id"] != null)
                {
                    bool success = false;
                    sr.Sect_ID     = Convert.ToInt32(RouteData.Values["sect_id"]);
                    sr.Sect_Name   = txtName.Text.Trim();
                    sr.Sect_Desc   = txtDescription.Text.Trim();
                    sr.Sect_Active = chkIsActive.Checked;

                    success = SectionCS.UpdateSectionItems(sr);

                    if (success)  // if update section is true
                    {
                        Response.Redirect("/Admin/Sections");
                    }
                }
            }

            else  // insert section
            {
                bool      success = false;
                SectionCS sr      = new SectionCS();
                sr.Sect_ID     = Convert.ToInt32(RouteData.Values["sect_id"]);
                sr.Sect_Name   = txtName.Text.Trim();
                sr.Sect_Desc   = txtDescription.Text.Trim();
                sr.Sect_Active = chkIsActive.Checked;

                success = SectionCS.InsertSectionItem(sr);

                if (success)  // if insert section is true
                {
                    Response.Redirect("/Admin/Sections");
                }
            }
        }