ProjectDetails.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:15k
- using System;
- using System.Web;
- using System.Web.UI.WebControls;
- using qminoa.BLL.PM;
- namespace qminoa.Webs.PM
- {
- public class ProjectDetails : qminoa.Webs.PageBase
- {
- public const string UserRoleNone = "0";
- public const string UserRoleAdministrator = "1";
- public const string UserRoleProjectManager = "2";
- public const string UserRoleConsultant = "3";
- protected System.Web.UI.WebControls.TextBox ProjectName;
- protected System.Web.UI.WebControls.TextBox Description;
- protected System.Web.UI.WebControls.TextBox CompletionDate;
- protected System.Web.UI.WebControls.TextBox Duration;
- protected System.Web.UI.WebControls.ListBox Members;
- protected System.Web.UI.WebControls.Button CopyButton;
- protected System.Web.UI.WebControls.Button AddButton;
- protected System.Web.UI.WebControls.Button SaveButton;
- protected System.Web.UI.WebControls.DropDownList Managers;
- protected System.Web.UI.WebControls.DropDownList Projects;
- protected System.Web.UI.WebControls.TextBox CategoryName;
- protected System.Web.UI.WebControls.TextBox Abbrev;
- protected System.Web.UI.WebControls.TextBox CatDuration;
- protected System.Web.UI.WebControls.DataGrid CategoriesGrid;
- protected System.Web.UI.WebControls.RequiredFieldValidator ProjectNameRequiredfieldvalidator;
- protected System.Web.UI.WebControls.RequiredFieldValidator ManagerRequiredFieldValidator;
- protected System.Web.UI.WebControls.CompareValidator CompletionDateCompareValidator;
- protected System.Web.UI.WebControls.RequiredFieldValidator CompletionDateRequiredFieldValidator;
- protected System.Web.UI.WebControls.CompareValidator DurationCompareValidator;
- protected System.Web.UI.WebControls.RequiredFieldValidator DurationRequiredFieldValidator;
- protected System.Web.UI.WebControls.CustomValidator ProjectsGridCustomValidator;
- protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidatorAbbrev;
- protected System.Web.UI.WebControls.CompareValidator CatDurationValidator;
- protected System.Web.UI.WebControls.CustomValidator AbbrevCustomValidator;
- protected System.Web.UI.WebControls.Button CancelButton;
- protected System.Web.UI.WebControls.Button CancelButton2;
- protected System.Web.UI.WebControls.Button CancelButton3;
- protected System.Web.UI.WebControls.Button DeleteButton;
- protected System.Web.UI.WebControls.Button DeleteButton2;
- protected System.Web.UI.WebControls.Button SaveButton2;
- protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
- protected System.Web.UI.WebControls.RangeValidator RangeValidator2;
- protected System.Web.UI.WebControls.Label CategoryErrorMessage;
- protected System.Web.UI.WebControls.Label ErrorMessage;
-
- private int _projID;
- private PMUser _user;
-
- private void Page_Load(object sender, System.EventArgs e)
- {
- this.PageBegin("项目管理",true);
- _user = new PMUser(Convert.ToInt16(this.Empid));
- if(_user.Role == UserRoleConsultant || _user.Role == UserRoleNone)
- {
- Response.Redirect(Application["vRoot"]+"/login.aspx");
- }
- _projID = (Request.QueryString["id"]==null) ? 0 : Convert.ToInt32(Request.QueryString["id"]);
- if (!IsPostBack)
- {
- Session["catArray"] = new CategoriesCollection();
- BindManagers();
- BindMembers();
- BindOtherProjects();
- if (_projID != 0)
- BindProject();
- }
- DeleteButton.Attributes.Add("onclick", "return confirm('删除该项目将删除和该项目相关的进程信息和进程日志信息,确定要删除吗?')");
- DeleteButton2.Attributes.Add("onclick", "return confirm('删除该项目将删除和该项目相关的进程信息和进程日志信息,确定要删除吗?')");
- }
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
-
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
- this.CancelButton.Click += new System.EventHandler(this.CancelButton_Click);
- this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
- this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
- this.AbbrevCustomValidator.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.AbbrevCustomValidator_ServerValidate);
- this.CopyButton.Click += new System.EventHandler(this.CopyButton_Click);
- this.CategoriesGrid.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.CategoriesGrid_ItemCreated);
- this.CategoriesGrid.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.CategoriesGrid_Sort);
- this.ProjectsGridCustomValidator.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.ValidateCategories);
- this.SaveButton2.Click += new System.EventHandler(this.SaveButton_Click);
- this.CancelButton2.Click += new System.EventHandler(this.CancelButton_Click);
- this.DeleteButton2.Click += new System.EventHandler(this.DeleteButton_Click);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void BindManagers()
- {
- Managers.DataSource = PMUser.ListManagers();
- Managers.DataValueField = "UserID";
- Managers.DataTextField = "UserName";
- Managers.DataBind();
- Managers.Items.Insert(0, new ListItem("选择项目经理...", String.Empty));
- }
- private void BindMembers()
- {
- Members.DataSource = PMUser.GetAllUsers(_user.UserID);
- Members.DataValueField = "UserID";
- Members.DataTextField = "UserName";
- Members.DataBind();
- }
- private void BindOtherProjects()
- {
- Projects.DataSource = Project.GetProjects();
- Projects.DataTextField = "Name";
- Projects.DataValueField = "ProjectID";
- Projects.DataBind();
- Projects.Items.Remove(Projects.Items.FindByValue(_projID.ToString()));
- if (Projects.Items.Count == 0)
- CopyButton.Enabled = false;
- }
- private void BindProject()
- {
- Project project = new Project(_projID);
- project.Load();
- ProjectName.Text = project.Name;
- Description.Text = project.Description;
- CompletionDate.Text = project.EstCompletionDate.ToShortDateString();
- Duration.Text = project.EstDuration.ToString();
- Managers.Items.FindByValue(project.ManagerUserID.ToString()).Selected = true;
- foreach (PMUser user in project.Members)
- {
- Members.Items.FindByValue(user.UserID.ToString()).Selected = true;
- }
- BindCategoriesGrid(project.Categories);
- }
- private void BindCategoriesGrid(CategoriesCollection cats)
- {
- SortGridData(cats, SortField, SortAscending);
- CategoriesGrid.DataSource = cats;
- CategoriesGrid.DataBind();
- Session["catArray"] = cats;
- }
- private void ReturnToProjectList()
- {
- Session["catArray"] = null;
- Response.Redirect("ProjectList.aspx", false);
- }
- private void SortGridData(CategoriesCollection list, string sortField, bool asc)
- {
- CategoriesCollection.CategoryFields sortCol = CategoriesCollection.CategoryFields.InitValue;
- switch(sortField)
- {
- case "Name":
- sortCol = CategoriesCollection.CategoryFields.Name;
- break;
- case "Abbrev":
- sortCol = CategoriesCollection.CategoryFields.Abbreviation;
- break;
- case "Duration":
- sortCol = CategoriesCollection.CategoryFields.Duration;
- break;
- }
- list.Sort(sortCol, asc);
- }
- private void CancelButton_Click(object sender, System.EventArgs e)
- {
- ReturnToProjectList();
- }
- private void DeleteButton_Click(object sender, System.EventArgs e)
- {
- Project.Remove(_projID);
- ReturnToProjectList();
- }
- private void SaveButton_Click(object sender, System.EventArgs e)
- {
- Members.Items.FindByValue(Managers.SelectedItem.Value).Selected = true;
- ProjectsGridCustomValidator.Validate();
- if (!ProjectsGridCustomValidator.IsValid)
- return;
- AbbrevCustomValidator.Validate();
- if (!AbbrevCustomValidator.IsValid)
- return;
- CategoriesCollection catArray = (CategoriesCollection)Session["catArray"];
- UsersCollection selectedMembers = new UsersCollection();
- foreach (ListItem li in Members.Items)
- {
- if (li.Selected)
- {
- PMUser user = new PMUser();
- user.UserID = Convert.ToInt32(li.Value);
- selectedMembers.Add(user);
- }
- }
- Project prj = new Project(
- _projID,
- ProjectName.Text,
- Description.Text,
- Convert.ToInt32(Managers.SelectedItem.Value),
- Convert.ToDateTime(CompletionDate.Text),
- Convert.ToDecimal(Duration.Text)
- );
- prj.Categories = catArray;
- prj.Members = selectedMembers;
-
- if (prj.Save())
- {
- ReturnToProjectList();
- }
- else
- {
- ErrorMessage.Text = "产生一个错误,你不能去除已经参与该项目进程的成员!";
- }
- }
- private void AddButton_Click(object sender, System.EventArgs e)
- {
- if (!AbbrevCustomValidator.IsValid)
- return;
- if (CategoryName.Text == "")
- {
- CategoryErrorMessage.Text = "Category name is required.";
- return;
- }
- if (Abbrev.Text == "")
- {
- CategoryErrorMessage.Text = "Category abbreviation is required.";
- return;
- }
- CategoriesCollection catArray = (CategoriesCollection)Session["catArray"];
- if (catArray == null)
- catArray = new CategoriesCollection();
- int catID = (Session["catID"] != null) ? (Convert.ToInt32(Session["catID"]) - 1) : -1;
- Session["catID"] = catID;
- Category cat = new Category();
- cat.CategoryID = catID;
- cat.Name = CategoryName.Text;
- cat.Abbreviation = Abbrev.Text;
- cat.EstDuration = (CatDuration.Text.Length==0) ? 0 : Convert.ToDecimal(CatDuration.Text);
- catArray.Add(cat);
- ProjectsGridCustomValidator.Validate();
- BindCategoriesGrid(catArray);
- CategoryName.Text = string.Empty;
- Abbrev.Text = string.Empty;
- CatDuration.Text = string.Empty;
- }
- private void CopyButton_Click(object sender, System.EventArgs e)
- {
- int catID;
- CategoriesCollection catArray = (CategoriesCollection)Session["catArray"];
- if (catArray == null)
- catArray = new CategoriesCollection();
- CategoriesCollection projcatArray = Project.GetCategories(Convert.ToInt32(Projects.SelectedItem.Value));
- foreach (Category cat in projcatArray)
- {
- catID = (Session["catID"] != null) ? (Convert.ToInt32(Session["catID"]) + 1) : 1;
- Session["catID"] = catID;
- cat.CategoryID = catID;
- catArray.Add(cat);
- }
- ProjectsGridCustomValidator.Validate();
- Session["catArray"] = catArray;
- BindCategoriesGrid(catArray);
- }
- protected void CategoriesGrid_OnDelete(Object sender, DataGridCommandEventArgs e)
- {
- int catID = Convert.ToInt32(CategoriesGrid.DataKeys[(int)e.Item.ItemIndex]);
- CategoriesCollection catArray = (CategoriesCollection)Session["catArray"];
- for (int i = 0;i < catArray.Count;i++)
- {
- if (((Category)catArray[i]).CategoryID == catID)
- {
- catArray.RemoveAt(i);
- }
- }
- BindCategoriesGrid(catArray);
- }
- protected void CategoriesGrid_OnCancel(Object sender, DataGridCommandEventArgs e)
- {
- CategoriesGrid.EditItemIndex = -1;
- BindCategoriesGrid((CategoriesCollection)Session["catArray"]);
- }
- protected void CategoriesGrid_OnUpdate(Object sender, DataGridCommandEventArgs e)
- {
- Category editCat = new Category();
- editCat.CategoryID = Convert.ToInt32(CategoriesGrid.DataKeys[(int)e.Item.ItemIndex]);
- editCat.Name = ((TextBox) e.Item.FindControl("EditName")).Text;
- editCat.Abbreviation = ((TextBox) e.Item.FindControl("EditAbbreviation")).Text;
- editCat.EstDuration = Convert.ToDecimal(((TextBox) e.Item.FindControl("EditDuration")).Text);
- CategoriesCollection catArray = (CategoriesCollection)Session["catArray"];
- if (catArray != null)
- {
- string editAbbrev = ((TextBox) e.Item.FindControl("EditAbbreviation")).Text;
- foreach (Category cat in catArray)
- {
- if (cat.Abbreviation == editCat.Abbreviation && cat.CategoryID != editCat.CategoryID)
- {
- CategoryErrorMessage.Text = "项目进程简称不能重复!";
- return;
- }
- }
- }
- CategoriesCollection catNew = new CategoriesCollection();
- catNew.Add(editCat);
- if (catArray == null)
- catArray = new CategoriesCollection();
- foreach (Category cat in catArray)
- {
- if (cat.CategoryID != editCat.CategoryID)
- {
- catNew.Add(cat);
- }
- }
- CategoriesGrid.EditItemIndex = -1;
- BindCategoriesGrid(catNew);
- }
-
- protected void CategoriesGrid_OnEdit(Object sender, DataGridCommandEventArgs e)
- {
- CategoriesGrid.EditItemIndex = e.Item.ItemIndex;
- BindCategoriesGrid((CategoriesCollection)Session["catArray"]);
- }
- private void CategoriesGrid_Sort(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
- {
- SortField = e.SortExpression;
- BindCategoriesGrid((CategoriesCollection)Session["catArray"]);
- }
- private void ValidateCategories(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
- {
- CategoriesCollection catArray = (CategoriesCollection)Session["catArray"];
- if (catArray != null)
- {
- if (catArray.Count > 0)
- {
- args.IsValid = true;
- return;
- }
- }
- args.IsValid = false;
- }
- private void AbbrevCustomValidator_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
- {
- CategoriesCollection catArray = (CategoriesCollection)Session["catArray"];
- if (catArray.Count != 0)
- {
- catArray.Sort(CategoriesCollection.CategoryFields.Abbreviation, true);
- for(int i=0; i < catArray.Count; i++)
- {
- if (((Category)catArray[i]).Abbreviation == Abbrev.Text)
- {
- args.IsValid = false;
- return;
- }
- if (i!=0 && ((Category)catArray[i]).Abbreviation == ((Category)catArray[i-1]).Abbreviation )
- {
- args.IsValid = false;
- return;
- }
-
- }
-
-
- }
- args.IsValid = true;
- }
- private void CategoriesGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
- {
- if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
- {
- ((ImageButton)e.Item.FindControl("CatDeleteButton")).Attributes.Add("onclick", "return confirm('删除此条项目进程将删除相关的进程日志或进程信息,确认在删除吗?')");
- }
- }
- string SortField
- {
- get
- {
- object o = ViewState["SortField"];
- if (o == null)
- {
- return String.Empty;
- }
- return (string)o;
- }
- set
- {
- if (value == SortField)
- {
- SortAscending = !SortAscending;
- }
- ViewState["SortField"] = value;
- }
- }
- bool SortAscending
- {
- get
- {
- object o = ViewState["SortAscending"];
- if (o == null)
- {
- return true;
- }
- return (bool)o;
- }
- set
- {
- ViewState["SortAscending"] = value;
- }
- }
- }
- }