projectresolutions.ascx.cs

来自「BugNET is an issue tracking and project 」· CS 代码 · 共 270 行

CS
270
字号
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BugNET.UserInterfaceLayer;
using BugNET.UserControls;
using BugNET.BusinessLogicLayer;

namespace BugNET.Administration.Projects.UserControls
{
    public partial class ProjectResolutions : System.Web.UI.UserControl, IEditProjectControl
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, System.EventArgs e)
        { }

        #region IEditProjectControl Members

        private int _ProjectId = -1;


        /// <summary>
        /// Gets or sets the project id.
        /// </summary>
        /// <value>The project id.</value>
        public int ProjectId
        {
            get { return _ProjectId; }
            set { _ProjectId = value; }
        }

        /// <summary>
        /// Inits this instance.
        /// </summary>
        public void Initialize()
        {
            BindResolutions();
            lstImages.Initialize();
        }

        /// <summary>
        /// Updates this instance.
        /// </summary>
        /// <returns></returns>
        public bool Update()
        {
            if (Page.IsValid)
                return true;
            else
                return false;
        }

        #endregion

        /// <summary>
        /// Binds the milestones.
        /// </summary>
        private void BindResolutions()
        {
            grdResolutions.DataSource = Resolution.GetResolutionsByProjectId(ProjectId);
            grdResolutions.DataKeyField = "Id";
            grdResolutions.DataBind();

            if (grdResolutions.Items.Count == 0)
                grdResolutions.Visible = false;
            else
                grdResolutions.Visible = true;
        }


        /// <summary>
        /// Deletes the milestone.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void DeleteResolution(Object s, DataGridCommandEventArgs e)
        {
            int mileStoneId = (int)grdResolutions.DataKeys[e.Item.ItemIndex];

            if (!Resolution.DeleteResolution(mileStoneId))
                lblError.Text = "Could not delete Resolution";
            else
                BindResolutions();
        }

        /// <summary>
        /// Handles the Click event of the cmdCancel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected void cmdCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Administration/Projects/EditProject.aspx?id=" + ProjectId.ToString());
        }

        /// <summary>
        /// Handles the Validate event of the ResolutionValidation control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.Web.UI.WebControls.ServerValidateEventArgs"/> instance containing the event data.</param>
        protected void ResolutionValidation_Validate(object sender, ServerValidateEventArgs e)
        {
            //validate that at least one Resolution exists.
            if (Resolution.GetResolutionsByProjectId(ProjectId).Count > 0)
            {
                e.IsValid = true;
            }
            else
            {
                e.IsValid = false;
            }

        }

        /// <summary>
        /// Handles the Edit event of the grdResolutions control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdResolutions_Edit(object sender, DataGridCommandEventArgs e)
        {
            grdResolutions.EditItemIndex = e.Item.ItemIndex;
            grdResolutions.DataBind();
        }

        /// <summary>
        /// Handles the Update event of the grdResolutions control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdResolutions_Update(object sender, DataGridCommandEventArgs e)
        {
            Resolution m = Resolution.GetResolutionById(Convert.ToInt32(grdResolutions.DataKeys[e.Item.ItemIndex]));
            TextBox txtResolutionName = (TextBox)e.Item.FindControl("txtResolutionName");
            PickImage pickimg = (PickImage)e.Item.FindControl("lstEditImages");

            m.Name = txtResolutionName.Text.Trim();
            m.ImageUrl = pickimg.SelectedValue;
            m.Save();

            grdResolutions.EditItemIndex = -1;
            BindResolutions();

        }

        /// <summary>
        /// Handles the Cancel event of the grdResolutions control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdResolutions_Cancel(object sender, DataGridCommandEventArgs e)
        {
            grdResolutions.EditItemIndex = -1;
            grdResolutions.DataBind();
        }
        /// <summary>
        /// Handles the ItemDataBound event of the grdResolutions control.
        /// </summary>
        /// <param name="s">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridItemEventArgs"/> instance containing the event data.</param>
        protected void grdResolutions_ItemDataBound(Object s, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Resolution currentResolution = (Resolution)e.Item.DataItem;

                Label lblResolutionName = (Label)e.Item.FindControl("lblResolutionName");
                lblResolutionName.Text = currentResolution.Name;

                ImageButton UpButton = (ImageButton)e.Item.FindControl("MoveUp");
                ImageButton DownButton = (ImageButton)e.Item.FindControl("MoveDown");
                UpButton.CommandArgument = currentResolution.Id.ToString();
                DownButton.CommandArgument = currentResolution.Id.ToString();

                System.Web.UI.WebControls.Image imgResolution = (System.Web.UI.WebControls.Image)e.Item.FindControl("imgResolution");
                if (currentResolution.ImageUrl == String.Empty)
                {
                    imgResolution.Visible = false;
                }
                else
                {
                    imgResolution.ImageUrl = "~/Images/Resolution/" + currentResolution.ImageUrl;
                    imgResolution.AlternateText = currentResolution.Name;
                }

                Button btnDelete = (Button)e.Item.FindControl("btnDelete");
                btnDelete.Attributes.Add("onclick", String.Format("return confirm('Are you sure you want to delete the \"{0}\" Resolution?');", currentResolution.Name));
            }
            if (e.Item.ItemType == ListItemType.EditItem)
            {
                Resolution currentResolution = (Resolution)e.Item.DataItem;
                TextBox txtResolutionName = (TextBox)e.Item.FindControl("txtResolutionName");
                PickImage pickimg = (PickImage)e.Item.FindControl("lstEditImages");

                txtResolutionName.Text = currentResolution.Name;
                pickimg.Initialize();
                pickimg.SelectedValue = currentResolution.ImageUrl;
            }
        }

        /// <summary>
        /// Adds the milestone.
        /// </summary>
        /// <param name="s">The s.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void AddResolution(Object s, EventArgs e)
        {

            string newName = txtName.Text.Trim();

            if (newName == String.Empty)
                return;

            Resolution newResolution = new Resolution(ProjectId, newName, lstImages.SelectedValue);
            if (newResolution.Save())
            {
                txtName.Text = "";
                BindResolutions();
                lstImages.SelectedValue = String.Empty;
            }
            else
            {
                lblError.Text = "Could not save Resolution";
            }
        }


        /// <summary>
        /// Handles the ItemCommand event of the grdResolutions control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.DataGridCommandEventArgs"/> instance containing the event data.</param>
        protected void grdResolutions_ItemCommand(object sender, DataGridCommandEventArgs e)
        {
            Resolution m;
            int itemIndex = e.Item.ItemIndex;
            switch (e.CommandName)
            {
                case "up":
                    //move row up
                    if (itemIndex == 0)
                        return;
                    m = Resolution.GetResolutionById(Convert.ToInt32(e.CommandArgument));
                    m.SortOrder -= 1;
                    m.Save();

                    break;
                case "down":
                    //move row down
                    if (itemIndex == grdResolutions.Items.Count - 1)
                        return;
                    m = Resolution.GetResolutionById(Convert.ToInt32(e.CommandArgument));
                    m.SortOrder += 1;
                    m.Save();
                    break;
            }
            BindResolutions();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?