440 lines
14 KiB
C#
440 lines
14 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 ClientEdit : BaseEditPage
|
|
{
|
|
|
|
#region BizObject
|
|
public Client mClient;
|
|
protected Client CurrentClient
|
|
{
|
|
get
|
|
{
|
|
if (mClient != null) return mClient;
|
|
|
|
string idstring = Request.QueryString["id"];
|
|
Guid oID = Guid.Empty;
|
|
if (!string.IsNullOrEmpty(idstring))
|
|
oID = new Guid(idstring);
|
|
|
|
mClient = (Client)Session["client"];
|
|
//ensure if object in session is the same as the one requested
|
|
if (mClient == null || (oID!=Guid.Empty && mClient.ID != oID))//Case 912
|
|
{
|
|
try
|
|
{
|
|
if (oID != Guid.Empty)
|
|
mClient = Client.GetItem(oID);
|
|
else
|
|
mClient = Client.NewItem();
|
|
|
|
Session["client"] = mClient;
|
|
}
|
|
catch (System.Security.SecurityException)
|
|
{
|
|
CloseMe();
|
|
}
|
|
}
|
|
|
|
return mClient;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Page events
|
|
bool bShowCustomFields = false;
|
|
|
|
|
|
protected void Page_Init()
|
|
{
|
|
|
|
if (Util.CurrentUser.IsClientOrHeadOfficeAccount || AyaBizUtils.Right("Object.Client") < (int)SecurityLevelTypes.ReadOnly)//Less than read only instead of NoAccess to catch records where it's zero instead of 1
|
|
{
|
|
Util.Denied(Context);
|
|
}
|
|
|
|
//Set up custom fields early so they can be retrieved from viewstate
|
|
if (!IsCallback && IsPostBack)
|
|
bShowCustomFields = Util.ShowCustomFields("Client", null, this.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("client");
|
|
|
|
|
|
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=" + CurrentClient.ID.ToString() + "&type=" + ((int)RootObjectTypes.Client).ToString(); ;
|
|
miFollow.Target = "_blank";
|
|
Master.Menu.Items.Add(miFollow);
|
|
|
|
//create the client notes menu item
|
|
Telerik.Web.UI.RadMenuItem mi = new Telerik.Web.UI.RadMenuItem();
|
|
mi.ToolTip = Util.LocaleText("ClientNote.Label.List");
|
|
mi.ImageUrl = "~/graphics/ClientNotes24.png";
|
|
mi.NavigateUrl = "ClientNotesEdit.aspx?id=" + CurrentClient.ID.ToString();
|
|
mi.Target = "_blank";
|
|
Master.Menu.Items.Add(mi);
|
|
|
|
|
|
//case 73
|
|
//create the Wiki menu item
|
|
if (CurrentClient.CanWiki)
|
|
Util.WikiPageInsertMenuItem(Master.Menu, RootObjectTypes.Client, CurrentClient.ID);
|
|
|
|
if (AyaBizUtils.Right("Object.Client") < (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.Client") > (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()
|
|
{
|
|
Client o = CurrentClient;
|
|
ckActive.Checked = o.Active;
|
|
edName.Text = o.Name;
|
|
if (string.IsNullOrEmpty(o.Name))
|
|
this.Title = Util.LocaleText("O.Client");
|
|
else
|
|
this.Title = o.Name;
|
|
hlWebAddress.NavigateUrl = Util.StringToHTTP(o.WebAddress);
|
|
hlWebAddress.Text = Util.LocaleText("Common.Label.WebAddress");
|
|
|
|
edWebAddress.Text = o.WebAddress;
|
|
ckBillHeadOffice.Checked = o.BillHeadOffice;
|
|
dtContractExpires.DbSelectedDate = o.ContractExpires;
|
|
ckUsesBanking.Checked = o.UsesBanking;
|
|
ckSendNotification.Checked = o.SendNotifications;
|
|
|
|
//Case 205
|
|
hlUsesBanking.Text = Util.LocaleText("Common.Label.UsesBanking");
|
|
if (o.UsesBanking)
|
|
{
|
|
hlUsesBanking.NavigateUrl = "ServiceBankEdit.aspx?id=" + o.ID + "&type=" + ((int)RootObjectTypes.Client).ToString();
|
|
hlUsesBanking.Target = "_blank";
|
|
}
|
|
else
|
|
hlUsesBanking.NavigateUrl = "";
|
|
|
|
//combo
|
|
|
|
//Case 307 changed following to use method that loads them completely and then selects id
|
|
Util.ComboPopulateAndInitializeBizList(cbRegion, "Region", o.RegionID, true);
|
|
Util.ComboPopulateAndInitializeBizList(cbDispatchZone, "DispatchZone", o.DispatchZoneID, true);
|
|
Util.ComboPopulateAndInitializeBizList(cbClientGroup, "ClientGroup", o.ClientGroupID, false);
|
|
Util.ComboPopulateAndInitializeBizList(cbHeadOffice, "HeadOffice", o.HeadOfficeID, true);
|
|
Util.ComboPopulateAndInitializeBizList(cbContractID, "Contract", o.ContractID, true);
|
|
|
|
cbTemplate.Items.Clear();
|
|
TemplatePickList UList = TemplatePickList.GetList(WorkorderTypes.TemplateService,true);
|
|
foreach (TemplatePickList.TemplatePickListInfo ui in UList)
|
|
{
|
|
cbTemplate.Items.Add(new Telerik.Web.UI.RadComboBoxItem(ui.Description,ui.ID.ToString()));
|
|
}
|
|
cbTemplate.SelectedValue=o.DefaultServiceTemplateID.ToString();
|
|
|
|
//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;
|
|
edPopUpNotes.Text = o.PopUpNotes;
|
|
edTechNotes.Text = o.TechNotes;
|
|
|
|
//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("Client", 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], ClientList.ReportKey, ClientListDetailed.ReportKey);
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region GetData
|
|
private void GetData()
|
|
{
|
|
|
|
Client o = CurrentClient;
|
|
|
|
o.Active = ckActive.Checked;
|
|
o.Name = edName.Text;
|
|
o.WebAddress = edWebAddress.Text;
|
|
o.BillHeadOffice = ckBillHeadOffice.Checked;
|
|
o.ContractExpires = dtContractExpires.SelectedDate;
|
|
o.UsesBanking = ckUsesBanking.Checked;
|
|
o.SendNotifications = ckSendNotification.Checked;
|
|
|
|
//Combo's
|
|
o.RegionID = Util.ComboValue(cbRegion);
|
|
o.DispatchZoneID = Util.ComboValue(cbDispatchZone);
|
|
o.ClientGroupID = Util.ComboValue(cbClientGroup);
|
|
o.HeadOfficeID = Util.ComboValue(cbHeadOffice);
|
|
o.ContractID = Util.ComboValue(cbContractID);
|
|
o.DefaultServiceTemplateID = Util.ComboValue(cbTemplate);
|
|
|
|
//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;
|
|
o.PopUpNotes = edPopUpNotes.Text;
|
|
o.TechNotes = edTechNotes.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("Client", 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
|
|
{
|
|
Client.DeleteItem(CurrentClient.ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.Master.SetErrors(Util.ReportSQLError(ex));
|
|
return;
|
|
}
|
|
CloseForm();
|
|
break;
|
|
case "LT:UI.Command.SaveNew":
|
|
if (SaveRecord())
|
|
{
|
|
//case 912
|
|
Session.Remove("client");
|
|
Session.Remove("contact");
|
|
mClient = null;
|
|
Response.Redirect("ClientEdit.aspx");
|
|
}
|
|
break;
|
|
case "LT:UI.Command.RecordHistory":
|
|
|
|
|
|
|
|
|
|
Util.PopupAlert(this.Page,
|
|
Util.RecordHistoryText(
|
|
CurrentClient.Creator,
|
|
CurrentClient.Modifier,
|
|
CurrentClient.Created,
|
|
CurrentClient.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], ClientList.ReportKey,
|
|
ClientList.GetListForSingleItem(CurrentClient.ID));
|
|
|
|
else
|
|
Util.Report(Page, s[1], ClientListDetailed.ReportKey,
|
|
ClientListDetailed.GetListForSingleItem(CurrentClient.ID));
|
|
|
|
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
private bool SaveRecord()
|
|
{
|
|
if (!CurrentClient.IsDirty) return true;
|
|
if (CurrentClient.IsSavable)
|
|
{
|
|
Session["client"] = mClient = (Client)mClient.Save();//case 912
|
|
|
|
this.Master.SetErrors("");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
//display broken rules, or whatever, see book
|
|
this.Master.SetErrors(mClient.BrokenRulesText);
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
private void CloseForm()
|
|
{
|
|
Session.Remove("client");
|
|
Session.Remove("contact");
|
|
CloseMe();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|