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

401 lines
13 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;
using Telerik.Web.UI;
public partial class HeadOfficeEdit : BaseEditPage
{
#region BizObject
public HeadOffice mHeadOffice;
protected HeadOffice CurrentHeadOffice
{
get
{
if (mHeadOffice != null) return mHeadOffice;
string idstring = Request.QueryString["id"];
Guid oID = Guid.Empty;
if (!string.IsNullOrEmpty(idstring))
oID = new Guid(idstring);
mHeadOffice = (HeadOffice)Session["headoffice"];
//ensure if object in session is the same as the one requested
if (mHeadOffice == null || (oID != Guid.Empty && mHeadOffice.ID != oID))//Case 912
{
try
{
if (oID != Guid.Empty)
mHeadOffice = HeadOffice.GetItem(oID);
else
mHeadOffice = HeadOffice.NewItem();
Session["headoffice"] = mHeadOffice;
}
catch (System.Security.SecurityException)
{
CloseMe();
}
}
return mHeadOffice;
}
}
#endregion
#region Page events
private bool bShowCustomFields = false;
protected void Page_Init()
{
if (Util.CurrentUser.IsClientOrHeadOfficeAccount ||
AyaBizUtils.Right("Object.HeadOffice") < (int)SecurityLevelTypes.ReadOnly)
{
Util.Denied(Context);
}
//Called early here as the custom fields are dynamic
//so if they are not recreated here their viewstate will not
//be set properly
bShowCustomFields = Util.ShowCustomFields("HeadOffice", null, CustomFields, this.phCustom, false, this.rc1.ID, this.rt1.ID);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack && !IsAjaxCallback)
{
//clear any remnants from prior session not removed
//due to improper close
Session.Remove("headoffice");
if (!bShowCustomFields)
{
divC1.Attributes.Add("class", "onehalfcolumn");
divC2.Attributes.Add("class", "onehalfcolumn");
}
else
{
divC1.Attributes.Add("class", "onethirdcolumn");
divC2.Attributes.Add("class", "onethirdcolumn");
}
//Follow up menu item
Telerik.Web.UI.RadMenuItem miFollow = new Telerik.Web.UI.RadMenuItem();
miFollow.ToolTip = Util.LocaleText("ScheduleMarker.Label.FollowUp");
miFollow.ImageUrl = "~/graphics/FollowUp24.png";
miFollow.NavigateUrl = "FollowUpSelector.aspx?id=" + this.CurrentHeadOffice.ID.ToString() + "&type=" + ((int)RootObjectTypes.HeadOffice).ToString(); ;
miFollow.Target = "_blank";
Master.Menu.Items.Add(miFollow);
//case 73
//create the Wiki menu item
if (CurrentHeadOffice.CanWiki)
Util.WikiPageInsertMenuItem(Master.Menu, RootObjectTypes.HeadOffice, CurrentHeadOffice.ID);
if (AyaBizUtils.Right("Object.HeadOffice") < (int)SecurityLevelTypes.ReadWrite)
Util.SetReadOnly(this);
}
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
//Get data logic
if (this.IsPostBack && !IsAjaxCallback)//Only on a postback and not a callback
{
//case 1052
if (AyaBizUtils.Right("Object.HeadOffice") > (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 Data
private void SetData()
{
HeadOffice o = CurrentHeadOffice;
ckActive.Checked = o.Active;
edName.Text = o.Name;
if (string.IsNullOrEmpty(o.Name))
this.Title = Util.LocaleText("O.HeadOffice");
else
this.Title = o.Name;
hlWebAddress.NavigateUrl = Util.StringToHTTP(o.WebAddress);
hlWebAddress.Text = Util.LocaleText("Common.Label.WebAddress");
edWebAddress.Text = o.WebAddress;
dtContractExpires.DbSelectedDate = o.ContractExpires;
ckUsesBanking.Checked = o.UsesBanking;
//Case 205
hlUsesBanking.Text = Util.LocaleText("Common.Label.UsesBanking");
if (o.UsesBanking)
{
hlUsesBanking.NavigateUrl = "ServiceBankEdit.aspx?id=" + o.ID + "&type=" + ((int)RootObjectTypes.HeadOffice).ToString();
hlUsesBanking.Target = "_blank";
}
else
hlUsesBanking.NavigateUrl = "";
//combo
//Case 307
Util.ComboPopulateAndInitializeBizList(cbRegion, "Region", o.RegionID,false);
Util.ComboPopulateAndInitializeBizList(cbContractID, "Contract", o.ContractID,true);
//Case 310
Util.ComboPopulateAndInitializeBizList(cbClientGroup, "ClientGroup", o.ClientGroupID,false);
//Postal address
edDeliveryAddress.Text = o.MailToAddress.DeliveryAddress;
edCity.Text = o.MailToAddress.City;
edStateProv.Text = o.MailToAddress.StateProv;
edPostal.Text = o.MailToAddress.Postal;
hlCountryCode.Text = Util.LocaleText("Address.Label.CountryCode");
edCountryCode.Text = o.MailToAddress.CountryCode;
//Physical address
edPDeliveryAddress.Text = o.GoToAddress.DeliveryAddress;
edPCity.Text = o.GoToAddress.City;
edPStateProv.Text = o.GoToAddress.StateProv;
edPPostal.Text = o.GoToAddress.Postal;
hlPCountryCode.Text = Util.LocaleText("Address.Label.CountryCode");
edPCountryCode.Text = o.GoToAddress.CountryCode;
//Notes
edNotes.Text = o.Notes;
//Case 306
edAccountNumber.Text = o.AccountNumber;
//Contacts
edContact.Text = o.Contact;
edEmail.Text = o.Email;
edPhone1.Text = o.Phone1;
edPhone2.Text = o.Phone2;
edPhone3.Text = o.Phone3;
edPhone4.Text = o.Phone4;
edPhone5.Text = o.Phone5;
edContactNotes.Text = o.ContactNotes;
//Case 305
Util.ShowCustomFields("HeadOffice", o, this.CustomFields, this.phCustom, false, this.rc1.ID, this.rt1.ID);
if (AyaBizUtils.Right("Object.Report") < (int)SecurityLevelTypes.ReadOnly)
Master.Menu.Items[0].Visible = false;
else
Util.ReportFillList(Master.Menu.Items[0], HeadOfficeList.ReportKey, HeadOfficeListDetailed.ReportKey);
}
#endregion
#region GetData
private void GetData()
{
HeadOffice o = CurrentHeadOffice;
o.Active = ckActive.Checked;
o.Name = edName.Text;
o.WebAddress = edWebAddress.Text;
o.ContractExpires = dtContractExpires.SelectedDate;
o.UsesBanking = ckUsesBanking.Checked;
//Combo's
o.RegionID = Util.ComboValue(cbRegion);
//Case 310
o.ClientGroupID = Util.ComboValue(cbClientGroup);
o.ContractID = Util.ComboValue(cbContractID);
//Postal address
o.MailToAddress.DeliveryAddress = edDeliveryAddress.Text;
o.MailToAddress.City = edCity.Text;
o.MailToAddress.StateProv = edStateProv.Text;
o.MailToAddress.Postal = edPostal.Text;
o.MailToAddress.CountryCode = edCountryCode.Text;
//Physical address
o.GoToAddress.DeliveryAddress = edPDeliveryAddress.Text;
o.GoToAddress.City = edPCity.Text;
o.GoToAddress.StateProv = edPStateProv.Text;
o.GoToAddress.Postal = edPPostal.Text;
o.GoToAddress.CountryCode = edPCountryCode.Text;
//Notes
o.Notes = edNotes.Text;
//Case 306
o.AccountNumber = edAccountNumber.Text;
//Contacts
o.Contact = edContact.Text;
o.Email = edEmail.Text;
o.Phone1 = edPhone1.Text;
o.Phone2 = edPhone2.Text;
o.Phone3 = edPhone3.Text;
o.Phone4 = edPhone4.Text;
o.Phone5 = edPhone5.Text;
o.ContactNotes = edContactNotes.Text;
//Case 305
Util.GetCustomFields("HeadOffice",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:
{
#region tbclicks
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
{
HeadOffice.DeleteItem(CurrentHeadOffice.ID);
}
catch (Exception ex)
{
this.Master.SetErrors(Util.ReportSQLError(ex));
return;
}
CloseForm();
break;
case "LT:UI.Command.SaveNew":
if (SaveRecord())
{//case 912
Session.Remove("headoffice");
Session.Remove("contact");
mHeadOffice = null;
Response.Redirect("HeadOfficeEdit.aspx");
}
break;
case "LT:UI.Command.RecordHistory":
Util.PopupAlert(this.Page,
Util.RecordHistoryText(
CurrentHeadOffice.Creator,
CurrentHeadOffice.Modifier,
CurrentHeadOffice.Created,
CurrentHeadOffice.Modified
), " "
);
break;
//case "LT:AssignedDoc.Label.List":
// Response.Redirect("stub.aspx");
// break;
}
#endregion tbclicks
}
break;
case AYMessageType.Print:
{
string[] s = Master.AyMessage.Message.Split(',');
bool summary = (s[0] != "PRINTDETAILED");
if (summary)
Util.Report(Page, s[1], HeadOfficeList.ReportKey,
HeadOfficeList.GetListForSingleItem(CurrentHeadOffice.ID));
else
Util.Report(Page, s[1], HeadOfficeListDetailed.ReportKey,
HeadOfficeListDetailed.GetListForSingleItem(CurrentHeadOffice.ID));
}
break;
}
}
private bool SaveRecord()
{
if (!CurrentHeadOffice.IsDirty) return true;
if (CurrentHeadOffice.IsSavable)
{
Session["headoffice"] = mHeadOffice = (HeadOffice)mHeadOffice.Save();//case 912
this.Master.SetErrors("");
return true;
}
else
{
//display broken rules, or whatever, see book
this.Master.SetErrors(mHeadOffice.BrokenRulesText);
return false;
}
}
private void CloseForm()
{
Session.Remove("headoffice");
Session.Remove("contact");
CloseMe();
}
#endregion
}