void ordersRadGrid_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item) { GridItem item = e.Item as GridItem; DataRowView drv = e.Item.DataItem as DataRowView; ePointState collectionPointState = (ePointState)Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["CollectionPointStateId"].ToString()); ePointState deliveryPointState = (ePointState)Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["deliveryPointStateId"].ToString()); int collectionPointId = Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["CollectionPointId"].ToString()); int deliveryPointId = Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["DeliveryPointId"].ToString()); DateTime collectAt = Convert.ToDateTime(((System.Data.DataRowView)e.Item.DataItem)["CollectionDateTime"].ToString()); DateTime collectAtBy = Convert.ToDateTime(((System.Data.DataRowView)e.Item.DataItem)["CollectionByDateTime"].ToString()); DateTime deliverAt = Convert.ToDateTime(((System.Data.DataRowView)e.Item.DataItem)["DeliveryDateTime"].ToString()); DateTime deliverAtFrom = Convert.ToDateTime(((System.Data.DataRowView)e.Item.DataItem)["DeliveryFromDateTime"].ToString()); bool collectionIsAnyTime = Convert.ToBoolean(((System.Data.DataRowView)e.Item.DataItem)["CollectionIsAnyTime"].ToString()); bool deliveryIsAnyTime = Convert.ToBoolean(((System.Data.DataRowView)e.Item.DataItem)["DeliveryIsAnyTime"].ToString()); int lcid = Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["LCID"].ToString()); decimal rate = Convert.ToDecimal(((System.Data.DataRowView)e.Item.DataItem)["ForeignRate"].ToString()); HiddenField hidOrderID = e.Item.FindControl("hidOrderChanged") as HiddenField; TextBox txtCollectAt = e.Item.FindControl("txtCollectAt") as TextBox; TextBox txtCollectionAtTime = e.Item.FindControl("txtCollectionAtTime") as TextBox; TextBox txtDeliverAt = e.Item.FindControl("txtDeliverAt") as TextBox; TextBox txtDeliverAtTime = e.Item.FindControl("txtDeliverAtTime") as TextBox; TextBox txtRate = e.Item.FindControl("txtRate") as TextBox; txtCollectAt.Attributes.Add("hidOrderID", hidOrderID.ClientID); txtCollectionAtTime.Attributes.Add("hidOrderID", hidOrderID.ClientID); txtDeliverAt.Attributes.Add("hidOrderID", hidOrderID.ClientID); txtDeliverAtTime.Attributes.Add("hidOrderID", hidOrderID.ClientID); txtRate.Attributes.Add("hidOrderID", hidOrderID.ClientID); CollectionDateManager.TargetControls.Add(new TargetInput(txtCollectAt.UniqueID, true)); DeliveryDateManager.TargetControls.Add(new TargetInput(txtDeliverAt.UniqueID, true)); TimeManager.TargetControls.Add(new TargetInput(txtCollectionAtTime.UniqueID, true)); TimeManager.TargetControls.Add(new TargetInput(txtDeliverAtTime.UniqueID, true)); RateManager.TargetControls.Add(new TargetInput(txtRate.UniqueID, true)); txtCollectAt.Text = collectAt.ToString(); txtCollectionAtTime.Text = collectAt.ToString(); txtDeliverAt.Text = deliverAt.ToString(); txtDeliverAtTime.Text = deliverAt.ToString(); if (collectionIsAnyTime) { txtCollectionAtTime.Text = ""; } else { txtCollectAt.Enabled = txtCollectionAtTime.Enabled = (collectAt == collectAtBy); } if (deliveryIsAnyTime) { txtDeliverAtTime.Text = ""; } else { txtDeliverAt.Enabled = txtDeliverAtTime.Enabled = (deliverAt == deliverAtFrom); } txtRate.Text = rate.ToString(); int orderId = Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["OrderId"].ToString()); string collectionPointDescription = ((System.Data.DataRowView)e.Item.DataItem)["CollectionPointDescription"].ToString(); string deliveryPointDescription = ((System.Data.DataRowView)e.Item.DataItem)["DeliveryPointDescription"].ToString(); bool itemHasPointsThatRequireApproval = false; // Set the hidden field order id. HtmlInputHidden hidOrderId = (HtmlInputHidden)item.FindControl("hidOrderId"); hidOrderId.Value = orderId.ToString(); // Only show approval hyperlink if point is unapproved. if (collectionPointState == ePointState.Unapproved) { itemHasPointsThatRequireApproval = true; Literal litCollectFrom = item.FindControl("litCollectFrom") as Literal; litCollectFrom.Controls.Add(new LiteralControl(string.Format(unApprovedPoint, ((System.Data.DataRowView)e.Item.DataItem)["CollectionPointDescription"].ToString(), string.Format("javascript:openDialogWithScrollbars('ApproveOrderPoint.aspx?PointId={0}&OrderId={1}&Ptype={2}',0,0);", collectionPointId, orderId, "C")))); } else { Label lblCollectFromPoint = (Label)item.FindControl("lblCollectFromPoint"); lblCollectFromPoint.Text = collectionPointDescription; } if (deliveryPointState == ePointState.Unapproved) { itemHasPointsThatRequireApproval = true; Literal litDeliverTo = item.FindControl("litDeliverTo") as Literal; litDeliverTo.Controls.Add(new LiteralControl(string.Format(unApprovedPoint, ((System.Data.DataRowView)e.Item.DataItem)["DeliveryPointDescription"].ToString(), string.Format("javascript:openDialogWithScrollbars('ApproveOrderPoint.aspx?PointId={0}&OrderId={1}&Ptype={2}',0,0);", deliveryPointId, orderId, "D")))); } else { Label lblDeliverToPoint = (Label)item.FindControl("lblDeliverToPoint"); lblDeliverToPoint.Text = deliveryPointDescription; } CheckBox selectionCheckbox = (CheckBox)item.FindControl("chkSelectOrder"); if (itemHasPointsThatRequireApproval) { selectionCheckbox.Enabled = false; } else { selectionCheckbox.Attributes.Add("onclick", "javascript:ChangeList(event,this);"); } } }
void grdOrders_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) { if (e.Item is GridDataItem) { HtmlImage imgOrderBookedIn = (HtmlImage)e.Item.FindControl("imgOrderBookedIn"); HiddenField hidOrderID = e.Item.FindControl("hidOrderChanged") as HiddenField; HyperLink lnkSetBookIn = e.Item.FindControl("lnkSetRequireBookIn") as HyperLink; DataRowView drv = (DataRowView)e.Item.DataItem; ePointState collectionPointState = (ePointState)Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["CollectionPointStateId"].ToString()); ePointState deliveryPointState = (ePointState)Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["deliveryPointStateId"].ToString()); eIdentityStatus collectionOrganisationState = (eIdentityStatus)Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["CollectionOrganisationStateID"].ToString()); eIdentityStatus deliveryOrganisationState = (eIdentityStatus)Convert.ToInt32(((System.Data.DataRowView)e.Item.DataItem)["DeliveryOrganisationStateID"].ToString()); int collectionPointId = (int)drv["CollectionPointId"]; int deliveryPointId = (int)drv["DeliveryPointId"]; int orderID = (int)drv["OrderID"]; palletSpaces += double.Parse(drv["NoPallets"].ToString()); // add the order id to the row as this is the simplest place to put it. e.Item.Attributes.Add("orderid", orderID.ToString()); e.Item.Attributes.Add("palletspaces", drv["NoPallets"].ToString()); CheckBox chkSelectOrder = e.Item.FindControl("chkSelectOrder") as CheckBox; string orderGroupId = ((DataRowView)e.Item.DataItem)["OrderGroupID"].ToString(); //if the order requires booking show the requires book in icon instead and hook up the method call if (drv["BookedInStateID"] != DBNull.Value && (int)drv["BookedInStateID"] == (int)eBookedInState.Required) { imgOrderBookedIn.Src = "/images/star.gif"; imgOrderBookedIn.Attributes.Add("onclick", "ShowBookIn(this," + drv["OrderID"].ToString() + ");"); imgOrderBookedIn.Alt = "Please click to mark as booked in."; imgOrderBookedIn.Visible = true; lnkSetBookIn.Text = "Del"; lnkSetBookIn.ToolTip = "Remove the Requires Book In Setting"; lnkSetBookIn.Attributes.Add("onclick", string.Format("RemoveBookInRequired(this,{0}); return false;", orderID)); } #region Requires Book In Control if (drv["BookedInStateID"] != DBNull.Value && (int)drv["BookedInStateID"] == (int)eBookedInState.NotRequired) { lnkSetBookIn.Text = "Set"; lnkSetBookIn.ToolTip = "Set that this job needs to be Booked In."; lnkSetBookIn.Attributes.Add("onclick", string.Format("SetBookInRequired(this,{0}); return false;", orderID)); } if (drv["BookedInStateID"] != DBNull.Value && (int)drv["BookedInStateID"] == (int)eBookedInState.BookedIn) { lnkSetBookIn.Visible = false; imgOrderBookedIn.Src = "/images/tick.gif"; imgOrderBookedIn.Visible = true; } #endregion #region rate Details int lcid = (int)drv["LCID"]; decimal rate = (decimal)drv["ForeignRate"]; TextBox txtRate = e.Item.FindControl("txtRate") as TextBox; CultureInfo culture = new CultureInfo(lcid); txtRate.Attributes.Add("symbol", culture.NumberFormat.CurrencySymbol); txtRate.Text = rate.ToString(); #endregion #region Wire up the Input Manager controls TextBox txtCollectAt = e.Item.FindControl("txtCollectAtDate") as TextBox; TextBox txtCollectAtTime = e.Item.FindControl("txtCollectAtTime") as TextBox; TextBox txtDeliverAtFrom = e.Item.FindControl("txtDeliverAtFromDate") as TextBox; TextBox txtDeliverAtFromTime = e.Item.FindControl("txtDeliverAtFromTime") as TextBox; TextBox txtDeliverAtBy = e.Item.FindControl("txtDeliverByFromDate") as TextBox; TextBox txtDeliverAtByTime = e.Item.FindControl("txtDeliverByFromTime") as TextBox; TextBox txtCollectBy = e.Item.FindControl("txtCollectByDate") as TextBox; TextBox txtCollectByTime = e.Item.FindControl("txtCollectByTime") as TextBox; rimApproveOrder.GetSettingByBehaviorID("DateInputBehaviour").TargetControls.Add(new TargetInput(txtCollectAt.UniqueID, true)); rimApproveOrder.GetSettingByBehaviorID("DateInputBehaviour").TargetControls.Add(new TargetInput(txtDeliverAtFrom.UniqueID, true)); rimApproveOrder.GetSettingByBehaviorID("DateInputBehaviour").TargetControls.Add(new TargetInput(txtDeliverAtBy.UniqueID, true)); rimApproveOrder.GetSettingByBehaviorID("DateInputBehaviour").TargetControls.Add(new TargetInput(txtCollectBy.UniqueID, true)); rimApproveOrder.GetSettingByBehaviorID("TimeInputBehaviour").TargetControls.Add(new TargetInput(txtCollectAtTime.UniqueID, true)); rimApproveOrder.GetSettingByBehaviorID("TimeInputBehaviour").TargetControls.Add(new TargetInput(txtDeliverAtFromTime.UniqueID, true)); rimApproveOrder.GetSettingByBehaviorID("TimeInputBehaviour").TargetControls.Add(new TargetInput(txtDeliverAtByTime.UniqueID, true)); rimApproveOrder.GetSettingByBehaviorID("TimeInputBehaviour").TargetControls.Add(new TargetInput(txtCollectByTime.UniqueID, true)); rimApproveOrder.GetSettingByBehaviorID("NumericInputBehaviour").TargetControls.Add(new TargetInput(txtRate.UniqueID, true)); #endregion #region Handle the Unaproved point bool itemHasPointsOrOrganisationsThatRequireApproval = false; PlaceHolder litViewCollectionOrganisation = e.Item.FindControl("litViewCollectionOrganisation") as PlaceHolder; Label lblCollectFromOrganisation = (Label)e.Item.FindControl("lblCollectFromOrganisation"); String convertedName = string.IsNullOrWhiteSpace(drv["CollectionOrganisationName"].ToString()) ? "Unnamed" : drv["CollectionOrganisationName"].ToString(); if (collectionOrganisationState != eIdentityStatus.Active) { itemHasPointsOrOrganisationsThatRequireApproval = true; litViewCollectionOrganisation.Controls.Add(new LiteralControl(string.Format(unApprovedPoint, string.Format("javascript:openDialogWithScrollbars('ApproveOrderOrganisation.aspx?OrganisationID={0}',700,700);", drv["CollectionOrganisationID"].ToString()), convertedName))); litViewCollectionOrganisation.Controls.Add(new LiteralControl("<br/><span style='color:red'>" + collectionOrganisationState.ToString() + "</span>")); } else { litViewCollectionOrganisation.Controls.Add(new LiteralControl(convertedName)); } PlaceHolder litViewCollectionPoint = e.Item.FindControl("litViewCollectionPoint") as PlaceHolder; if (collectionPointState == ePointState.Unapproved) { itemHasPointsOrOrganisationsThatRequireApproval = true; litViewCollectionPoint.Controls.Add(new LiteralControl(string.Format(unApprovedPoint, string.Format("javascript:openDialogWithScrollbars('ApproveOrderPoint.aspx?PointId={0}&OrderId={1}&Ptype={2}',400,700);", collectionPointId, orderID, "C"), drv["CollectionPointDescription"].ToString()))); litViewCollectionPoint.Controls.Add(new LiteralControl("<br/><span style='color:red'>to be approved</span>")); } else { if (Globals.Configuration.GPSRealtime) { Label lblCollectFromPoint = (Label)e.Item.FindControl("lblCollectFromPoaint"); //lblCollectFromPoint.Text = drv["CollectionPointDescription"].ToString(); ; HyperLink hl = new HyperLink(); if (drv["CollectionLatitude"] != DBNull.Value && double.Parse(drv["CollectionLatitude"].ToString()) != 0) { hl.NavigateUrl = string.Format("javascript:ViewPoint({0}, {1}, '{2}');", drv["CollectionLatitude"].ToString(), drv["CollectionLongitude"].ToString(), Server.HtmlEncode(drv["CollectionPointDescription"].ToString())); hl.Text = Server.HtmlEncode(drv["CollectionPointDescription"].ToString()); litViewCollectionPoint.Controls.Add(hl); } else { litViewCollectionPoint.Controls.Add(new LiteralControl(drv["CollectionPointDescription"].ToString())); } } else { litViewCollectionPoint.Controls.Add(new LiteralControl(drv["CollectionPointDescription"].ToString())); } } PlaceHolder litViewDeliveryOrganisation = e.Item.FindControl("litViewDeliveryOrganisation") as PlaceHolder; Label lblDeliverToOrganisation = (Label)e.Item.FindControl("lblDeliverToOrganisation"); convertedName = string.IsNullOrWhiteSpace(drv["DeliveryOrganisationName"].ToString()) ? "Unnamed" : drv["DeliveryOrganisationName"].ToString(); if (deliveryOrganisationState != eIdentityStatus.Active) { itemHasPointsOrOrganisationsThatRequireApproval = true; litViewDeliveryOrganisation.Controls.Add(new LiteralControl(string.Format(unApprovedPoint, string.Format("javascript:openDialogWithScrollbars('ApproveOrderOrganisation.aspx?OrganisationID={0}',700,700);", drv["DeliveryOrganisationID"].ToString()), convertedName))); litViewDeliveryOrganisation.Controls.Add(new LiteralControl("<br/><span style='color:red'>" + deliveryOrganisationState.ToString() + "</span>")); } else { litViewDeliveryOrganisation.Controls.Add(new LiteralControl(convertedName)); } PlaceHolder litViewDeliveryPoint = e.Item.FindControl("litViewDeliveryPoint") as PlaceHolder; if (deliveryPointState == ePointState.Unapproved) { itemHasPointsOrOrganisationsThatRequireApproval = true; litViewDeliveryPoint.Controls.Add(new LiteralControl(string.Format(unApprovedPoint, string.Format("javascript:openDialogWithScrollbars('ApproveOrderPoint.aspx?PointId={0}&OrderId={1}&Ptype={2}',400,700);", deliveryPointId, orderID, "D"), drv["DeliveryPointDescription"].ToString()))); litViewDeliveryPoint.Controls.Add(new LiteralControl("<br/><span style='color:red'>to be approved</span>")); } else { if (Globals.Configuration.GPSRealtime) { if (drv["DeliveryLatitude"] != DBNull.Value && double.Parse(drv["DeliveryLatitude"].ToString()) != 0) { HyperLink hl = new HyperLink(); hl.Text = drv["DeliveryPointDescription"].ToString(); hl.NavigateUrl = string.Format("javascript:ViewPoint({0}, {1}, '{2}');", drv["DeliveryLatitude"].ToString(), drv["DeliveryLongitude"].ToString(), Server.HtmlEncode(drv["DeliveryPointDescription"].ToString())); if (deliveryPointState == ePointState.Unapproved) { hl.Text = "show"; } else { hl.Text = Server.HtmlEncode(drv["DeliveryPointDescription"].ToString()); } litViewDeliveryPoint.Controls.Add(hl); } else { litViewDeliveryPoint.Controls.Add(new LiteralControl(drv["DeliveryPointDescription"].ToString())); } } else { litViewDeliveryPoint.Controls.Add(new LiteralControl(drv["DeliveryPointDescription"].ToString())); } } if (itemHasPointsOrOrganisationsThatRequireApproval) { chkSelectOrder.Enabled = false; } else { chkSelectOrder.Attributes.Add("onclick", "javascript:ChangeList(event,this);orderCheckChange('" + orderGroupId.ToString() + "', this);"); } #endregion chkSelectOrder.Attributes.Add("orderid", orderID.ToString()); #region display the current time options for the collection and delivery txtCollectAt.Text = ((DateTime)drv["CollectionDateTime"]).ToString("dd/MM/yy"); txtCollectAtTime.Text = ((DateTime)drv["CollectionDateTime"]).ToString("HH:mm"); txtCollectBy.Text = ((DateTime)drv["CollectionByDateTime"]).ToString("dd/MM/yy"); txtCollectByTime.Text = ((DateTime)drv["CollectionByDateTime"]).ToString("HH:mm"); txtDeliverAtFrom.Text = ((DateTime)drv["DeliveryFromDateTime"]).ToString("dd/MM/yy"); txtDeliverAtFromTime.Text = ((DateTime)drv["DeliveryFromDateTime"]).ToString("HH:mm"); txtDeliverAtBy.Text = ((DateTime)drv["DeliveryDateTime"]).ToString("dd/MM/yy"); txtDeliverAtByTime.Text = ((DateTime)drv["DeliveryDateTime"]).ToString("HH:mm"); RadioButtonList rblCollectionTimeOptions = e.Item.FindControl("rblCollectionTimeOptions") as RadioButtonList; if (txtCollectAt.Text == txtCollectBy.Text && txtCollectAtTime.Text == "00:00" && txtCollectByTime.Text == "23:59") { // Any Time rblCollectionTimeOptions.Items.FindByValue("2").Selected = true; txtCollectBy.Style.Add("display", "none"); txtCollectByTime.Style.Add("display", "none"); txtCollectAtTime.Text = string.Empty; } else if (txtCollectAt.Text == txtCollectBy.Text && txtCollectAtTime.Text == txtCollectByTime.Text) { // time booking rblCollectionTimeOptions.Items.FindByValue("1").Selected = true; txtCollectBy.Style.Add("display", "none"); txtCollectByTime.Style.Add("display", "none"); } else { // Booking Window rblCollectionTimeOptions.Items.FindByValue("0").Selected = true; txtCollectBy.Style.Add("display", ""); txtCollectByTime.Style.Add("display", ""); } RadioButtonList rblDeliveryTimeOptions = e.Item.FindControl("rblDeliveryTimeOptions") as RadioButtonList; if (txtDeliverAtFrom.Text == txtDeliverAtBy.Text && txtDeliverAtFromTime.Text == "00:00" && txtDeliverAtByTime.Text == "23:59") { // Any Time rblDeliveryTimeOptions.Items.FindByValue("2").Selected = true; txtDeliverAtBy.Style.Add("display", "none"); txtDeliverAtByTime.Style.Add("display", "none"); txtDeliverAtFromTime.Text = string.Empty; } else if (txtDeliverAtFrom.Text == txtDeliverAtBy.Text && txtDeliverAtFromTime.Text == txtDeliverAtByTime.Text) { // time booking rblDeliveryTimeOptions.Items.FindByValue("1").Selected = true; txtDeliverAtBy.Style.Add("display", "none"); txtDeliverAtByTime.Style.Add("display", "none"); } else { // Booking Window rblDeliveryTimeOptions.Items.FindByValue("0").Selected = true; txtDeliverAtBy.Style.Add("display", ""); txtDeliverAtByTime.Style.Add("display", ""); } #endregion } }