Files
ayanova7/source/WBI/ProjectEdit.aspx.cs
2018-06-29 19:47:36 +00:00

293 lines
9.0 KiB
C#

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using GZTW.AyaNova.BLL;
public partial class ProjectEdit : BaseEditPage
{
#region BizObject
public Project mProject;
protected Project CurrentProject
{
get
{
if (mProject != null) return mProject;
string idstring = Request.QueryString["id"];
Guid oID = Guid.Empty;
if (!string.IsNullOrEmpty(idstring))
oID = new Guid(idstring);
mProject = (Project)Session["project"];
//ensure if object in session is the same as the one requested
if (mProject == null || (oID != Guid.Empty && mProject.ID != oID))//Case 912
{
try
{
if (oID != Guid.Empty)
mProject = Project.GetItem(oID);
else
mProject = Project.NewItem();
Session["project"] = mProject;
}
catch (System.Security.SecurityException)
{
CloseMe();
}
}
return mProject;
}
}
#endregion
#region Page events
protected void Page_Init()
{
if (Util.CurrentUser.IsClientOrHeadOfficeAccount ||
AyaBizUtils.Right("Object.Project") < (int)SecurityLevelTypes.ReadOnly)
{
Util.Denied(Context);
}
//Set up custom fields early so they can be retrieved from viewstate
if(!IsCallback && IsPostBack)
Util.ShowCustomFields("Project", null, this.CustomFields, this.phCustom, false, this.rc1.ID, this.rt1.ID);
}
protected void Page_Load(object sender, EventArgs e)
{
//string s=System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
//don't process the following on an ajax callback
if (IsCallback) return;
//Initialize controls on first page load
if (!this.IsPostBack)
{
//Item zero is always the print menu
//Master.Menu.Items[0].Hidden=true;
//Localize the page
//Case 308 commented out and moved to load complete
//Util.Localize(this.Page);
//case 73
//create the Wiki menu item
if (CurrentProject.CanWiki)
Util.WikiPageInsertMenuItem(Master.Menu, RootObjectTypes.Project, CurrentProject.ID);
SetData();
if (AyaBizUtils.Right("Object.Project") < (int)SecurityLevelTypes.ReadWrite)
Util.SetReadOnly(this);
}
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
////don't process the following on an ajax callback
//if (IsCallback) return;
////Get data logic
//if (this.IsPostBack)//Only on a postback
//{
// //Only if user isn't closing form outright without saving
// if (Master.AyMessage == null || Master.AyMessage.Message != "LT:UI.Command.Close")
// {
// GetData();
// }
// if (Master.AyMessage != null)
// HandleAyMessage();
//}
//Case 308 replicated following block from client form
//Get data logic
if (this.IsPostBack && !IsAjaxCallback)//Only on a postback and not a callback
{
//case 1052
if (AyaBizUtils.Right("Object.Project") > (int)SecurityLevelTypes.ReadOnly)
GetData();
}
//Load and set data in initial form load
//and in all postbacks that are not a result of a rad
//manager callback
if (!IsAjaxCallback)
{
//Localize the page
Util.Localize(this.Page);
SetData();
}
if (Master.AyMessage != null)
HandleAyMessage();
}
#endregion page events
#region Set / get data
private void SetData()
{
Project o = CurrentProject;
ckActive.Checked = o.Active;
edName.Text = o.Name;
if (string.IsNullOrEmpty(o.Name))
this.Title = Util.LocaleText("O.Project");
else
this.Title = Util.LocaleText("O.Project") +" - " +o.Name;
edAccountNumber.Text = o.AccountNumber;
Util.ComboInitialize(cbOverseer, "User", o.ProjectOverseerID);
Util.ComboPopulateAndInitializeBizList(cbRegion, "Region", o.RegionID, true);//case 58
dtDateStarted.DbSelectedDate = o.DateStarted;
dtDateCompleted.DbSelectedDate = o.DateCompleted;
edNotes.Text = o.Notes;
Util.ShowCustomFields("Project", o, this.CustomFields, this.phCustom, false, this.rc1.ID, this.rt1.ID);
}
private void GetData()
{
Project o = CurrentProject;
o.Active = ckActive.Checked;
o.Name = edName.Text;
o.AccountNumber = edAccountNumber.Text;
o.DateStarted = dtDateStarted.DbSelectedDate;
o.DateCompleted = dtDateCompleted.DbSelectedDate;
o.ProjectOverseerID = new Guid(cbOverseer.SelectedValue);
o.RegionID = Util.ComboValue(cbRegion);//case 58
o.Notes = edNotes.Text;
Util.GetCustomFields("Project", o, this.phCustom);
}
#endregion
#region Toolbar and other master page messages
/// <summary>
/// Messages from master page
/// </summary>
void HandleAyMessage()
{
switch (Master.AyMessage.MessageType)
{
case AYMessageType.ToolBarClick:
{
switch (Master.AyMessage.Message)
{
case "LT:UI.Command.Close":
CloseForm();
break;
case "LT:UI.Command.Save":
SaveRecord();
break;
case "LT:UI.Command.SaveClose":
if (SaveRecord())
CloseForm();
break;
case "LT:UI.Command.Delete":
try
{
Project.DeleteItem(CurrentProject.ID);
}
catch (Exception ex)
{
this.Master.SetErrors(Util.ReportSQLError(ex));
return;
}
CloseForm();
break;
case "LT:UI.Command.SaveNew":
if (SaveRecord())
{
Session.Remove("project");
mProject = null;
Response.Redirect("ProjectEdit.aspx");
}
break;
case "LT:UI.Command.RecordHistory":
Util.PopupAlert(this.Page,Util.RecordHistoryText(
CurrentProject.Creator,
CurrentProject.Modifier,
CurrentProject.Created,
CurrentProject.Modified
));
break;
//case "LT:AssignedDoc.Label.List":
// Response.Redirect("stub.aspx");
// break;
}
}
break;
}
}
private bool SaveRecord()
{
if (!CurrentProject.IsDirty) return true;
if (CurrentProject.IsSavable)
{
Session["project"] = mProject = (Project)mProject.Save();
this.Master.SetErrors("");
return true;
}
else
{
//display broken rules, or whatever, see book
this.Master.SetErrors(mProject.BrokenRulesText);
return false;
}
}
private void CloseForm()
{
Session.Remove("project");
CloseMe();
}
#endregion
#region Combo box events
protected void cbOverseer_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
{
Util.ComboPopulateBizList("UserPickList", cbOverseer, true, e,true);
}
#endregion combobox events
}