TargetInvocationException - c#-4.0

I wrote the code below:
private void DisplayStartUps()
{
Form2 dialog = new Form2();
if (dialog.ShowDialog(this) == DialogResult.OK)
{
// Read the contents of testDialog's TextBox.
totalTeams = dialog.NumOfTeams;
}
dialog.Dispose();
}
When the form 2 opens, then I click on the "red x" pn the top to close the form. I got the message:
TargetInvocationException was unhandled
What does that mean and how to fix it?

Related

Not sure why code returning an Illegal exception related with input data on java 8

I have written the code below.
I made a database, with type "Integer" to accept number values, string to accept "Letter" values and "Date" to accept Date values.
Once i run it, i get the above captioned error on the JOptionPane dialog box, and after i click exit on "ok" on the Dialog box, and exit on the JFrame window, it returns "Build Successful" on the output Window.
Here is the code:
private void jBtnSaveMemberActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/merinet","root","philo");
String sql = "insert into Membership values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, Integer.parseInt(jTxtMemberNumber.getText()));
pstmt.setString(2, jTxtNewMemberLastName.getText());
pstmt.setString(3, jTxtNewMemberMiddleName.getText());
pstmt.setString(4, jTxtNewMemberFirstName.getText());
pstmt.setDate(5, Date.valueOf(jDateChooserMemberDOB.getDateFormatString()));
pstmt.setInt (6, Integer.parseInt(jTxtNewMemberIdNumber.getText()));
pstmt.setString(7, jComboBoxMemberGender.getItemAt(1));
pstmt.setDate(8, Date.valueOf(jDateChooserMemberDofMembership.getDateFormatString()));
pstmt.setInt(9, Integer.parseInt(jTxtNewMemberPostalAddress.getText()));
pstmt.setString(10, jComboBoxNewMemberCity.getItemAt(1));
pstmt.setString(11, jComboBoxNewMemberCounty.getItemAt(1));
pstmt.setString(12, jComboBoxNewMemberCitizenship.getItemAt(1));
pstmt.setString(13, jComboBoxNewMemberCountry.getItemAt(1));
pstmt.setString(14, jTxtNewMemberEmail.getText());
pstmt.setString(15, jTxtNewMemberCellPhone1.getText());
pstmt.setString(16, jTxtNewMemberCellPhoneNumber2.getText());
conn.close();
}catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}

PXProcessing SetError not showing in UI Grid

This my process screen:
as you can see it throws errors but it doesnt indicate the error mark on the grid.
After clicking the process button, it just unchecks the checkbox in my records
i want the grid to be like this(with the red 'x' mark):
this is my graph :
public PXCancel<PayrollFilter> Cancel;
public PXSetup<PayrollSetup> PayrollSetup;
public PXFilter<PayrollFilter> Filter;
[PXFilterable]
public PXFilteredProcessingJoin<PayrollEmployeeProcess, PayrollFilter,
InnerJoin<EPEmployee,
On<PayrollEmployee.employeeID, Equal<EPEmployee.bAccountID>>,
InnerJoin<Branch,
On<EPEmployee.parentBAccountID, Equal<Branch.bAccountID>>>>,
Where<PayrollEmployee.payPeriodID, Equal<Current<PayrollFilter.payPeriodID>>,
And<Branch.branchID, Equal<Current<AccessInfo.branchID>>>>> EmployeePayrollProcess;
#region Constructor
public PayrollProcess()
{
PayrollSetup setup = PayrollSetup.Current;
EmployeePayrollProcess.SetSelected<PayrollEmployeeProcess.selected>();
EmployeePayrollProcess.SetProcessDelegate(delegate (List<PayrollEmployeeProcess> employees)
{
if (Filter.Current == null) return;
var payPeriod = Filter.Current.PayPeriodID ?? 0;
var payrollPeriod = Filter.Current.PayrollPeriodID ?? 0;
if (payPeriod == 0 || payrollPeriod == 0) return;
PXLongOperation.StartOperation(this, delegate ()
{
bool errorOccured = false;
foreach (PayrollEmployeeProcess employee in employees)
{
PayrollRegisterEntry graph = PXGraph.CreateInstance<PayrollRegisterEntry>();
try
{
graph.ProcessPayroll(employee, payPeriod, payrollPeriod);
PXProcessing<PayrollEmployeeProcess>.SetInfo("Employee processed");
}
catch (Exception ex)
{
errorOccured = true;
//employees.IndexOf(employee),
PXProcessing<PayrollEmployeeProcess>.SetError(ex);
}
finally
{
graph.Clear();
}
}
if (errorOccured) throw new PXException("At least one employee was not processed.");
});
});
// EmployeePayrollProcess.
}`
can anyone can help me? I'm using Acumatica 6
Throwing an exception in Acumatica sets the error in the header. To set a Row or Field level error you need to set/raise it. There's a few ways to set/raise errors, what they have in common is that they don't use the 'throw' keyword.
For a processing screen with a filter, use the following syntax to raise the error:
PXFilteredProcessing<GridDetailDAC, GridFilterDAC>.SetError(rowIndex, new PXSetPropertyException("Error Message", PXErrorLevel.RowError));
Processing screen without filter:
PXProcessing.SetError(rowIndex, new PXException("Error Message"));

Not able to get control in CodedUI automation test when page get autopostback on some event

I am writing CodedUI automation test for my website in which i have to first select the value from combo-box on that basis the text box get visible, at that moment autopostback occur so after recording the events unable to find text box it throws error that text box not found in UI after selecting combo-box value.
public bool testforSearch()
{
#region Variable Declarations
HtmlComboBox uIDdlDistrictsComboBox = this.UIHttpwwwsbssnaponglobWindow.UISearchYourNameEnglisDocument.UIDdlDistrictsComboBox;
HtmlEdit uITxtEPICNoEdit = this.UIHttpwwwsbssnaponglobWindow.UISearchYourNameEnglisDocument.UITxtEPICNoEdit;
HtmlInputButton uISearchButton = this.UIHttpwwwsbssnaponglobWindow.UISearchYourNameEnglisDocument.UISearchButton;
#endregion
// Go to web page
this.UIHttpwwwsbssnaponglobWindow.LaunchUrl(new System.Uri(this.testforSearchParams.UIHttpwwwsbssnaponglobWindowUrl));
// Select 'Meerut' in 'ddlDistricts' combo box
uIDdlDistrictsComboBox.SelectedItem = this.testforSearchParams.UIDdlDistrictsComboBoxSelectedItem;
if (uITxtEPICNoEdit.WaitForControlExist())
{
// Type 'abcd' in 'txtEPICNo' text box
uITxtEPICNoEdit.Text = this.testforSearchParams.UITxtEPICNoEditText;
}
else
{
return false;
}
// Click 'Search' button
Mouse.Click(uISearchButton, new Point(19, 8));
return true;
}

how to close print dialog when user cancel print preview dialog

I need some help.
My requirement is when the user click on print button it should show a print preview dialog.
if user cancel or close the preview dialog the form must be return to original.
the problem i am facing is print preview dialog box is visible. but i don't know how to capture the print preview tools click events.
public void print()
{
PrintDialog pd = new PrintDialog();
PrintDocument pdoc = new PrintDocument();
PrinterSettings ps = new PrinterSettings();
PaperSize psize = new PaperSize();
pdoc.DefaultPageSettings.Landscape = false;
pd.Document = pdoc;
pd.Document.DefaultPageSettings.PaperSize = psize;
pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);
DialogResult result = pd.ShowDialog();
if (result == DialogResult.OK)
{
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = pdoc;
ppd.ShowDialog();
pdoc.Print();
}
}
if i place the PrintPreviewDialog code before pd.ShowDialog() nothing visible in the preview mode.
this not working
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = pdoc;
ppd.ShowDialog();
DialogResult result = pd.ShowDialog();
if (result == DialogResult.OK)
{
pdoc.Print();
}
DialogResult is not supported in showdialog() with print dialog .
so the worked way is true or false
PrintDialog pri = new PrintDialog();
if (pri.ShowDialog() == true)
{
pri.PrintQueue.AddJob(fileName, fileName,false);
}
else
{
return;
}
you can also not to use pri.ShowDialog() as the if statement already invoking the method also .

Error while editing grid view record

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

Resources