I have a .net page which needs to open a new pop-up window when certain conditions are not met in the code behind file. I have the following code:
private bool isValidPart(string partNo)
{
if (!string.IsNullOrEmpty(partNo))
{
DataBase.DBManager dm = new DBManager();
if (!Convert.ToBoolean(dm.ExecScalar("usp_getPart", partNo)))
{
string url = "test.aspx";
string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
return false;
}
}
return true;
}
I put a break point and verified it. It hits the line but the pop-up window does not open up. It just simply moves to next line and returns false.
May I please know the reason behind it?
#yog2411 This is the code which checks that isvalidpart()
private bool SetRowData()
{
int rowIndex = 0;
if (ViewState["CurrentData"] != null)
{
DataTable dtCurrentData = (DataTable)ViewState["CurrentData"];
DataRow drCurrentRow = null;
if (dtCurrentData.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentData.Rows.Count; i++)
{
TextBox TextCustomerName = (TextBox)gvInventory.Rows[rowIndex].Cells[1].FindControl("txtCustomerName");
TextBox TextPONumber = (TextBox)gvInventory.Rows[rowIndex].Cells[2].FindControl("txtPONumber");
TextBox TextPartNumber = (TextBox)gvInventory.Rows[rowIndex].Cells[3].FindControl("txtPartNumber");
TextBox TextQuantity = (TextBox)gvInventory.Rows[rowIndex].Cells[4].FindControl("txtQuantity");
//TextBox TextReqShipDate = (TextBox)gvInventory.Rows[rowIndex].Cells[5].FindControl("txtReqShipDate");
if (!isValidPart(TextPartNumber.Text))
return false;
drCurrentRow = dtCurrentData.NewRow();
drCurrentRow["RowNumber"] = i + 1;
dtCurrentData.Rows[i - 1]["CustName"] = TextCustomerName.Text;
dtCurrentData.Rows[i - 1]["PONum"] = TextPONumber.Text;
dtCurrentData.Rows[i - 1]["PartNum"] = TextPartNumber.Text;
dtCurrentData.Rows[i - 1]["Qty"] = TextQuantity.Text;
// dtCurrentData.Rows[i - 1]["ReqShipDate"] = TextReqShipDate.Text;
rowIndex++;
}
ViewState["CurrentData"] = dtCurrentData;
gvInventory.DataSource = dtCurrentData;
gvInventory.DataBind();}
}
SetPreviousData();
return true;
}
try writing a JS function
function showMyPopUp(myUrl) {
//I have this settings and it works like a popUp,
//I just going to write the properties you have, but you can change them for these ones
//var CustomFeatures = 'titlebar=no, status=no,menubar=no,resizable=no,scrollbars=no,toolbar=no,location=no,width=300,height=100,top=100,left=100';
var CustomFeatures = 'resizable=yes,width=300,height=100,top=100,left=100';
window.open(myUrl, '_blank', CustomFeatures, true);
}
and in your C# this
string url = "test.aspx";
string myCallfunction = "showMyPopUp('" + url + "');"
ScriptManager.RegisterStartupScript(this, this.GetType(), "Funct", myCallfunction , true);
hope it helps
Related
Am tryinng to read PDf and inside PDF controls. my pdf is generated by adobe pdf library. getting null acro fields.but my form have 4 check boxes. 4 check boxed i can use to check or uncheck . i want checkbox is checked or not.
i used itextsharp to read pdf but, it is not finding controls.
private static string GetFormFieldNamesWithValues(PdfReader pdfReader)
{
return string.Join("\r\n", pdfReader.AcroFields.Fields
.Select(x => x.Key + "=" +
pdfReader.AcroFields.GetField(x.Key) + "=" + pdfReader.AcroFields.GetFieldType(x.Key)).ToArray());
}
static void Main(string[] args)
{
DataTable filedDetails;
DataRow dr;
string cName="";
string cType = "";
string cValue = "";
int txtCount = 0;
int btnCount = 0;
int chkBoxCount = 0;
int rdButtonCount = 0;
int dropDownCount = 0;
var fileName = "C:\\PreScreenings\\ViewPDF Cien.pdf";// PDFFileName.Get(context);
//var fileName = #"C:\Users\465sanv\Downloads\Read-PDF-Controls-master\ReadPDFControl\Input\David1990.pdf";
var fields = GetFormFieldNamesWithValues(new PdfReader(fileName));
string[] splitRows = fields.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
filedDetails = new DataTable("PDF Table");
filedDetails.Columns.AddRange(new[] { new DataColumn("Control Name"), new DataColumn("Control Type"), new DataColumn("Control Value") });
foreach (string row in splitRows)
{
dr = filedDetails.NewRow();
string[] str = row.Split("=".ToCharArray(), StringSplitOptions.None);
cName = str[0].ToString();
cValue = str[1].ToString();
if (str[2].ToString() == "1")
{
btnCount++;
cType = "Button" + btnCount.ToString();
}
else if (str[2].ToString() == "2")
{
chkBoxCount++;
cType = "Check Box" + chkBoxCount.ToString();
}
else if (str[2].ToString() == "3")
{
rdButtonCount++;
cType = "Radio Button" + rdButtonCount.ToString();
}
else if (str[2].ToString() == "4")
{
txtCount++;
cType = "Text Field" + txtCount.ToString();
}
else if (str[2].ToString() == "6")
{
dropDownCount++;
cType = "Drop Down" + dropDownCount.ToString();
}
dr[0] = cName;
dr[1] = cType;
dr[2] = cValue;
filedDetails.Rows.Add(dr);
}
}
I have a simple Windows Forms application with a form that has two TextBoxes to find postcode/suburb name:
Enter the suburb name
Enter the postcode
If the postcode (TextBox) has no value entered the form is hung up and it won't submit/return values. Tried a few things but still fails (FormatException was unhandled). Adding any int value it works fine.
private void btnFind_Click(object sender, EventArgs e)
{
//DECLARE ARRAY
string[] arrSuburbName = new string[5];
int[] arrSuburbPC = new int[5];
//POPULATESUBURB NAME ARRAY
arrSuburbName[0] = "DEE WHY";
arrSuburbName[1] = "SYDNEY";
arrSuburbName[2] = "HURSTVILLE";
arrSuburbName[3] = "BALMAIN";
arrSuburbName[4] = "NORTH SYDNEY";
//POPULATE POSTCODE ID ARRAY
arrSuburbPC[0] = 2099;
arrSuburbPC[1] = 2000;
arrSuburbPC[2] = 2220;
arrSuburbPC[3] = 2041;
arrSuburbPC[4] = 2060;
//VARIABLES
string inputSuburb = "";
int inputPostCode = 0;
string msg = "";
//INPUT
inputSuburb = txtInputSuburb.Text.Trim();
inputPostCode = int.Parse(txtInputPostCode.Text);
//PROCESS
for (int i = 0; i < arrSuburbPC.Length; i++)
{
if (inputSuburb.ToUpper() == arrSuburbName[i])
{
msg = "Postcode for " + arrSuburbName[i] + " is: " + arrSuburbPC[i];
inputPostCode = 0;
break; //EXIT THE LOOP
}
else if (inputPostCode == arrSuburbPC[i])
{
msg = "Postcode for " + arrSuburbName[i] + " is: " + arrSuburbPC[i];
break; //EXIT THE LOOP
}
else
{
msg = "Postcode Not Found";
}
}
//OUTPUT
lblResult.Text = msg;
}
Why don't you use Int.TryParse(...) instead of Int.Parse(...)?
Parse v. TryParse
You have
inputSuburb = txtInputSuburb.Text.Trim();
inputPostCode = int.Parse(txtInputPostCode.Text);
but in the UI screen you attached you gave OR so it can happen that postcode will be empty.
You need to change you logic in code. Things to consider:
What to do if post code is empty? -> this is your situation right now
What if user enter non-number like 'abcd'
Your logic should have some validation. Use try catch construction for example.
Maybe you should also consider user NumericUpDown control?
I am trying to pass value from C# code to a CrystalReport report.
Edit
private void PrintOrder(List<OrderPrintBO> pListOrderBO)
{
DSOrderReport oDSOrderReport = new DSOrderReport();
DataTable oDataTable = oDSOrderReport.Tables[0];
String sOrderNo = "";
if (pListOrderBO.Count > 0)
{
for (int i = 0; i < pListOrderBO.Count; i++)
{
DataRow oRow = oDataTable.NewRow();
oRow["OrderID"] = pListOrderBO[i].OrderID;
oRow["OrderNumber"] = pListOrderBO[i].OrderNumber;
sOrderNo = pListOrderBO[i].OrderNumber;
oDataTable.Rows.Add(oRow);
}
}
oDSOrderReport.Merge(oDataTable);
oDSOrderReport.AcceptChanges();
if (oDSOrderReport.Tables[0].Rows.Count > 0)
{
// Main Copy
PrintDialog printDialog = new PrintDialog();
rptOrder oMainOrder = new rptOrder();
String sCompanyName = System.Configuration.ConfigurationManager.AppSettings["CompanyName"].ToString();
String sPhone1 = System.Configuration.ConfigurationManager.AppSettings["Phone1"].ToString();
String sPhone2 = System.Configuration.ConfigurationManager.AppSettings["Phone2"].ToString();
String sShowOrderNo = System.Configuration.ConfigurationManager.AppSettings["ShowOrderNo"].ToString();
((CrystalDecisions.CrystalReports.Engine.TextObject)oMainOrder.ReportDefinition.ReportObjects["txtCompanyName"]).Text = sCompanyName;
((CrystalDecisions.CrystalReports.Engine.TextObject)oMainOrder.ReportDefinition.ReportObjects["txtPhone1"]).Text = "Tel:" + sPhone1;
((CrystalDecisions.CrystalReports.Engine.TextObject)oMainOrder.ReportDefinition.ReportObjects["txtPhone2"]).Text = "Tel:" + sPhone2;
////This commented out section gives exception
//string sVarOrderNo = "";
//if (sShowOrderNo.ToLower() == "yes")
//{
// sVarOrderNo = sOrderNo;
//}
//((CrystalDecisions.CrystalReports.Engine.TextObject)oMainOrder.ReportDefinition.ReportObjects["txtOrderNo"]).Text = "O.N. : " + sVarOrderNo;
oMainOrder.SetDataSource(oDSOrderReport);
oMainOrder.PrintOptions.PrinterName = printDialog.PrinterSettings.PrinterName;
try
{
oMainOrder.PrintToPrinter(1, false, 0, 0);
MessageBox.Show("Order Printed Successfully", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
else
{
MessageBox.Show("Error in Printing Order", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
End Edit
For the first three text boxes (CompanyName, Phone1 & Phone2), every thing working just fine, but when I tried to pass the OrderNo to the report, Index was outside the bounds of the array. exception is occured, even though my report have a TextBox object named txtOrderNo
I am not sure why this is happening. Please help. Thanks.
Try to change your sOrderNo related code is as below.
string sVarOrderNo = "";
if (sShowOrderNo.ToLower() == "yes")
{
sVarOrderNo = sOrderNo;
}
((CrystalDecisions.CrystalReports.Engine.TextObject)oMainOrder.ReportDefinition.ReportObjects["txtOrderNo"]).Text = "O.N. : " + sVarOrderNo;
UPDATE
Your problem is below mentioned code snippet.Inside the for loop you try to assign a value to sOrderNo. Which is meaningless.B'cos it overrides every time when loop goes.So what is the purpose of this ? If you need this value then you have to bring this value through as your table's row or as a parameter to the report.
if (pListOrderBO.Count > 0)
{
for (int i = 0; i < pListOrderBO.Count; i++)
{
DataRow oRow = oDataTable.NewRow();
oRow["OrderID"] = pListOrderBO[i].OrderID;
oRow["OrderNumber"] = pListOrderBO[i].OrderNumber;
sOrderNo = pListOrderBO[i].OrderNumber;
oDataTable.Rows.Add(oRow);
}
}
I hope this will help to you.
I am currently using lucene.net to search the content of files for keyword search. I am able to get the results correctly but I have a scenario where I need to display the keywords found in a particular file.
There are two different files containing "karthik" and "steven", and if I search for "karthik and steven" I am able to get both the files displayed. If I search only for "karthik" and "steven" separately, only the respective files are getting displayed.
When I search for "karthik and steven" simultaneously I get both the files in the result as I am displaying the filename alone, and now I need to display the particular keyword found in that particular file as a record in the listview.
Public bool StartSearch()
{
bool bResult = false;
Searcher objSearcher = new IndexSearcher(mstrIndexLocation);
Analyzer objAnalyzer = new StandardAnalyzer();
try
{
//Perform Search
DateTime dteStart = DateTime.Now;
Query objQuery = QueryParser.Parse(mstrSearchFor, "contents", objAnalyzer);
Hits objHits = objSearcher.Search(objQuery, objFilter);
DateTime dteEnd = DateTime.Now;
mlngTotalTime = (Date.GetTime(dteEnd) - Date.GetTime(dteStart));
mlngNumHitsFound = objHits.Length();
//GeneratePreviewText(objQuery, mstrSearchFor,objHits);
//Generate results - convert to XML
mstrResultsXML = "";
if (mlngNumHitsFound > 0)
{
mstrResultsXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><Results>";
//Loop through results
for (int i = 0; i < objHits.Length(); i++)
{
try
{
//Get the next result
Document objDocument = objHits.Doc(i);
//Extract the data
string strPath = objDocument.Get("path");
string strFileName = objDocument.Get("name");
if (strPath == null) { strPath = ""; }
string strLastWrite = objDocument.Get("last_write_time");
if (strLastWrite == null)
strLastWrite = "unavailable";
else
{
strLastWrite = DateField.StringToDate(strLastWrite).ToShortDateString();
}
double dblScore = objHits.Score(i) * 100;
string strScore = String.Format("{0:00.00}", dblScore);
//Add results as an XML row
mstrResultsXML += "<Row>";
//mstrResultsXML += "<Sequence>" + (i + 1).ToString() + "</Sequence>";
mstrResultsXML += "<Path>" + strPath + "</Path>";
mstrResultsXML += "<FileName>" + strFileName + "</FileName>";
//mstrResultsXML += "<Score>" + strScore + "%" + "</Score>";
mstrResultsXML += "</Row>";
}
catch
{
break;
}
}
//Finish off XML
mstrResultsXML += "</Results>";
//Build Dataview (to bind to datagrid
DataSet objDS = new DataSet();
StringReader objSR = new StringReader(mstrResultsXML);
objDS.ReadXml(objSR);
objSR = null;
mobjResultsDataView = new DataView();
mobjResultsDataView = objDS.Tables[0].DefaultView;
}
//Finish up
objSearcher.Close();
bResult = true;
}
catch (Exception e)
{
mstrError = "Exception: " + e.Message;
}
finally
{
objSearcher = null;
objAnalyzer = null;
}
return bResult;
}
Above is the code i am using for search and the xml i am binding to the listview, now i need to tag the particular keywords found in the respective document and display it in the listview as recordsss,simlar to the below listview
No FileName KeyWord(s)Found
1 Test.Doc karthik
2 Test2.Doc steven
i hope u guys undesrtood the question,
This depends on how your documents were indexed. You'll need to extract the original content, pass it through the analyzer to get the indexed tokens, and check which matches the generated query.
Just go with the Highlighter.Net package, part of contrib, which does this and more.
When I simply execute the following line of code
wMessages.ScrollBarsEnabled = true;
I can see the System.UriFormatException in IntelliTrace data, saying "Invalid URI: The hostname could not be parsed.". I can't catch this exception, it's shown only in IntelliTrace. Removing the code makes my webbrowser work perfectly, but I need these scrollbars.
I can't understand what is the link between scrollbars and URI? Maybe it has something to do with the Document property of the browser? The URL of the document is "about:blank".
Any suggestions?
UPD:
Here is the full code:
string h = "";
if (currentpage != null)
h = template + "<body><div class=\"messages\">" + currentpage.Messages() + "</div><div></div></body></html>";
else
h = template + "<body><div class=\"messages\">" + "</div><div></div></body></html>";
wMessages.ScrollBarsEnabled = false;
Misc.OpenNew(wMessages, h);
try
{
if (wMessages == null) return;
if (wMessages.Document == null) return;
}
catch (System.Exception)
{
return;
}
HtmlElement body = wMessages.Document.Body;
wMessages.Dock = DockStyle.Top;
const double MaxHeightRatio = 0.4;
int availableHeight = pContainer.Height - wHeader.Height - pFooter.Height;
int BodyHeigth = (int)body.ScrollRectangle.Height;
if (BodyHeigth > (int)(availableHeight * MaxHeightRatio))
{
wMessages.Height = (int)(availableHeight * MaxHeightRatio);
wMessages.ScrollBarsEnabled = true; // here goes the exception
}
else
{
//wMessages.ScrollBarsEnabled = false;
wMessages.Height = BodyHeigth;
}
wMessages.Visible = true;