314 lines
9.9 KiB
C#
314 lines
9.9 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 LoanItemEdit : BaseEditPage
|
|
{
|
|
|
|
#region BizObject
|
|
public GZTW.AyaNova.BLL.LoanItem mLoanItem;
|
|
protected GZTW.AyaNova.BLL.LoanItem CurrentLoanItem
|
|
{
|
|
get
|
|
{
|
|
if (mLoanItem != null) return mLoanItem;
|
|
|
|
string idstring = Request.QueryString["id"];
|
|
Guid oID = Guid.Empty;
|
|
if (!string.IsNullOrEmpty(idstring))
|
|
oID = new Guid(idstring);
|
|
|
|
mLoanItem = (GZTW.AyaNova.BLL.LoanItem)Session["loanitem"];
|
|
//ensure if object in session is the same as the one requested
|
|
if (mLoanItem == null || (oID != Guid.Empty && mLoanItem.ID != oID))//Case 912
|
|
{
|
|
try
|
|
{
|
|
if (oID != Guid.Empty)
|
|
mLoanItem = GZTW.AyaNova.BLL.LoanItem.GetItem(oID);
|
|
else
|
|
mLoanItem = GZTW.AyaNova.BLL.LoanItem.NewItem();
|
|
|
|
Session["loanitem"] = mLoanItem;
|
|
}
|
|
catch (System.Security.SecurityException)
|
|
{
|
|
CloseMe();
|
|
}
|
|
}
|
|
|
|
return mLoanItem;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Page events
|
|
private bool bShowCustomFields = false;
|
|
protected void Page_Init()
|
|
{
|
|
if (Util.CurrentUser.IsClientOrHeadOfficeAccount ||
|
|
AyaBizUtils.Right("Object.LoanItem") < (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("LoanItem", 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("loanitem");
|
|
|
|
if (!bShowCustomFields)
|
|
{
|
|
rc1.Visible = false;
|
|
divC1.Attributes.Add("class", "onehalfcolumn");
|
|
divC2.Attributes.Add("class", "onehalfcolumn");
|
|
|
|
}
|
|
else
|
|
{
|
|
rc1.Visible = true;
|
|
divC1.Attributes.Add("class", "onethirdcolumn");
|
|
divC2.Attributes.Add("class", "onethirdcolumn");
|
|
|
|
}
|
|
|
|
if (AyaBizUtils.Right("Object.LoanItem") < (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.LoanItem") > (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();
|
|
Page.Title = Util.LocaleText("O.LoanItem") + " - " + CurrentLoanItem.Name + " " + CurrentLoanItem.Serial;
|
|
|
|
//case 73
|
|
//create the Wiki menu item
|
|
if (CurrentLoanItem.CanWiki)
|
|
Util.WikiPageInsertMenuItem(Master.Menu, RootObjectTypes.LoanItem, CurrentLoanItem.ID);
|
|
}
|
|
|
|
if (Master.AyMessage != null)
|
|
HandleAyMessage();
|
|
|
|
}
|
|
#endregion page events
|
|
|
|
#region Set Data
|
|
private void SetData()
|
|
{
|
|
GZTW.AyaNova.BLL.LoanItem o = CurrentLoanItem;
|
|
|
|
Util.ComboPopulateAndInitializeBizList(cbRegion, "Region", o.RegionID, true);//case 58
|
|
|
|
edName.Text = o.Name;
|
|
edSerial.Text = o.Serial;
|
|
edNotes.Text = o.Notes;
|
|
|
|
ckActive.Checked = o.Active;
|
|
|
|
//Case 512
|
|
this.edRateHour.Text = o.RateHour.ToString("c");
|
|
this.edRateHalfDay.Text = o.RateHalfDay.ToString("c");
|
|
this.edRateDay.Text = o.RateDay.ToString("c");
|
|
this.edRateWeek.Text = o.RateWeek.ToString("c");
|
|
this.edRateMonth.Text = o.RateMonth.ToString("c");
|
|
this.edRateYear.Text = o.RateYear.ToString("c");
|
|
|
|
|
|
//Case 305
|
|
Util.ShowCustomFields("LoanItem", 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], LoanItemList.ReportKey, "");
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region GetData
|
|
private void GetData()
|
|
{
|
|
GZTW.AyaNova.BLL.LoanItem o = CurrentLoanItem;
|
|
|
|
o.RegionID = Util.ComboValue(cbRegion);//case 58
|
|
|
|
o.Name = edName.Text;
|
|
o.Serial = edSerial.Text;
|
|
|
|
o.Notes = edNotes.Text;
|
|
o.Active = ckActive.Checked;
|
|
|
|
//Case 512
|
|
o.RateHour = Util.ParseDecimal(edRateHour.Text);
|
|
o.RateHalfDay = Util.ParseDecimal(edRateHalfDay.Text);
|
|
o.RateDay = Util.ParseDecimal(edRateDay.Text);
|
|
o.RateWeek = Util.ParseDecimal(edRateWeek.Text);
|
|
o.RateMonth = Util.ParseDecimal(edRateMonth.Text);
|
|
o.RateYear = Util.ParseDecimal(edRateYear.Text);
|
|
|
|
|
|
//Case 305
|
|
Util.GetCustomFields("LoanItem", 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
|
|
{
|
|
LoanItem.DeleteItem(CurrentLoanItem.ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.Master.SetErrors(Util.ReportSQLError(ex));
|
|
return;
|
|
}
|
|
|
|
CloseForm();
|
|
break;
|
|
case "LT:UI.Command.SaveNew":
|
|
if (SaveRecord())
|
|
{
|
|
Session.Remove("loanitem");
|
|
mLoanItem = null;
|
|
Response.Redirect("ClientEdit.aspx");
|
|
}
|
|
break;
|
|
case "LT:UI.Command.RecordHistory":
|
|
Util.PopupAlert(this.Page,
|
|
Util.RecordHistoryText(
|
|
CurrentLoanItem.Creator,
|
|
CurrentLoanItem.Modifier,
|
|
CurrentLoanItem.Created,
|
|
CurrentLoanItem.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,
|
|
LoanItemList.GetListForSingleItem(CurrentLoanItem.ID));
|
|
|
|
//else
|
|
// Util.Report(Page, s[1], ClientListDetailed.ReportKey,
|
|
// ClientListDetailed.GetListForSingleItem(CurrentClient.ID));
|
|
|
|
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
private bool SaveRecord()
|
|
{
|
|
if (!CurrentLoanItem.IsDirty) return true;
|
|
if (CurrentLoanItem.IsSavable)
|
|
{
|
|
Session["loanitem"] = mLoanItem = (LoanItem)mLoanItem.Save();
|
|
|
|
this.Master.SetErrors("");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
//display broken rules, or whatever, see book
|
|
this.Master.SetErrors(mLoanItem.BrokenRulesText);
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
private void CloseForm()
|
|
{
|
|
Session.Remove("loanitem");
|
|
CloseMe();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|