Error while editing grid view record - c#-4.0

I got following error while i am clicked edit button on grid view for 2 page
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
can you please specify what should i have to do to remove this error
following is the code for edit command, It works well when i am on first page but gives erro if i goes to another any page in grid view
protected void GVviewReminder_RowCommand(object sender, GridViewCommandEventArgs e)
{
lblError.Text = "";
if (e.CommandName == "Edit")
{
GridViewRow selectedRow = GVviewReminder.Rows[Convert.ToInt32(e.CommandArgument)];
string ID = selectedRow.Cells[1].Text;
Response.Redirect("edit_health_reminder.aspx?HealthReminderIsOpen=true&id=" + ID);
}
}

The error log says index out of range so look at collections.
GVviewReminder.Rows[Convert.ToInt32(e.CommandArgument)]
selectedRow.Cells[1].Text

Related

Notes Window Not Updating on Bill

I am updating the Notes on a Bill via some custom code in a graph extension. My problem is that the window that pops open when you click on the Notes icon in the upper-right corner of the screen does not reflect the changes that I made to the notes in code. If I use the < > buttons to scroll to another Bill and then back to the one that I updated, it shows the changes. So, I'm not sure how to get the notes to refresh.
This is on the AP301000 screen. I have tried Base.Document.View.RequestRefresh(), Base.Document.View.Clear() and calling the Base.Actions.PressSave() after my code changes the note for the Bill.
TIA!
Here's Code:
protected void APTran_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
{
var row = (APTran)e.Row;
if (row == null)
return;
//*********************** copy notes and file attachments from PO lines and header to the Bill **********************************
if ((row.PONbr != null) && (row.POLineNbr != null))
{
POOrderEntry poEntry = (POOrderEntry)PXGraph.CreateInstance(typeof(POOrderEntry));
poEntry.Clear();
POOrder poHeader = poEntry.Document.Search<POOrder.orderNbr>(row.PONbr);
poEntry.Document.Current = poHeader;
POLine poLine = poEntry.Transactions.Search<POLine.lineNbr>(row.POLineNbr);
if (poLine != null)
{
PXNoteAttribute.CopyNoteAndFiles(poEntry.Caches[typeof(POLine)], poLine, cache, row); //// - use this for Notes and Files.
// making of copy of what the note is on the APInvoice at this point because the PXNoteAttribute.CopyNoteAndFiles() below
// will replace what is in the notes with what is in the PO instead of appending.
string oldNote = PXNoteAttribute.GetNote(Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current);
PXNoteAttribute.CopyNoteAndFiles(poEntry.Caches[typeof(POOrder)], poHeader, Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current);
PXNoteAttribute.SetNote(Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current, oldNote);
Base.Actions.PressSave();
string poNote = PXNoteAttribute.GetNote(poEntry.Caches[typeof(POOrder)], poHeader);
if (!string.IsNullOrEmpty(poNote))
{
//string oldNote = PXNoteAttribute.GetNote(Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current);
if ((oldNote == null) || !oldNote.Contains(poNote))
{
string newNote = "";
if (string.IsNullOrEmpty(oldNote))
newNote = poNote;
else
newNote = oldNote + Environment.NewLine + poNote;
//These 2 lines will not update the note without the PressSave();
//Guid noteGuid = (Guid)PXNoteAttribute.GetNoteID(Base.Caches[typeof(APInvoice)], Base.CurrentDocument.Current, null);
//PXNoteAttribute.UpdateNoteRecord(Base.Caches[typeof(APInvoice)], noteGuid, newNote);
PXNoteAttribute.SetNote(Base.Caches[typeof(APInvoice)], Base.Document.Current, newNote); // Sets the note but, screen does not refresh.
//Base.Caches[typeof(APInvoice)].Update(Base.Document.Current); //Does not refresh Notes on screen.
//PXNoteAttribute.GetNoteID<APInvoice.noteID>(Base.Caches[typeof(APInvoice)], Base.Document.Current); // Does not update the screen.
//Base.Caches[typeof(Note)].IsDirty = true; /// No Effect.
//Base.Caches[typeof(Note)].Clear(); //this has no effect on refreshing the notes that are seen on the screen.
//Base.Caches[typeof(NoteDoc)].Clear();
//Base.Actions.PressSave(); // blanks out the header if the Bill has never been saved. Does not refresh note on screen.
//Base.Document.View.Clear();
//Base.Document.View.RequestRefresh(); // this wipes out the new note if adding a second PO.
}
}
}
}
}
Here's the fix for this that I deployed. I'm thinking that there is a better way to do this but, seems to be working ok for now. I added this:
[PXOverride]
public void Persist(Action persist)
{
persist();
APInvoice invoice = (APInvoice)Base.CurrentDocument.SelectSingle();
if (invoice.Status == "H")
throw new PXRedirectRequiredException(Base, "Reloading Notes...");
}
So, I overrode the Persist() in order to refresh the page but, I only do that if the Bill is still on Hold. This refreshes the Notes that are shown on the screen.

Change String length or decimal precision of field attribute dynamically

I'm trying to use setup data from one table to allow me to format fields on the fly / dynamically. I know I can change field names and visibility based on the PXUIFieldAttribute class, but changing the precision or string length is a bit trickier, obviously. From the research I've done, I've come up with the following example code that seems like it should work - but I get the error:
"Unable to cast object of type 'PX.Data.PXUIFieldAttribute' to type 'PX.Data.PXDBDecimalAttribute'.
I don't see why this is occurring...
protected virtual void xTACOpenSourceDetail_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
{
var osd = (PXCache)sender;
foreach (PXDBDecimalAttribute attribute in this.Caches<xTACOpenSourceDetail>().GetAttributes("Number1"))
{
PXDBDecimalAttribute someAttribute = attribute as PXDBDecimalAttribute;
if (someAttribute != null)
{
someAttribute.DBProperties._precision = 4;
}
}
}
I just tried the below code in sales order screen and it seems working!
var props = typeof(SOOrder).GetProperties().Where(prop => Attribute.IsDefined(prop, typeof(PXDecimalAttribute)));
foreach (System.Reflection.PropertyInfo item in props)
{
PXDecimalAttribute.SetPrecision(this.Base.Caches[typeof(SOOrder)], item.Name, 1);
}
You might need to change this to match your DAC.

Error: Reference Nbr. cannot be found in the system.."}

I customized the ARPaymentEntry in which it creates a Journal Voucher Entry with created Credit Memo, it retrieves the Credit Memo applies the open invoice that is also applied in the current payment. when I create the instance to call the Credit Memo and add the Invoice in ARAdjust table, an error occurs when trying to insert it, giving a Reference Nbr cannot be found in the system, although when I'm trying to manually applying it I could see the open invoice.
public void ReleaseCreditMemo(string refNbr)
{
try
{
ARPaymentEntry docGraph = PXGraph.CreateInstance<ARPaymentEntry>();
List<ARRegister> list = new List<ARRegister>();
ARPayment payment;
ARRegister invoice = PXSelect<ARRegister, Where<ARRegister.docType, Equal<Required<ARRegister.docType>>, And<ARRegister.refNbr, Equal<Required<ARRegister.refNbr>>>>>.Select(docGraph, ARInvoiceType.CreditMemo, refNbr);
docGraph.Document.Current = PXSelect<ARPayment, Where<ARPayment.docType, Equal<Required<ARPayment.docType>>, And<ARPayment.refNbr, Equal<Required<ARPayment.refNbr>>>>>.Select(docGraph, ARInvoiceType.CreditMemo, refNbr);
payment = docGraph.Document.Current;
list.Add(payment);
foreach (ISARWhTax item in ARWhLine.Select())
{
decimal? _CuryAdjgAmt = payment.CuryOrigDocAmt > invoice.CuryDocBal ? invoice.CuryDocBal : payment.CuryOrigDocAmt;
decimal? _CuryAdjgDiscAmt = payment.CuryOrigDocAmt > invoice.CuryDocBal ? 0m : invoice.CuryDiscBal;
ARAdjust adj = new ARAdjust();
adj.AdjdBranchID = item.AdjdBranchID;
adj.AdjdDocType = ARInvoiceType.Invoice;
adj.AdjdRefNbr = item.AdjdRefNbr;
adj.AdjdCustomerID = item.CustomerID;
adj.AdjdDocDate = invoice.DocDate;
adj.CuryAdjgAmt = _CuryAdjgAmt;
adj.CuryAdjdDiscAmt = _CuryAdjgDiscAmt;
if (docGraph.Document.Current.CuryUnappliedBal == 0m && docGraph.Document.Current.CuryOrigDocAmt > 0m)
{
throw new PXLoadInvoiceException();
}
//This line code below OCCURS THE ERROR
docGraph.Adjustments.Insert(adj);
}
docGraph.Save.Press();
PXLongOperation.StartOperation(docGraph, delegate() { ARDocumentRelease.ReleaseDoc(list, false); });
}
catch (Exception ex)
{
throw new PXException(ex.Message);
}
}
I would look at the selector of the field causing the error ("Reference Nbr.") as having a selector on a field will validate the entered value to the selector's select statement (unless validatevalue=false for the selector). Maybe the selector will give you some pointers as to what is missing or causing the validation to fail.
I figured it out it that after the code below executes it does not immediately updates the View. So what I did is to execute my code at ARPayment_RowSelected event with a conditional statement if the document is released.
PXLongOperation.StartOperation(this.Base, delegate() { ARDocumentRelease.ReleaseDoc(list, false); });

(J2ME polish) Click gesture for touchscreen support

im trying to follow this, but got no luck. I'm using treeItem or Choicegroup and it can be selected but can't be clicked, like when clicked, it will go to the next page.
I don't wanna use X and Y coz my Item is dynamic which it was generated through XML. therefore, the item location will be changed. I want a touch pointer for a specific item like the choice group that Im using.
http://www.enough.de/products/j2me-polish/documentation/lush-ui/touch-support.html#gesture-click
You have Choicegroup and you want that on click of item it should go to next page then:
you can use :
choicegroupname.addCommand(command of Command.OK type, say commandOpen);
then,you can set setItemCommandListener to commandOpen and in commandAction you can traverse choicegroup so that you can get focused index and you do your code there,then break.Hope this helps.
you can do this like:
commandOpen.setItemCommandListener(new ItemCommandListener() {
public void commandAction(Command cmd, Item arg1) {
//size will be count of items
for(int i=0 ; i < size ; i++){
if(choicegroupname.focusedIndex== i){
//Do your code
return;
}
}
}
});

Why is UILabel not updating?

I have created a view that shows lost connection messages to users which pops over the current view. I want to update the view periodically based on connection status changes.
I can properly get the view and change the text of a label (verified with WriteLines), but nothing changes on the actual display. I even tried removing the view and readding it and calling SetNeedsDisplay, but nothing seems to help.
I have a global variable called OverView:
public static UIView OverView;
I create the label subview, add it to the overview and pop the overview in front of the current view:
UILabel labelTitle = new UILabel();
labelTitle.Text = title;
UIView labelTitleView = (UIView) labelTitle;
labelTitleView.Tag = 5000;
OverView.AddSubview(labelTitleView);
curView.InsertSubviewAbove(OverView, curView);
curView.BringSubviewToFront(OverView);
And then at a later time, I try to modify it like this from another function:
if ((OverView != null) && (OverView.Subviews != null))
{
for (int i = 0; i < OverView.Subviews.Length; i++)
{
WriteToConsole("Type: " + OverView.Subviews[i].GetType());
if (OverView.Subviews[i] is UILabel)
{
WriteToConsole("Found Label with Tag: " + ((UILabel)(OverView.Subviews[i])).Tag + " Text: " + ((UILabel)(OverView.Subviews[i])).Text);
if (((UILabel)(OverView.Subviews[i])).Tag == 5000)
{
WriteToConsole("Setting subview Title to: " + lostConnectionTitle);
lock (overViewLocker)
{
appReference.InvokeOnMainThread(delegate
{
UILabel tempLabel = ((UILabel)(OverView.Subviews[i]));
tempLabel.Text = lostConnectionTitle;
OverView.Subviews[i].RemoveFromSuperview();
OverView.AddSubview(tempLabel);
OverView.BringSubviewToFront(tempLabel);
OverView.SetNeedsLayout();
OverView.SetNeedsDisplay();
WriteToConsole("SetNeedsDisplay");
});
}
}
}
}
}
Have you tried to use delegate methods on your label, and change their value when events occur ?
For example, if your event is clicking on a button, you should have something like that:
yourLabel.Text = "Init";
buttonExample.TouchUpInside += (sender, e) => {
yourLabel.Text = "I touched my button";
};
When your View loads, you'll see "Init" and your button and once you click on it, the label text changed.
Xamarin has some explanation about events and delegate methods here.
I hope that helped.

Resources