protected void lbDelete_Click(object sender, EventArgs e)
 {
     try
     {
         bool bRemove = false;
         for (int i = 0; i < gvWidgets.Rows.Count; i++)
         {
             CheckBox cb = gvWidgets.Rows[i].FindControl("cb") as CheckBox;
             if (cb.Checked)
             {
                 Literal literal = gvWidgets.Rows[i].FindControl("WidgetID") as Literal;
                 if (literal != null)
                 {
                     int      iWidgetID = Convert.ToInt32(literal.Text);
                     BSWidget bsWidget  = BSWidget.GetWidget(iWidgetID);
                     bRemove = bsWidget != null && bsWidget.Remove();
                 }
             }
         }
         if (bRemove)
         {
             MessageBox1.Message = Language.Admin["WidgetDeleted"];
             MessageBox1.Type    = MessageBox.ShowType.Information;
             MessageBox1.Visible = true;
         }
         GetWidgets();
         GetAllWidgets();
     }
     catch (Exception ex)
     {
         MessageBox1.Message = ex.Message;
         MessageBox1.Type    = MessageBox.ShowType.Error;
     }
 }
    protected void btnSaveWidget_Click(object sender, EventArgs e)
    {
        try
        {
            BSWidget bsWidget = new BSWidget();
            bsWidget.Title       = txtTitle.Text;
            bsWidget.Description = tmceDescription.Content;
            bsWidget.Visible     = Convert.ToBoolean(ddlVisible.SelectedValue);
            bsWidget.PlaceHolder = ddlPlace.SelectedValue;

            MessageBox1.Type = MessageBox.ShowType.Error;

            if (Request["p"] != null && Request["p"] == "AddWidget")
            {
                bsWidget.Type = WidgetTypes.Page;
                if (bsWidget.Save())
                {
                    Response.Redirect("Widgets.aspx?Message=1");
                }
                else
                {
                    MessageBox1.Message = "Error";
                }
            }
            else
            {
                bsWidget = BSWidget.GetWidget(Convert.ToInt32(Request["WidgetID"]));

                if (!divWidgetContent.Visible)
                {
                    bsWidget.Description = string.Empty;
                }

                if (bsWidget.Save())
                {
                    Response.Redirect("Widgets.aspx?Message=1");
                }
                else
                {
                    MessageBox1.Message = "Error";
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox1.Message = ex.Message;
            MessageBox1.Type    = MessageBox.ShowType.Error;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string widget = Request["w"];

        if (!string.IsNullOrEmpty(widget))
        {
            widget = BSHelper.CreateCode(widget);
            BSWidget bsWidget = BSWidget.GetWidget(widget);
            if (bsWidget != null)
            {
                phWidget.Controls.Add(LoadControl("~/Widgets/" + bsWidget.FolderName + "/View.ascx"));
            }
            else if (BSTheme.Current.Widgets[widget] != null)
            {
                BSWidget w = BSTheme.Current.Widgets[widget];
                phWidget.Controls.Add(LoadControl(String.Format("~/Themes/{0}/Widgets/{1}/View.ascx", Blogsa.ActiveTheme, w.FolderName)));
            }
        }
    }
    private void VisibleUnVisible(bool bVisible)
    {
        try
        {
            bool bDone = false;
            for (int i = 0; i < gvWidgets.Rows.Count; i++)
            {
                CheckBox cb = gvWidgets.Rows[i].FindControl("cb") as CheckBox;
                if (cb.Checked)
                {
                    Literal literal = gvWidgets.Rows[i].FindControl("WidgetID") as Literal;
                    if (literal != null)
                    {
                        int iWidgetID = Convert.ToInt32(literal.Text);

                        BSWidget bsWidget = BSWidget.GetWidget(iWidgetID);
                        if (bsWidget != null)
                        {
                            bsWidget.Visible = bVisible;
                            bDone            = bsWidget.Save();
                        }
                    }
                }
            }
            if (bDone)
            {
                MessageBox1.Message = bVisible ? Language.Admin["BeActive"] : Language.Admin["BePassive"];
                MessageBox1.Type    = MessageBox.ShowType.Information;
                MessageBox1.Visible = true;
            }
            GetWidgets();
        }
        catch (Exception ex)
        {
            MessageBox1.Message = ex.Message;
            MessageBox1.Type    = MessageBox.ShowType.Error;
        }
    }
    protected void gvWidgets_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "UD")
            {
                string[] values = e.CommandArgument.ToString().Split('|');
                int      val    = -1;
                if (values[0] == "U")
                {
                    val = -1;
                }
                else
                {
                    val = +1;
                }

                int iWidgetID = Convert.ToInt32(values[1]);

                BSWidget bsWidget = BSWidget.GetWidget(iWidgetID);
                bsWidget.Sort += (short)val;

                if (bsWidget.Save())
                {
                    MessageBox1.Type    = MessageBox.ShowType.Error;
                    MessageBox1.Message = "Error";
                }
                GetWidgets();
            }
        }
        catch (Exception ex)
        {
            MessageBox1.Message = ex.Message;
            MessageBox1.Type    = MessageBox.ShowType.Error;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            GenerateHeaderButtons();
            if (!Page.IsPostBack)
            {
                GetWidgets();
                GetAllWidgets();

                ddlVisible.Items.Add(new ListItem(Language.Admin["Active"], "True"));
                ddlVisible.Items.Add(new ListItem(Language.Admin["Passive"], "False"));

                string fileName = Server.MapPath("~/Themes/" + Blogsa.Settings["theme"] + "/Settings.xml");
                string temp     = BSHelper.GetXmlSingleNodeValue(fileName, "//theme//places");
                if (temp.Trim() != "")
                {
                    string[] strPlaceHolders = temp.Split(',');
                    foreach (string t in strPlaceHolders)
                    {
                        ddlPlace.Items.Add(t);
                    }
                }
                else
                {
                    ddlPlace.Items.Add("Default");
                }

                if (Request["WidgetID"] != null)
                {
                    divEditWidget.Visible     = true;
                    divEditWidgetSide.Visible = true;

                    int iWidgetID = 0;
                    int.TryParse(Request["WidgetID"], out iWidgetID);

                    BSWidget bsWidget = BSWidget.GetWidget(iWidgetID);

                    if (bsWidget != null)
                    {
                        txtTitle.Text           = bsWidget.Title;
                        tmceDescription.Content = bsWidget.Description;
                        if (bsWidget.Type == WidgetTypes.Page)
                        {
                            divWidgetContent.Visible = true;
                        }

                        ddlVisible.SelectedValue = bsWidget.Visible.ToString();
                        ddlPlace.SelectedValue   = bsWidget.PlaceHolder;
                    }
                    else
                    {
                        Response.Redirect("Widgets.aspx");
                    }
                }
                else if (Request["p"] != null && Request["p"] == "AddWidget")
                {
                    divEditWidget.Visible     = true;
                    divEditWidgetSide.Visible = true;
                    divWidgetContent.Visible  = true;
                }
                else
                {
                    divWidgets.Visible     = true;
                    divWidgetsSide.Visible = true;
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox1.Message = ex.Message;
            MessageBox1.Type    = MessageBox.ShowType.Error;
        }
    }