TimeEntry.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:17k
- using System;
- using System.Collections;
- using System.Data;
- using System.Text;
- using System.Web.UI.WebControls;
- using qminoa.BLL;
- using qminoa.Common.Data;
- using qminoa.BLL.PM;
- using qminoa.DA;
- namespace qminoa.Webs.PM
- {
- public class TimeEntry : qminoa.Webs.PageBase
- {
- protected qminoa.BLL.PM.TimeEntry _userInput = new qminoa.BLL.PM.TimeEntry(0, 0, 0, 0, DateTime.MinValue, null, -1M);
- protected DataTable _dayListTable = null;
- private PMUser _user;
- private DateTime _weekEndingDate = DateTime.Today;
- private DateTime _weekStartingDate = DateTime.Today;
- protected System.Web.UI.WebControls.Button AddEntry;
- protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
- protected System.Web.UI.WebControls.Button Cancel;
- protected System.Web.UI.WebControls.DropDownList CategoryList;
- protected System.Web.UI.WebControls.DropDownList Days;
- protected System.Web.UI.WebControls.TextBox Description;
- protected System.Web.UI.WebControls.TextBox Hours;
- protected System.Web.UI.WebControls.DropDownList ProjectList;
- protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
- protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
- protected System.Web.UI.WebControls.DataGrid TimeEntryGrid;
- protected System.Web.UI.WebControls.DropDownList UserList;
- protected System.Web.UI.WebControls.TextBox WeekEnding;
- protected System.Web.UI.WebControls.DropDownList BranchDropList;
- protected System.Web.UI.WebControls.DropDownList DepartmentDropList;
- private void Page_Load(object sender, System.EventArgs e)
- {
- this.PageBegin("项目管理",true);
- _user = new PMUser(Convert.ToInt16(this.Empid));
- if (!Page.IsPostBack)
- {
- BLL.PM.TimeEntry.FillCorrectStartEndDates(DateTime.Today,
- ref _weekStartingDate, ref _weekEndingDate);
- WeekEnding.Text = _weekEndingDate.ToShortDateString();
- BindUserList();
- BindEntryFields();
- BindTimeSheet(_user.UserID, _weekStartingDate, _weekEndingDate);
- }
- else
- {
- BLL.PM.TimeEntry.FillCorrectStartEndDates(Convert.ToDateTime(WeekEnding.Text),
- ref _weekStartingDate, ref _weekEndingDate);
- _dayListTable = BLL.PM.TimeEntry.GetWeek(Convert.ToDateTime(WeekEnding.Text));
- }
- }
-
- private void BindCategoryList()
- {
- if (ProjectList.SelectedItem != null)
- {
- CategoryList.DataSource = Project.GetCategories(Convert.ToInt32(ProjectList.SelectedItem.Value));
- CategoryList.DataValueField = "CategoryID";
- CategoryList.DataTextField = "Abbreviation";
- CategoryList.DataBind();
- }
- }
- private void BindDates()
- {
- _dayListTable = BLL.PM.TimeEntry.GetWeek(Convert.ToDateTime(WeekEnding.Text));
- Days.DataSource = _dayListTable;
- Days.DataValueField = "Date";
- Days.DataTextField = "Day";
- Days.DataBind();
- Days.Items.FindByText(Convert.ToDateTime(DateTime.Today).ToString("ddd")).Selected= true;
- }
- private void BindEntryFields()
- {
- BindDates();
- BindProjectList();
- BindCategoryList();
- }
-
- private void BindProjectList()
- {
- if (ProjectList.SelectedItem != null)
- _userInput.ProjectID = Convert.ToInt32(ProjectList.SelectedItem.Value);
- ProjectList.DataSource = ListUserProjects();
- ProjectList.DataTextField = "Name";
- ProjectList.DataValueField = "ProjectID";
- ProjectList.DataBind();
- if (ProjectList.Items.FindByValue(_userInput.ProjectID.ToString()) != null)
- ProjectList.Items.FindByValue(_userInput.ProjectID.ToString()).Selected = true;
- }
- private void BindTimeSheet(int userID, DateTime start, DateTime end)
- {
- BindTimeSheet(userID, userID, start, end);
- }
- private void BindTimeSheet(int queryUserID, int userID, DateTime start, DateTime end)
- {
- TimeEntriesCollection entryList = BLL.PM.TimeEntry.GetEntries(queryUserID, userID, start, end);
- if (entryList != null)
- {
- SortGridData(entryList, SortField, SortAscending);
- }
- TimeEntryGrid.DataSource = entryList;
- TimeEntryGrid.DataBind();
- }
- private void BindUserList()
- {
- DataTable empTB = (new EmpSystem()).GetEmpTB_By_EmpID(_user.UserID);
- DataRow row = empTB.Rows[0];
- int depID = (int)row[DepData.DEPID_FIELD];
- DataTable depTB = (new DepSystem()).GetDepTB_By_DepID(depID);
- row = depTB.Rows[0];
- int branchID = (int)row[DepData.BRANCHID_FIELD];
- AdminDB admin = new AdminDB();
- BranchDropList.DataSource=admin.GetAllBranch();
- BranchDropList.DataBind();
- BranchDropList.Items.FindByValue(branchID.ToString()).Selected=true;
- DepartmentDropList.DataSource=admin.GetDepByBranch(Int32.Parse(BranchDropList.SelectedItem.Value));
- DepartmentDropList.DataBind();
- DepartmentDropList.Items.FindByValue(depID.ToString()).Selected=true;
- UserList.DataSource = PMUser.GetUsers(_user.UserID, _user.Role,Int32.Parse(DepartmentDropList.SelectedItem.Value));
- UserList.DataBind();
- UserList.Items.FindByValue(_user.UserID.ToString()).Selected=true;
- }
- private void ClearEntryFields()
- {
- BindEntryFields();
- TimeEntryGrid.EditItemIndex = -1;
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- Description.Text = string.Empty;
- Hours.Text = string.Empty;
- }
-
- protected CategoriesCollection ListGridCategories(int projectID)
- {
- return BLL.PM.Project.GetCategories(projectID);
- }
- protected ProjectsCollection ListUserProjects()
- {
- return BLL.PM.Project.GetProjects(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value));
- }
- private void SortGridData(TimeEntriesCollection list, string sortField, bool asc)
- {
- TimeEntriesCollection.TimeEntryFields sortCol = TimeEntriesCollection.TimeEntryFields.InitValue;
- switch(sortField)
- {
- case "EntryDate":
- sortCol = TimeEntriesCollection.TimeEntryFields.Day;
- break;
- case "ProjectName":
- sortCol = TimeEntriesCollection.TimeEntryFields.Project;
- break;
- case "CategoryName":
- sortCol = TimeEntriesCollection.TimeEntryFields.Category;
- break;
- case "Duration":
- sortCol = TimeEntriesCollection.TimeEntryFields.Hours;
- break;
- case "Description":
- sortCol = TimeEntriesCollection.TimeEntryFields.Description;
- break;
- default:
- break;
- }
- list.Sort(sortCol, asc);
- }
- #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.WeekEnding.TextChanged += new System.EventHandler(this.WeekEnding_TextChanged);
- this.ProjectList.SelectedIndexChanged += new System.EventHandler(this.ProjectList_SelectedIndexChanged);
- this.AddEntry.Click += new System.EventHandler(this.AddEntry_Click);
- this.Cancel.Click += new System.EventHandler(this.Cancel_Click);
- this.BranchDropList.SelectedIndexChanged += new System.EventHandler(this.BranchDropList_SelectedIndexChanged);
- this.DepartmentDropList.SelectedIndexChanged += new System.EventHandler(this.DepartmentDropList_SelectedIndexChanged);
- this.UserList.SelectedIndexChanged += new System.EventHandler(this.UserList_OnChange);
- this.TimeEntryGrid.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.TimeEntryGrid_OnCancel);
- this.TimeEntryGrid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.TimeEntryGrid_OnEdit);
- this.TimeEntryGrid.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.TimeEntryGrid_Sort);
- this.TimeEntryGrid.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.TimeEntryGrid_OnUpdate);
- this.TimeEntryGrid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.TimeEntryGrid_OnDelete);
- this.TimeEntryGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.TimeEntryGrid_Itembound);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
-
- private void AddEntry_Click(object sender, System.EventArgs e)
- {
- Requiredfieldvalidator1.Validate();
- RequiredFieldValidator2.Validate();
- RangeValidator1.Validate();
- CompareValidator1.Validate();
-
- if (Requiredfieldvalidator1.IsValid && RequiredFieldValidator2.IsValid && CompareValidator1.IsValid && RangeValidator1.IsValid)
- {
- BLL.PM.TimeEntry te = new BLL.PM.TimeEntry(0,
- Convert.ToInt32(UserList.SelectedItem.Value),
- Convert.ToInt32(ProjectList.SelectedItem.Value),
- Convert.ToInt32(CategoryList.SelectedItem.Value),
- Convert.ToDateTime(Days.SelectedItem.Value),
- Description.Text, Convert.ToDecimal(Hours.Text));
- te.Save();
- ClearEntryFields();
- }
- }
-
- private void Cancel_Click(object sender, System.EventArgs e)
- {
- ClearEntryFields();
- }
- private void ProjectList_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- BindCategoryList();
- }
- private void TimeEntryGrid_Itembound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
- {
- if (e.Item.ItemType == ListItemType.EditItem)
- {
- DropDownList currentCbo = (DropDownList) e.Item.FindControl("EntryDays");
- currentCbo.SelectedIndex = currentCbo.Items.IndexOf(currentCbo.Items.FindByText(_userInput.Day));
- currentCbo = (DropDownList) e.Item.FindControl("EntryProjects");
- currentCbo.SelectedIndex = currentCbo.Items.IndexOf(currentCbo.Items.FindByText(_userInput.ProjectName));
- currentCbo = (DropDownList) e.Item.FindControl("EntryCategories");
- currentCbo.SelectedIndex = currentCbo.Items.IndexOf(currentCbo.Items.FindByText(_userInput.CategoryName));
- }
- }
- protected void TimeEntryGrid_OnCancel(Object sender, DataGridCommandEventArgs e)
- {
- TimeEntryGrid.EditItemIndex = -1;
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- }
-
- protected void TimeEntryGrid_OnDelete(Object sender, DataGridCommandEventArgs e)
- {
- int entryLogID = Convert.ToInt32(TimeEntryGrid.DataKeys[(int)e.Item.ItemIndex]);
- BLL.PM.TimeEntry.Remove(entryLogID);
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- }
- protected void TimeEntryGrid_OnEdit(Object sender, DataGridCommandEventArgs e)
- {
- TimeEntryGrid.EditItemIndex = e.Item.ItemIndex;
- _userInput.Day = ((Label) e.Item.FindControl("EntryDay")).Text;
- _userInput.ProjectName = ((Label) e.Item.FindControl("EntryProject")).Text.Trim();
- _userInput.ProjectID = Convert.ToInt32(((Label) e.Item.FindControl("EntryProjectID")).Text);
- _userInput.CategoryName = ((Label) e.Item.FindControl("EntryCategory")).Text.Trim();
- _userInput.Duration = Convert.ToDecimal(((Label) e.Item.FindControl("EntryDuration")).Text);
- _userInput.Description = ((Label) e.Item.FindControl("GridDescription")).Text.Trim();
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- }
- protected void TimeEntryGrid_OnUpdate(Object sender, DataGridCommandEventArgs e)
- {
- DataGridItem item = TimeEntryGrid.Items[TimeEntryGrid.EditItemIndex];
- RequiredFieldValidator required = (RequiredFieldValidator) item.FindControl("RequiredFieldValidatorGridHours");
- CompareValidator comparer = (CompareValidator) item.FindControl("CompareValidatorGridHours");
- required.Validate();
- comparer.Validate();
-
- if (required.IsValid && comparer.IsValid)
- {
- int entryLogID;
- int userID;
- int projectID;
- int categoryID;
- DateTime taskDate;
- string description;
- decimal duration;
- BLL.PM.TimeEntry te = null;
- entryLogID = Convert.ToInt32(TimeEntryGrid.DataKeys[(int)e.Item.ItemIndex]);
- userID = Convert.ToInt32(UserList.SelectedItem.Value);
- projectID = Convert.ToInt32(((DropDownList) e.Item.FindControl("EntryProjects")).SelectedItem.Value);
- categoryID = Convert.ToInt32(((DropDownList) e.Item.FindControl("EntryCategories")).SelectedItem.Value);
- taskDate = Convert.ToDateTime(((DropDownList) e.Item.FindControl("EntryDays")).SelectedItem.Value);
- description = ((TextBox) e.Item.FindControl("EntryDescription")).Text;//TTSecurity.CleanStringRegex(((TextBox) e.Item.FindControl("EntryDescription")).Text);
- duration = Convert.ToDecimal(((TextBox) e.Item.FindControl("EntryHours")).Text);
- te = new BLL.PM.TimeEntry(entryLogID, userID, projectID, categoryID, taskDate, description, duration);
- te.Save();
- TimeEntryGrid.EditItemIndex = -1;
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- }
- }
- private void TimeEntryGrid_Sort(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
- {
- TimeEntryGrid.EditItemIndex = -1;
- SortField = e.SortExpression;
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- }
- protected void UserProjects_OnChange(object sender, System.EventArgs e)
- {
- DataGridItem item = TimeEntryGrid.Items[TimeEntryGrid.EditItemIndex];
-
- if (item != null)
- {
- TextBox txt = (TextBox) item.FindControl("EntryHours");
- _userInput.Duration = Convert.ToDecimal(txt.Text);
-
- TextBox txtDesc = (TextBox) item.FindControl("EntryDescription");
- _userInput.Description = txtDesc.Text;
- DropDownList EntryDays = (DropDownList)item.FindControl("EntryDays");
- _userInput.EntryDate = Convert.ToDateTime(EntryDays.SelectedItem.Value);
- _userInput.Day = EntryDays.SelectedItem.Text;
- }
- DropDownList EntryProjects = (DropDownList) sender;
- _userInput.ProjectID = Convert.ToInt32(EntryProjects.SelectedItem.Value);
- _userInput.ProjectName = EntryProjects.SelectedItem.Text;
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- }
-
- private void UserList_OnChange(object sender, System.EventArgs e)
- {
- TimeEntryGrid.EditItemIndex = -1;
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- BindEntryFields();
- }
- private void WeekEnding_TextChanged(object sender, System.EventArgs e)
- {
- TimeEntryGrid.EditItemIndex = -1;
- BLL.PM.TimeEntry.FillCorrectStartEndDates(Convert.ToDateTime(WeekEnding.Text),
- ref _weekStartingDate, ref _weekEndingDate);
- WeekEnding.Text = _weekEndingDate.ToShortDateString();
- BindEntryFields();
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- }
- private void BranchDropList_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- AdminDB admin = new AdminDB();
- DepartmentDropList.DataSource=admin.GetDepByBranch(Int32.Parse(BranchDropList.SelectedItem.Value));
- DepartmentDropList.DataBind();
- if(DepartmentDropList.Items.Count !=0)
- {
- UserList.DataSource = PMUser.GetUsers(_user.UserID, _user.Role,Int32.Parse(DepartmentDropList.SelectedItem.Value));
- UserList.DataBind();
- UserList.Items[0].Selected = true;
- TimeEntryGrid.EditItemIndex = -1;
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- BindEntryFields();
- }
- else
- {
- BindTimeSheet(_user.UserID, 0, _weekStartingDate, _weekEndingDate);
- UserList.Items.Clear();
- ProjectList.Items.Clear();
- }
- }
- private void DepartmentDropList_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- if(DepartmentDropList.Items.Count !=0)
- {
- UserList.DataSource = PMUser.GetUsers(_user.UserID, _user.Role,Int32.Parse(DepartmentDropList.SelectedItem.Value));
- UserList.DataBind();
- UserList.Items[0].Selected = true;
- TimeEntryGrid.EditItemIndex = -1;
- BindTimeSheet(_user.UserID, Convert.ToInt32(UserList.SelectedItem.Value), _weekStartingDate, _weekEndingDate);
- BindEntryFields();
- }
- else
- {
- BindTimeSheet(_user.UserID, 0, _weekStartingDate, _weekEndingDate);
- UserList.Items.Clear();
- ProjectList.Items.Clear();
- }
- }
- 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;
- }
- }
- }
- }