This commit is contained in:
232
source/WBI/WorkorderNew.aspx.cs
Normal file
232
source/WBI/WorkorderNew.aspx.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
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;
|
||||
public partial class WorkorderNew : BaseThemePage
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (Util.CurrentUser.IsClientOrHeadOfficeAccount)
|
||||
{
|
||||
Util.Denied(Context);
|
||||
}
|
||||
|
||||
btnClient.Text = Util.LocaleText("O.Client");
|
||||
|
||||
|
||||
|
||||
switch (BaseObject)
|
||||
{
|
||||
case RootObjectTypes.WorkorderService:
|
||||
if (AyaBizUtils.Right("Object.WorkorderService") < (int)SecurityLevelTypes.ReadOnly)
|
||||
Util.Denied(Context);
|
||||
lblTemplate.Text = Util.LocaleText("O.WorkorderServiceTemplate");
|
||||
mBaseTemplateType = WorkorderTypes.TemplateService;
|
||||
break;
|
||||
case RootObjectTypes.WorkorderQuote:
|
||||
if (AyaBizUtils.Right("Object.WorkorderQuote") < (int)SecurityLevelTypes.ReadOnly)
|
||||
Util.Denied(Context);
|
||||
lblTemplate.Text = Util.LocaleText("O.WorkorderQuoteTemplate");
|
||||
mBaseTemplateType = WorkorderTypes.TemplateQuote;
|
||||
break;
|
||||
case RootObjectTypes.WorkorderPreventiveMaintenance:
|
||||
if (AyaBizUtils.Right("Object.WorkorderPreventiveMaintenance") < (int)SecurityLevelTypes.ReadOnly)
|
||||
Util.Denied(Context);
|
||||
lblTemplate.Text = Util.LocaleText("O.WorkorderPreventiveMaintenanceTemplate");
|
||||
mBaseTemplateType = WorkorderTypes.TemplatePreventiveMaintenance;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (IsPostBack)
|
||||
{
|
||||
mSelectedClientID = Util.ComboValue(cbClient);
|
||||
mSelectedTemplateID = Util.ComboValue(cbTemplates);
|
||||
}
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(edSearch.Text))
|
||||
{
|
||||
|
||||
//special filter by search
|
||||
SearchResultList srl = SearchResultList.GetPickListForObjectType(edSearch.Text, RootObjectTypes.Client);
|
||||
ClientPickList cpl = ClientPickList.GetList(srl.ListPickListID, true);
|
||||
|
||||
//populate the list here manually
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add("Display");
|
||||
dt.Columns.Add("Value", typeof(Guid));
|
||||
|
||||
//add an initial blank row for Guid.empty
|
||||
DataRow drBlank = dt.NewRow();
|
||||
drBlank["Display"] = "-";//Case 344
|
||||
drBlank["Value"] = Guid.Empty;
|
||||
dt.Rows.Add(drBlank);
|
||||
|
||||
foreach (ClientPickList.ClientPickListInfo i in cpl)
|
||||
{
|
||||
DataRow dr = dt.NewRow();
|
||||
dr["Display"] = i.Name;
|
||||
dr["Value"] = i.ID;
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
|
||||
DataView dv = dt.DefaultView;
|
||||
dv.Sort = "Display";
|
||||
cbClient.DataSource = dv;
|
||||
cbClient.DataValueField = "Value";
|
||||
cbClient.DataTextField = "Display";
|
||||
cbClient.DataBind();
|
||||
}
|
||||
else
|
||||
LoadCombo();
|
||||
|
||||
cbClient.SelectedValue = mSelectedClientID.ToString();
|
||||
LoadTemplates();
|
||||
|
||||
}
|
||||
|
||||
private void LoadCombo()
|
||||
{
|
||||
Util.ComboPopulateBizList("Client", cbClient, true, null, true);
|
||||
|
||||
}
|
||||
|
||||
private void LoadTemplates()
|
||||
{
|
||||
cbTemplates.Items.Clear();
|
||||
TemplatePickList UList = TemplatePickList.GetList(mBaseTemplateType,true);
|
||||
foreach (TemplatePickList.TemplatePickListInfo ui in UList)
|
||||
{
|
||||
cbTemplates.Items.Add(new Telerik.Web.UI.RadComboBoxItem( ui.Description,ui.ID.ToString()));
|
||||
}
|
||||
|
||||
if (mBaseTemplateType == WorkorderTypes.TemplateService)
|
||||
cbTemplates.SelectedValue = TemplateServiceResolver.ResolveTemplate(mSelectedClientID, Util.CurrentUserID).ToString();
|
||||
else
|
||||
cbTemplates.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
private RootObjectTypes mBaseObject = RootObjectTypes.Nothing;
|
||||
private RootObjectTypes BaseObject
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
if (mBaseObject==RootObjectTypes.Nothing)
|
||||
{
|
||||
//preset from maingrid, however we're here from somewhere else
|
||||
//i.e. the schedule then default to service workorder
|
||||
if (Session["ActiveObjectType"] == null)
|
||||
return RootObjectTypes.WorkorderService;
|
||||
|
||||
mBaseObject = (RootObjectTypes)Session["ActiveObjectType"];
|
||||
}
|
||||
|
||||
//case 1949
|
||||
//there are only three types of root objects actually used by this page
|
||||
//so if it isn't any of those three then default to service
|
||||
if (mBaseObject != RootObjectTypes.WorkorderService &&
|
||||
mBaseObject != RootObjectTypes.WorkorderQuote &&
|
||||
mBaseObject != RootObjectTypes.WorkorderPreventiveMaintenance)
|
||||
mBaseObject = RootObjectTypes.WorkorderService;
|
||||
|
||||
return mBaseObject;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private WorkorderTypes mBaseTemplateType = WorkorderTypes.Unknown;
|
||||
|
||||
private Guid mSelectedClientID = Guid.Empty;
|
||||
private Guid mSelectedTemplateID = Guid.Empty;
|
||||
protected void btnOK_Click(object sender, ImageClickEventArgs e)
|
||||
{
|
||||
|
||||
if (mSelectedClientID == Guid.Empty)
|
||||
return;
|
||||
|
||||
Workorder w = null;
|
||||
|
||||
Guid gTemplate = mSelectedTemplateID;
|
||||
if (gTemplate != Guid.Empty)
|
||||
{
|
||||
w = Workorder.NewItem(gTemplate, mSelectedClientID);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
switch (BaseObject)
|
||||
{
|
||||
case RootObjectTypes.WorkorderService:
|
||||
w = Workorder.NewItem(WorkorderTypes.Service);
|
||||
break;
|
||||
case RootObjectTypes.WorkorderQuote:
|
||||
w = Workorder.NewItem(WorkorderTypes.Quote);
|
||||
break;
|
||||
case RootObjectTypes.WorkorderPreventiveMaintenance:
|
||||
w = Workorder.NewItem(WorkorderTypes.PreventiveMaintenance);
|
||||
break;
|
||||
}
|
||||
w.ClientID = mSelectedClientID;
|
||||
}
|
||||
|
||||
|
||||
//if we're here from the schedule screen then the url will have two extra parameters
|
||||
//one for time and date and one for scheduleable user
|
||||
if (Request.QueryString["usr"] != null)
|
||||
{
|
||||
WorkorderItemScheduledUser wisu=w.WorkorderItems[0].ScheduledUsers.Add(w.WorkorderItems[0]);
|
||||
wisu.UserID = new Guid(Request.QueryString["usr"].ToString());
|
||||
string start=Request.QueryString["st"].ToString();
|
||||
wisu.StartDate = ParseStartDate(start);
|
||||
wisu.StopDate = ParseStartDate(start).AddMinutes(30);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Put the new unsaved workorder in the cache for a 2 minute window
|
||||
//so that it's available to the workorder edit form which will immediately remove
|
||||
//it from the Cache and put it in the session cache
|
||||
//this is done like this because through experimentation could not find any other
|
||||
//cache method that the workorder would survive between transit from here to
|
||||
//the workorder edit form. Tried session, context etc, tried server.transfer etc
|
||||
//the object would immediately disappear from the cache used when arriving at workorderedit
|
||||
//however using the Cache as below works properly.
|
||||
|
||||
//this is all necessary to support an unsaved workorder so that when user get's to workorderedit
|
||||
//they can exit without saving. It would be super easy to just save it here and open it there
|
||||
//but then they would not get the behaviour they expect from other objects
|
||||
Cache.Insert("workorder" + w.ID.ToString(),
|
||||
w,
|
||||
null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(2));
|
||||
|
||||
string toUrl = "WorkorderEdit.aspx?id=" + w.ID.ToString();
|
||||
Response.Redirect(toUrl, true);
|
||||
}
|
||||
|
||||
private DateTime ParseStartDate(string startparam)
|
||||
{
|
||||
string[] st = startparam.Split('-');
|
||||
//Note: Javascript getmonth function is zero based for no apparent reason
|
||||
//so that's why +1 is added to the second parameter below
|
||||
DateTime dt = new DateTime(Util.ParseInt(st[0]), Util.ParseInt(st[1])+1, Util.ParseInt(st[2]), Util.ParseInt(st[3]), Util.ParseInt(st[4]), 1);
|
||||
return dt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//case 983
|
||||
protected void btnSearch_Click(object sender, ImageClickEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user