333 lines
10 KiB
C#
333 lines
10 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 UnitModelEdit : BaseEditPage
|
|
{
|
|
|
|
#region BizObject
|
|
public GZTW.AyaNova.BLL.UnitModel mUnitModel;
|
|
protected GZTW.AyaNova.BLL.UnitModel CurrentUnitModel
|
|
{
|
|
get
|
|
{
|
|
if (mUnitModel != null) return mUnitModel;
|
|
|
|
string idstring = Request.QueryString["id"];
|
|
Guid oID = Guid.Empty;
|
|
if (!string.IsNullOrEmpty(idstring))
|
|
oID = new Guid(idstring);
|
|
|
|
mUnitModel = (GZTW.AyaNova.BLL.UnitModel)Session["unitmodel"];
|
|
//ensure if object in session is the same as the one requested
|
|
if (mUnitModel == null || (oID != Guid.Empty && mUnitModel.ID != oID))//Case 912
|
|
{
|
|
try
|
|
{
|
|
if (oID != Guid.Empty)
|
|
mUnitModel = GZTW.AyaNova.BLL.UnitModel.GetItem(oID);
|
|
else
|
|
mUnitModel = GZTW.AyaNova.BLL.UnitModel.NewItem();
|
|
|
|
Session["unitmodel"] = mUnitModel;
|
|
}
|
|
catch (System.Security.SecurityException)
|
|
{
|
|
CloseMe();
|
|
}
|
|
}
|
|
|
|
return mUnitModel;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Page events
|
|
private bool bShowCustomFields = false;
|
|
protected void Page_Init()
|
|
{
|
|
if (Util.CurrentUser.IsClientOrHeadOfficeAccount ||
|
|
AyaBizUtils.Right("Object.UnitModel") < (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("UnitModel", 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("unitmodel");
|
|
|
|
if (!bShowCustomFields)
|
|
{
|
|
|
|
divC1.Attributes.Add("class", "onehalfcolumn");
|
|
divC2.Attributes.Add("class", "onehalfcolumn");
|
|
|
|
}
|
|
else
|
|
{
|
|
divC1.Attributes.Add("class", "onethirdcolumn");
|
|
divC2.Attributes.Add("class", "onethirdcolumn");
|
|
|
|
}
|
|
|
|
//case 73
|
|
//create the Wiki menu item
|
|
if (CurrentUnitModel.CanWiki)
|
|
Util.WikiPageInsertMenuItem(Master.Menu, RootObjectTypes.UnitModel, CurrentUnitModel.ID);
|
|
|
|
if (AyaBizUtils.Right("Object.UnitModel") < (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.UnitModel") > (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.UnitModel") + " - " + CurrentUnitModel.Name;
|
|
|
|
}
|
|
|
|
if (Master.AyMessage != null)
|
|
HandleAyMessage();
|
|
|
|
}
|
|
#endregion page events
|
|
|
|
#region Set Data
|
|
private void SetData()
|
|
{
|
|
GZTW.AyaNova.BLL.UnitModel o = CurrentUnitModel;
|
|
|
|
Util.ComboPopulateBizList("UnitModelCategory", cbUnitModelCategoryID, false, null,false);
|
|
cbUnitModelCategoryID.SelectedValue = o.UnitModelCategoryID.ToString();
|
|
Util.ComboInitialize(cbVendor, "Vendor", o.VendorID);
|
|
|
|
|
|
edModelNumber.Text = o.ModelNumber;
|
|
edName.Text = o.Name;
|
|
edUPC.Text = o.UPC;
|
|
edWarrantyLength.Text = o.WarrantyLength.ToString();
|
|
edWarrantyTerms.Text = o.WarrantyTerms;
|
|
edNotes.Text = o.Notes;
|
|
|
|
ckActive.Checked = o.Active;
|
|
ckDiscontinued.Checked = o.Discontinued;
|
|
ckLifeTimeWarranty.Checked = o.LifeTimeWarranty;
|
|
|
|
dtIntroducedDate.DbSelectedDate = o.IntroducedDate;
|
|
dtDiscontinuedDate.DbSelectedDate = o.DiscontinuedDate;
|
|
|
|
//Case 305
|
|
Util.ShowCustomFields("UnitModel", 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], UnitModelList.ReportKey, "");
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region GetData
|
|
private void GetData()
|
|
{
|
|
GZTW.AyaNova.BLL.UnitModel o = CurrentUnitModel;
|
|
|
|
o.UnitModelCategoryID = Util.ComboValue(cbUnitModelCategoryID);
|
|
o.VendorID = Util.ComboValue(cbVendor);
|
|
|
|
|
|
|
|
|
|
|
|
o.ModelNumber = edModelNumber.Text;
|
|
o.Name = edName.Text;
|
|
o.UPC = edUPC.Text;
|
|
o.WarrantyLength = Util.ParseInt(edWarrantyLength.Text);
|
|
o.WarrantyTerms = edWarrantyTerms.Text;
|
|
o.Notes = edNotes.Text;
|
|
o.Active = ckActive.Checked;
|
|
o.Discontinued = ckDiscontinued.Checked;
|
|
o.LifeTimeWarranty = ckLifeTimeWarranty.Checked;
|
|
o.IntroducedDate = dtIntroducedDate.DbSelectedDate;
|
|
o.DiscontinuedDate = dtDiscontinuedDate.DbSelectedDate;
|
|
|
|
|
|
//Case 305
|
|
Util.GetCustomFields("UnitModel", o, this.phCustom);
|
|
}
|
|
#endregion
|
|
|
|
#region Populate combos
|
|
|
|
|
|
protected void cbVendor_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
|
|
{
|
|
Util.ComboPopulateBizList("Vendor", cbVendor, true, e,false);
|
|
}
|
|
|
|
|
|
#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
|
|
{
|
|
UnitModel.DeleteItem(CurrentUnitModel.ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.Master.SetErrors(Util.ReportSQLError(ex));
|
|
return;
|
|
}
|
|
|
|
CloseForm();
|
|
break;
|
|
case "LT:UI.Command.SaveNew":
|
|
if (SaveRecord())
|
|
{
|
|
Session.Remove("unitmodel");
|
|
mUnitModel = null;
|
|
Response.Redirect("UnitModelEdit.aspx");
|
|
}
|
|
break;
|
|
case "LT:UI.Command.RecordHistory":
|
|
Util.PopupAlert(this.Page,
|
|
Util.RecordHistoryText(
|
|
CurrentUnitModel.Creator,
|
|
CurrentUnitModel.Modifier,
|
|
CurrentUnitModel.Created,
|
|
CurrentUnitModel.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,
|
|
UnitModelList.GetListForSingleItem(CurrentUnitModel.ID));
|
|
|
|
//else
|
|
// Util.Report(Page, s[1], ClientListDetailed.ReportKey,
|
|
// ClientListDetailed.GetListForSingleItem(CurrentClient.ID));
|
|
|
|
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
private bool SaveRecord()
|
|
{
|
|
if (!CurrentUnitModel.IsDirty) return true;
|
|
if (CurrentUnitModel.IsSavable)
|
|
{
|
|
Session["unitmodel"] = mUnitModel = (UnitModel)mUnitModel.Save();
|
|
|
|
this.Master.SetErrors("");
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
//display broken rules, or whatever, see book
|
|
this.Master.SetErrors(mUnitModel.BrokenRulesText);
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
private void CloseForm()
|
|
{
|
|
Session.Remove("unitmodel");
|
|
CloseMe();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|