error message: exception has been thrown by the target of an invocation - activereports

I get the error in the subject after the second time it’s run basically. It happens on the last line, student_count = Convert...
When it runs the first time it shows the proper format of columns and column names and title of the report, etc. What I mean is when I enter this code under the script tab, and then click on the preview tab, it shows the column names, report title, etc. However, when I click back on the script tab or designer tab and then click back to the preview tab, it throws that error at me. Therefore, I said the second run stuff because it seems it’s doing it after the first time.
I now ran a debugger in MS VS 2008 and I get newline in constant on the last line:
student_count = Convert.ToDecimal(textBox("Detail","txtR0_SisNumber4″).Name);
public Section section(string sectionName)
{
return (Section) rpt.Sections[sectionName];
}
public TextBox textBox(string sectionName, string controlName)
{
return (TextBox) section(sectionName).Controls[controlName];
}
public Picture picture(string sectionName, string controlName)
{
return (Picture) section(sectionName).Controls[controlName];
}
public string textBoxTxt(string section, string name)
{
if( textBox(section, name)!=null){
return textBox(section, name).Text;
}
return "";
}
public void PageHeader_BeforePrint()
{
try{
picture("PageHeader","imgOrgLogo").Image = System.Drawing.Image.FromFile(textBoxTxt("PageHeader", "dataOrgLogo"));
}
catch { }
}
public void PageFooter_BeforePrint()
{
textBox("PageFooter","txtPageIndicator").Text = "Page "
+ textBoxTxt("PageFooter","txtPageNum")
+ " of "
+ textBoxTxt("PageFooter","txtPageTotal");
}
public void Detail_BeforePrint()
{
decimal student_count, student_total;
string percentage_string;
student_count = Convert.ToDecimal(textBox("Detail","txtR0_SisNumber4″).Name);
}

Convert.ToDecimal(textBox("Detail","txtR0_SisNumber4″).Name);
equals to
Convert.ToDecimal("txtR0_SisNumber4″);
And this might cause the error. I think that this line should be actually look like
Convert.ToDecimal(textBox("Detail","txtR0_SisNumber4″).Value);

Related

Insert multiple lines of text into a Rich Text content control with OpenXML

I'm having difficulty getting a content control to follow multi-line formatting. It seems to interpret everything I'm giving it literally. I am new to OpenXML and I feel like I must be missing something simple.
I am converting my multi-line string using this function.
private static void parseTextForOpenXML(Run run, string text)
{
string[] newLineArray = { Environment.NewLine, "<br/>", "<br />", "\r\n" };
string[] textArray = text.Split(newLineArray, StringSplitOptions.None);
bool first = true;
foreach (string line in textArray)
{
if (!first)
{
run.Append(new Break());
}
first = false;
Text txt = new Text { Text = line };
run.Append(txt);
}
}
I insert it into the control with this
public static WordprocessingDocument InsertText(this WordprocessingDocument doc, string contentControlTag, string text)
{
SdtElement element = doc.MainDocumentPart.Document.Body.Descendants<SdtElement>().FirstOrDefault(sdt => sdt.SdtProperties.GetFirstChild<Tag>().Val == contentControlTag);
if (element == null)
throw new ArgumentException("ContentControlTag " + contentControlTag + " doesn't exist.");
element.Descendants<Text>().First().Text = text;
element.Descendants<Text>().Skip(1).ToList().ForEach(t => t.Remove());
return doc;
}
I call it with something like...
doc.InsertText("Primary", primaryRun.InnerText);
Although I've tried InnerXML and OuterXML as well. The results look something like
Example AttnExample CompanyExample AddressNew York, NY 12345 or
<w:r xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:t>Example Attn</w:t><w:br /><w:t>Example Company</w:t><w:br /><w:t>Example Address</w:t><w:br /><w:t>New York, NY 12345</w:t></w:r>
The method works fine for simple text insertion. It's just when I need it to interpret the XML that it doesn't work for me.
I feel like I must be super close to getting what I need, but my fiddling is getting me nowhere. Any thoughts? Thank you.
I believe the way I was trying to do it was doomed to fail. Setting the Text attribute of an element is always going to be interpreted as text to be displayed it seems. I ended up having to take a slightly different tack. I created a new insert method.
public static WordprocessingDocument InsertText(this WordprocessingDocument doc, string contentControlTag, Paragraph paragraph)
{
SdtElement element = doc.MainDocumentPart.Document.Body.Descendants<SdtElement>().FirstOrDefault(sdt => sdt.SdtProperties.GetFirstChild<Tag>().Val == contentControlTag);
if (element == null)
throw new ArgumentException("ContentControlTag " + contentControlTag + " doesn't exist.");
OpenXmlElement cc = element.Descendants<Text>().First().Parent;
cc.RemoveAllChildren();
cc.Append(paragraph);
return doc;
}
It starts the same, and gets the Content Control by searching for it's Tag. But then I get it's parent, remove the Content Control elements that were there and just replace them with a paragraph element.
It's not exactly what I had envisioned, but it seems to work for my needs.

how to read problems explorer view in eclipse programatically

is there any way to read the eclipse problem view programatically in eclipse plugin.
I want to fetch data from the following screen-
Yes: Ask the workbench for all Markers of type IMarker.PROBLEM. The documentation contains a code snippet for this:
IMarker[] problems = null;
int depth = IResource.DEPTH_INFINITE;
try {
problems = resource.findMarkers(IMarker.PROBLEM, true, depth);
} catch (CoreException e) {
// something went wrong
}
To get the workspace root, use ResourcesPlugin.getWorkspace().getRoot();
The file MarkerTypesModel.java contains this code:
private String getWellKnownLabel(String type) {
if (type.equals(IMarker.PROBLEM)) {
return "Problem";//$NON-NLS-1$
}
if (type.equals(IMarker.TASK)) {
return "Task";//$NON-NLS-1$
}
if (type.equals("org.eclipse.jdt.core.problem")) { //$NON-NLS-1$
return "Java Problem";//$NON-NLS-1$
}
return type;
}
As you can see, it compares the type with a fixed string to produce Java Problem (and the NON_NLS-Comments are wrong, too).

GWT numberformat weird behaviour

I have a GWT project for which the locale is set to fr. I have a custom text field that uses a number format to validate and format the numerical inputs.
The formatting works fine but not the input validation. Here is a snapshot of the method that validates that the new value is a valid percentage (this is called onValueChanged):
private void validateNumber(String newVal){
logger.debug("value changed, newVal="+newVal+", current="+current);
// Attempt to parse value
double val=0;
try{
val=Double.parseDouble(newVal);
}catch(NumberFormatException e){
logger.warn("parsing failed",e);
try{
val=getFormatter().parse(newVal);
}catch(NumberFormatException ex){
logger.warn("parsing with nb format failed",ex);
// on failure: restore previous value
setValue(current,false);
return;
}
}
//some check on min and max value here
}
For example if the starting value is set by the program to "0.2" it will show up as 20,00 % hence using the correct decimal separator.
Now:
if I input 0,1 I get a numberformat exception.
if I input 0.1 it show as 10,00 %
if I 10% (without the space before the '%'), I get a numberformat exception
Do you know how I can modify the method to have 0,1 and 10% identified as valid inputs?
As Colin mentioned, you definitely want to parse and format using a GWT Number Format object, not Double, so the parsing and formatting are properly locale specific.
Below is some code snippets I could find to parse, validate and format a percent number.
Note however the edit process has the % unit hard-coded outside of the text box value, hence no conversion between 20,45% and 0.2045 in the edit process, 20,45 is entered directly and visualized as such. I vaguely recall struggling with such conversion during the edit process but forgot the details as it was a while back. So if it is a critical part of your question and requirements then I am afraid the examples below may be of limited value. Anyway, here they are!
Notations:
TextBox txt = new TextBox();
NumberFormat _formatFloat = NumberFormat.getFormat("#,##0.00");
NumberFormat _formatPercent = NumberFormat.getFormat("##0.00%");
Parsing text entry like "20,45" as 20.45 (not "20,45%" as 0.2045):
txt.setText("20,45"); // French locale format example, % symbol hard-coded outside of text box.
try {
float amount = (float) _formatFloat.parse(txt.getText());
} catch (NumberFormatException e) ...
Parsing & Validating text entry like "20,45":
private class PercentEntryValueChangeHandler implements ValueChangeHandler<String>
{
#Override
public void onValueChange(ValueChangeEvent<String> event)
{
validatePercent((TextBox) event.getSource());
}
};
private void validatePercent(final TextBox percentTextBox)
{
try
{
if (!percentTextBox.getText().isEmpty())
{
final float val = (float) _formatFloat.parse(percentTextBox.getText());
if (isValid(val))
percentTextBox.setText(_formatFloat.format(val));
else
{
percentTextBox.setFocus(true);
percentTextBox.setText("");
Window.alert("Please give me a valid value!");
}
}
}
catch (NumberFormatException e)
{
percentTextBox.setFocus(true);
percentTextBox.setText("");
Window.alert("Error: entry is not a valid number!");
}
}
private boolean isValid(float val) { return 12.5 < val && val < 95.5; }
txt.addValueChangeHandler(new PercentEntryValueChangeHandler());
Formatting 20.45 as "20,45":
float val = 20.45;
txt.setText(_formatFloat.format(val));
Formatting 0.2045 as "20,45%" (read only process, the text box is not editable, the % is set inside the text box):
float val = 0.2045;
txt.setText(_formatPercent.format((double)(val))); // * 100 embedded inside format.
It is not fancy and probably far from perfect but it works!
Any feedback on how to improve upon this implementation is more than welcome and appreciated!
I hope it helps anyway.
I managed to make it work by changing the code to the following:
private void validateNumber(String newVal){
double val=0;
try{
val=getFormatter().parse(newVal);
}catch(NumberFormatException e){
boolean ok=false;
try{
val=NumberFormat.getDecimalFormat().parse(newVal);
ok=true;
}catch(NumberFormatException e1){}
if(!ok){
try{
val=Double.parseDouble(newVal);
}catch(NumberFormatException ex){
setValue(current,false);
// inform user
Window.alert(Proto2.errors.myTextField_NAN(newVal));
return;
}
}
}

How to filter datagridview using text inputted from a rich text box?

I have a datagridview that I want to display a data from a database. But I don't want it to display all of the data. I want it to display the data for a specific ID only. Meaning if the user enters 3 ID, it will display the info for that 3 ID. Hence I want to use a rich text box as a filter so that the user can enter multiple ID for each line in the rich text box. The user can enter the ID No. within the rich text box and the data will be used as a filter to display the data for that particular ID. But I cannot make it read beyond the first line of the rich text box. If I enter just one ID in the first line, it works perfectly, but if I enter a second ID in the second line, or in the third line, then it will not display anything at all. I tried using for loop to read each line of the rich text box but it doesn't work. Any advice or solution??
here is my code :
namespace TrackCon
{
public partial class trackInput : Form
{
public trackInput()
{
InitializeComponent();
}
/*private void trackInput_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'trackingBMSDATADataSet.BRDATA' table. You can move, or remove it, as needed.
this.bRDATATableAdapter.Fill(this.trackingBMSDATADataSet.BRDATA);
}*/
private void trackBtn_Click(object sender, EventArgs e)
{
RichTextBox dynamicRichTextBox = new RichTextBox();
DataTable dt = null;
string connoInput = richTextBox1.Text;
string conString = Properties.Settings.Default.BMSDATAConnectionString;
//string[] RichTextBoxLines = dynamicRichTextBox.Lines;
foreach (char line in richTextBox1.Text)
{
using (SqlCeConnection con = new SqlCeConnection(#"Data Source=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\TrackCon\TrackCon\BMSDATA.sdf;Persist Security Info = True;Password=xxxx"))
{
con.Open();
SqlCeCommand com = new SqlCeCommand("SELECT conno,cmpsno,ctrx,dsysdate,cstnno,corigin FROM BRDATA WHERE conno = '" + richTextBox1.Text + "'OR cmpsno = '" + richTextBox1.Text + "'", con);
SqlCeDataAdapter adap = new SqlCeDataAdapter(com);
DataSet set = new DataSet();
adap.Fill(set);
if (set.Tables.Count > 0)
{
dt = set.Tables[0];
}
dataGridView1.DataSource = dt;
con.Close();
}
}
}
}
}
I suggest to use a TextBox and set MultiLine to true.
Then you can read all the ids like this:
string[] ids = myTextBox.Text.Split('\n');
EDIT:
You can use SQL's IN to find all elements:
string sql = "SELECT conno, etc FROM BRDATA WHERE conno IN (" + String.Join(", ", ids) + ")";

Ajax Popupcontrolextender issues

I have a bizarre problem. I have followed the example here (http://www.4guysfromrolla.com/articles/071107-1.aspx) to display an ajax popup, but it is not working properly.
The problem I have is that the image attributes are not set properly, I checked with Firebug and this is what I get on page 1 after load.
<img src="StyleSheets/magglass.jpg" id="mainContent_TheGrid_MagGlass_0">
Now the bizarre, if I go to page 2, the onmouseover event is set properly for all images and if I come back to page 1, it is set properly too, e.g.
<img src="StyleSheets/magglass.jpg" onmouseover="$find('pce0').showPopup(); " id="mainContent_TheGrid_MagGlass_0">
I stepped through the code and confirmed that the rowcreated event is firing for my grid, for each row
Any Ideas?
My code is slightly different to the example, see below
protected void TheGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Programmatically reference the PopupControlExtender
PopupControlExtender pce = e.Row.FindControl("TheGrid_PopupControlExtender") as PopupControlExtender;
// Set the BehaviorID
string behaviorID = string.Concat("pce", e.Row.RowIndex);
pce.BehaviorID = behaviorID;
// Programmatically reference the Image control
Image i = (Image)e.Row.Cells[0].FindControl("MagGlass");
// Add the client-side attributes (onmouseover & onmouseout)
string OnMouseOverScript = string.Format("$find('{0}').showPopup(); ", behaviorID);
i.Attributes.Add("onmouseover", OnMouseOverScript);
}
}
The GetDynamicContent Method is below, which adds the hidepopup method.
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string GetDynamicContent(string contextKey)
{
GridView MyGrid = (GridView)HttpContext.Current.Session["TheGrid"];
var MyVar = from GridViewRow MyRow in MyGrid.Rows
where MyRow.Cells[MyRow.Cells.Count - 1].Text == contextKey
select MyRow;
//This is the selected row by the user
GridViewRow MyGridRow = MyVar.SingleOrDefault();
//MyGridRow.Cells[3].Text is the log entry.
string MyTable = #"<table class=""PopUpTable""><tr><td><textarea class=""textarea"">"
+ MyGridRow.Cells[3].Text + "</textarea></td>";
//MyGridRow.RowIndex is used to determine the name of popup control for the hidepopup script
MyTable += "<td><button type=\"button\" class=\"PopUpButton\" onclick=\"$find('pce" + MyGridRow.RowIndex.ToString() + "').hidePopup();\">Close</button></td></tr></table>";
return MyTable;
}
This is the pageIndexChanging event
protected void TheGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
TheGrid.PageIndex = e.NewPageIndex;
LoadFromDB();
}
The LoadFromDB method here:
private void LoadFromDB()
{
try
{
LOGDBDataContext LDC = new LOGDBDataContext(ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString);
string Query = #"DateTimeStamp >= #0 and DateTimeStamp <= #1";
var Tolo = LDC
.Logs
.Where(Query, this.FromCalendar.SelectedDate, this.ToCalendar.SelectedDate)
.OrderBy("DateTimeStamp desc")
.Select("new (LogID, DateTimeStamp, Organization, LogEntry, ServerHostname)");
TheGrid.DataSource = Tolo;
TheGrid.DataBind();
}
catch (Exception ex)
{
//do something here
}
}
Never Mind, found the answer.
Poor Debugging
A poor attempt at
clearing the gridview that was not
invoked by the pagechanging event
Incompetence thy name is yomismo