186 lines
6.3 KiB
C#
186 lines
6.3 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 UnitMeterReadings : BaseThemePage
|
|
{
|
|
#region Normal base edit page stuff since we're not using it here
|
|
//private bool checkedforcallback = false;
|
|
//private bool iscallback = false;
|
|
//public bool IsAjaxCallback
|
|
//{
|
|
// get
|
|
// {
|
|
// if (!checkedforcallback)
|
|
// {
|
|
// HttpContext ctx = HttpContext.Current;
|
|
|
|
// iscallback = (
|
|
// ctx != null &&
|
|
// ctx.Request != null &&
|
|
// (ctx.Request.QueryString["rcbID"] != null ||
|
|
// ctx.Request.Form["RadAJAXControlID"] != null));
|
|
// checkedforcallback = true;
|
|
// }
|
|
// return iscallback;
|
|
// }
|
|
//}
|
|
#endregion
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (Util.CurrentUser.IsClientOrHeadOfficeAccount ||
|
|
AyaBizUtils.Right("Object.UnitMeterReading") < (int)SecurityLevelTypes.ReadOnly)
|
|
{
|
|
Util.Denied(Context);
|
|
}
|
|
if (!IsPostBack && !IsAjaxCallback)
|
|
{
|
|
Util.GridInitEditable("UnitMeterReading", Grid, "UnitMeterReading");
|
|
}
|
|
|
|
if (!IsAjaxCallback)
|
|
{
|
|
//Localize the page
|
|
Util.Localize(this.Page);
|
|
this.Title = Util.LocaleText("O.UnitMeterReading") + " - " + UnitNameFetcher.GetUnitNameFromUnitID(new Guid(Request.QueryString["id"].ToString()));
|
|
|
|
if (AyaBizUtils.Right("Object.Report") < (int)SecurityLevelTypes.ReadOnly)
|
|
mnu.Items[0].Visible = false;
|
|
else
|
|
Util.ReportFillList(mnu.Items[0], UnitMeterReadingList.ReportKey, "");
|
|
|
|
}
|
|
}
|
|
|
|
#region Grid populate and edit
|
|
protected void Grid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
|
|
{
|
|
Grid.DataSource = UnitMeterReadingList.GetList(new Guid(Request.QueryString["id"].ToString()),"");
|
|
|
|
}
|
|
protected void Grid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
|
|
{
|
|
if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
|
|
{
|
|
GridEditableItem edititem = (GridEditableItem)e.Item;
|
|
Util.Localize(edititem);
|
|
}
|
|
|
|
if (e.Item is GridDataItem)
|
|
{
|
|
GridNameValueCellItem gnv = ((UnitMeterReadingList.UnitMeterReadingListInfo)e.Item.DataItem).LT_UnitMeterReading_Label_WorkorderItemID;
|
|
GridDataItem dataItem = e.Item as GridDataItem;
|
|
if (e.Item.IsInEditMode)
|
|
{
|
|
|
|
//RadComboBox cb = e.Item.FindControl("cbtitle") as Telerik.Web.UI.RadComboBox;
|
|
//Util.ComboPopulateBizList("ContactTitle", cb, false, null);
|
|
//cb.SelectedValue = selectedTitleID;
|
|
|
|
}
|
|
else
|
|
{
|
|
GridColumn gc=e.Item.OwnerTableView.Columns.FindByUniqueName("LT_UnitMeterReading_Label_WorkorderItemID");
|
|
HyperLink hl = dataItem[gc].Controls[0] as HyperLink;
|
|
|
|
if (gnv.Value != Guid.Empty)
|
|
{
|
|
Guid woid = WorkorderIDFetcher.GetWorkorderByRelative(RootObjectTypes.WorkorderItem, gnv.Value);
|
|
hl.NavigateUrl = "WorkorderEdit.aspx?id=" + woid.ToString();
|
|
hl.Text = gnv.Display;
|
|
hl.Target = "_blank";
|
|
}
|
|
else
|
|
{
|
|
hl.NavigateUrl = "";
|
|
hl.Text = "";
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void Grid_UpdateCommand(object source, GridCommandEventArgs e)
|
|
{
|
|
if (e.Item is GridEditFormItem)
|
|
{
|
|
|
|
GridEditFormItem editFormItem = e.Item as GridEditFormItem;
|
|
|
|
TextBox notes = editFormItem.FindControl("tbNotes") as TextBox;
|
|
TextBox meter = editFormItem.FindControl("tbMeter") as TextBox;
|
|
Telerik.Web.UI.RadDateTimePicker dp = editFormItem.FindControl("dtMeterDate") as Telerik.Web.UI.RadDateTimePicker;
|
|
UnitMeterReading u = UnitMeterReading.NewItem();
|
|
u.UnitID = new Guid(Request.QueryString["id"].ToString());
|
|
if (Request.QueryString["woitemid"] != null)
|
|
{
|
|
u.WorkorderItemID = new Guid(Request.QueryString["woitemid"].ToString());
|
|
}
|
|
u.MeterDate = dp.DbSelectedDate;
|
|
u.Meter = Util.ParseLong(meter.Text);
|
|
u.Description = Util.ObjectToString(notes.Text);
|
|
u.Save();
|
|
//TODO: No broken rules for meter reading so no need to
|
|
//cancel, but if in future a broken rule is added for empty meter reading
|
|
//or bad date etc then the following will cancel the save and return still
|
|
//in edit mode
|
|
//e.Canceled = true;
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
protected void Grid_ItemCommand(object source, GridCommandEventArgs e)
|
|
{
|
|
if (e.CommandName == RadGrid.InitInsertCommandName)
|
|
{
|
|
e.Canceled = true;
|
|
e.Item.OwnerTableView.InsertItem();
|
|
|
|
|
|
GridEditableItem insertedItem = e.Item.OwnerTableView.GetInsertItem();
|
|
GridEditFormItem editFormItem = insertedItem as GridEditFormItem;
|
|
Telerik.Web.UI.RadDateTimePicker dp = editFormItem.FindControl("dtMeterDate") as Telerik.Web.UI.RadDateTimePicker;
|
|
dp.DbSelectedDate = DBUtil.CurrentWorkingDateTime;//case 1163
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Menu items
|
|
protected void mnu_ItemClick(object sender, Telerik.Web.UI.RadMenuEventArgs e)
|
|
{
|
|
if (e.Item.Value.StartsWith("PRINT"))
|
|
{
|
|
|
|
string[] s = e.Item.Value.Split(',');
|
|
Util.Report(Page, s[1], UnitMeterReadingList.ReportKey,
|
|
UnitMeterReadingList.GetList(new Guid(Request.QueryString["id"].ToString()), ""));
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
}
|