426 lines
14 KiB
C#
426 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 UnitEdit : BaseEditPage
|
|
{
|
|
|
|
#region BizObject
|
|
public GZTW.AyaNova.BLL.Unit mUnit;
|
|
protected GZTW.AyaNova.BLL.Unit CurrentUnit
|
|
{
|
|
get
|
|
{
|
|
if (mUnit != null) return mUnit;
|
|
|
|
string idstring = Request.QueryString["id"];
|
|
Guid oID = Guid.Empty;
|
|
if (!string.IsNullOrEmpty(idstring))
|
|
oID = new Guid(idstring);
|
|
|
|
mUnit = (GZTW.AyaNova.BLL.Unit)Session["unit"];
|
|
//ensure if object in session is the same as the one requested
|
|
if (mUnit == null || (oID != Guid.Empty && mUnit.ID != oID))//Case 912
|
|
{
|
|
try
|
|
{
|
|
if (oID != Guid.Empty)
|
|
mUnit = GZTW.AyaNova.BLL.Unit.GetItem(oID);
|
|
else
|
|
mUnit = GZTW.AyaNova.BLL.Unit.NewItem();
|
|
|
|
Session["unit"] = mUnit;
|
|
}
|
|
catch (System.Security.SecurityException)
|
|
{
|
|
CloseMe();
|
|
}
|
|
}
|
|
|
|
return mUnit;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Page events
|
|
private bool bShowCustomFields = false;
|
|
protected void Page_Init()
|
|
{
|
|
if (Util.CurrentUser.IsClientOrHeadOfficeAccount ||
|
|
AyaBizUtils.Right("Object.Unit") < (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("Unit", 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("unit");
|
|
|
|
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=" + CurrentUnit.ID.ToString() + "&type=" + ((int)RootObjectTypes.Unit).ToString(); ;
|
|
miFollow.Target = "_blank";
|
|
Master.Menu.Items.Add(miFollow);
|
|
|
|
//case 73
|
|
//create the Wiki menu item
|
|
if (CurrentUnit.CanWiki)
|
|
Util.WikiPageInsertMenuItem(Master.Menu, RootObjectTypes.Unit, CurrentUnit.ID);
|
|
|
|
if (AyaBizUtils.Right("Object.Unit") < (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.Unit") > (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()
|
|
{
|
|
GZTW.AyaNova.BLL.Unit o = CurrentUnit;
|
|
|
|
Page.Title = Util.LocaleText("O.Unit") + " " + o.Serial;
|
|
|
|
Util.ComboInitialize(cbReplacedByUnitID, "Unit", o.ReplacedByUnitID);
|
|
Util.ComboInitialize(cbUnitModelID, "UnitModel", o.UnitModelID);
|
|
Util.ComboInitialize(cbParentID, "Unit", o.ParentID);
|
|
Util.ComboInitialize(cbPurchasedFromID, "Vendor", o.PurchasedFromID);
|
|
Util.ComboInitialize(cbClientID, "Client", o.ClientID);
|
|
|
|
edSerial.Text = o.Serial;
|
|
edDescription.Text = o.Description;
|
|
edReceiptNumber.Text = o.Receipt;
|
|
edWarrantyLength.Text = o.WarrantyLength.ToString();
|
|
edWarrantyTerms.Text = o.WarrantyTerms;
|
|
|
|
ckActive.Checked = o.Active;
|
|
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.Unit).ToString();
|
|
hlUsesBanking.Target = "_blank";
|
|
}
|
|
else
|
|
hlUsesBanking.NavigateUrl = "";
|
|
|
|
ckMetered.Checked = o.Metered;
|
|
hlMetered.Text = Util.LocaleText("Unit.Label.Metered");
|
|
if (o.Metered)
|
|
{
|
|
hlMetered.NavigateUrl = "UnitMeterReadings.aspx?id=" + CurrentUnit.ID;
|
|
hlMetered.Target = "_blank";
|
|
}
|
|
else
|
|
hlMetered.NavigateUrl = "";
|
|
|
|
ckBoughtHere.Checked = o.BoughtHere;
|
|
ckUnitOverrideWarranty.Checked = o.OverrideModelWarranty;
|
|
ckLifeTimeWarranty.Checked = o.LifeTimeWarranty;
|
|
ckUnitHasOwnAddress.Checked = o.UnitHasOwnAddress;
|
|
|
|
dtPurchasedDate.DbSelectedDate = o.PurchasedDate;
|
|
|
|
|
|
|
|
|
|
//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 78
|
|
edText1.Text = o.Text1;
|
|
edText2.Text = o.Text2;
|
|
edText3.Text = o.Text3;
|
|
edText4.Text = o.Text4;
|
|
|
|
//Case 305
|
|
Util.ShowCustomFields("Unit", 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], UnitList.ReportKey, "");
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region GetData
|
|
private void GetData()
|
|
{
|
|
GZTW.AyaNova.BLL.Unit o = CurrentUnit;
|
|
|
|
o.ReplacedByUnitID = Util.ComboValue(cbReplacedByUnitID);
|
|
o.UnitModelID = Util.ComboValue(cbUnitModelID);
|
|
o.ParentID = Util.ComboValue(cbParentID);
|
|
o.PurchasedFromID = Util.ComboValue(cbPurchasedFromID);
|
|
o.ClientID = Util.ComboValue(cbClientID);
|
|
|
|
o.Serial = edSerial.Text;
|
|
o.Description = edDescription.Text;
|
|
o.Receipt = edReceiptNumber.Text;
|
|
o.WarrantyLength = Util.ParseInt(edWarrantyLength.Text);
|
|
o.WarrantyTerms = edWarrantyTerms.Text;
|
|
o.Active = ckActive.Checked;
|
|
o.UsesBanking = ckUsesBanking.Checked;
|
|
o.Metered = ckMetered.Checked;
|
|
o.BoughtHere = ckBoughtHere.Checked;
|
|
o.OverrideModelWarranty = ckUnitOverrideWarranty.Checked;
|
|
o.LifeTimeWarranty = ckLifeTimeWarranty.Checked;
|
|
o.UnitHasOwnAddress = ckUnitHasOwnAddress.Checked;
|
|
o.PurchasedDate = dtPurchasedDate.DbSelectedDate;
|
|
|
|
//case 78
|
|
o.Text1 = edText1.Text;
|
|
o.Text2 = edText2.Text;
|
|
o.Text3 = edText3.Text;
|
|
o.Text4 = edText4.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 305
|
|
Util.GetCustomFields("Unit",o, this.phCustom);
|
|
}
|
|
#endregion
|
|
|
|
#region Populate combos
|
|
|
|
protected void cbReplacedByUnitID_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
|
|
{
|
|
Util.ComboPopulateBizList("UnitList", cbReplacedByUnitID, true, e,false);
|
|
|
|
}
|
|
protected void cbUnitModelID_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
|
|
{
|
|
Util.ComboPopulateBizList("UnitModelList", cbUnitModelID, true, e, false);
|
|
}
|
|
protected void cbParentID_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
|
|
{
|
|
Util.ComboPopulateBizList("UnitList", cbParentID, true, e, false);
|
|
}
|
|
protected void cbPurchasedFromID_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
|
|
{
|
|
Util.ComboPopulateBizList("Vendor", cbPurchasedFromID, true, e, false);
|
|
}
|
|
protected void cbClientID_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
|
|
{
|
|
Util.ComboPopulateBizList("Client", cbClientID, true, e, true);
|
|
}
|
|
|
|
#endregion populate combos
|
|
|
|
#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
|
|
{
|
|
GZTW.AyaNova.BLL.Unit.DeleteItem(CurrentUnit.ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.Master.SetErrors(Util.ReportSQLError(ex));
|
|
return;
|
|
}
|
|
|
|
|
|
CloseForm();
|
|
break;
|
|
case "LT:UI.Command.SaveNew":
|
|
if (SaveRecord())
|
|
{
|
|
Session.Remove("unit");
|
|
mUnit = null;
|
|
Response.Redirect("ClientEdit.aspx");
|
|
}
|
|
break;
|
|
case "LT:UI.Command.RecordHistory":
|
|
Util.PopupAlert(this.Page,
|
|
Util.RecordHistoryText(
|
|
CurrentUnit.Creator,
|
|
CurrentUnit.Modifier,
|
|
CurrentUnit.Created,
|
|
CurrentUnit.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], UnitList.ReportKey,
|
|
UnitList.GetListForSingleItem(CurrentUnit.ID));
|
|
|
|
//else
|
|
// Util.Report(Page, s[1], ClientListDetailed.ReportKey,
|
|
// ClientListDetailed.GetListForSingleItem(CurrentClient.ID));
|
|
|
|
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
private bool SaveRecord()
|
|
{
|
|
if (!CurrentUnit.IsDirty) return true;
|
|
if (CurrentUnit.IsSavable)
|
|
{
|
|
Session["unit"] = mUnit = (GZTW.AyaNova.BLL.Unit)mUnit.Save();
|
|
|
|
this.Master.SetErrors("");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
//display broken rules, or whatever, see book
|
|
this.Master.SetErrors(mUnit.BrokenRulesText);
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
private void CloseForm()
|
|
{
|
|
Session.Remove("unit");
|
|
CloseMe();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region link buttons
|
|
|
|
protected void btnUnitModelID_Click(object sender, EventArgs e)
|
|
{
|
|
Util.OpenEditWindow(Page, "UnitModel", CurrentUnit.UnitModelID);
|
|
}
|
|
|
|
#endregion
|
|
}
|