Can you ignore a value in a DLL? - asp.net

In Grrr.Premium.Google.GoogleGeoCode, the baseUrl is set to http://maps.googleapis.com/maps/api/geocode/, which is failing because it needs to be https.
Is it possible to modify the code below to ignore the value in the DLL and define it here?
Grrr.Premium.Google.GoogleGeoCode encode = new Grrr.Premium.Google.GoogleGeoCode();
encode.Query = "json?key=#######&address=" + Server.UrlEncode(txtAddress.Text.Trim() + " " + txtCity.Text.Trim() + " " + drpState.SelectedValue + " " + txtZip.Text);
encode.GeoCode();
I feel like this must be possible, and easy, but I can't figure it out. :(
Thanks in advance for any help.

Related

Dynamic Query with MATCHES in Progress 4GL

I have to create a query in which people can input some values or not. If they don't input them, the program will search for everything. And people can put just a part of the data of the code. My code became something like this.
cQuery = "" +
" FOR EACH table1 " +
" WHERE table1.status_ = 1 " +
" AND table1.section MATCHES " + QUOTER("*"+ pc-section + "*").
So my question.
1 - I read a lot that MATCHES uses a table scan and we should avoid it so I thought about putting MATCHES in an if variable. Is it really necessary?
2 - is the QUOTER(""+ pc-section + "") the correct way of using MATCHES in a dynamic query? My results seem wrong and I don't know if it was because of the MATCHES or if there is another problem in my code.
Sorry for any wrong ideas and thanks for your time.
EDIT:
My IF statement is like this:
DEF VAR ifSection AS CHAR.
IF pc-section <> "" THEN ifSection = " AND table1.section MATCHES " + QUOTER("*"+ pc-section + "*").
And in my code i use:
" FOR EACH table1 " +
" WHERE table1.status_ = 1 " + ifSection.
I managed to make it work now. The problem in my results was because I forgot to add 'ifSection' after THEN. But I still am not sure if this is the best way to do it. Is there another better way to use MATCHES in a dynamic query? Thanks for the help
Don't use IF statements in a WHERE clause - you will never, ever use an index that way.
You can put the IF around the outside:
cQuery = " FOR EACH table1 WHERE table1.status_ = 1 ".
IF <something> THEN
// no index
cQuery = cQuery + " AND field-name MATCHES " + QUOTER("*"+ pc-section + "*").
ELSE
IF <something-else> THEN
// may be indexed
cQuery = cQuery + " AND field-name BEGINS " + QUOTER(pc-section).
ELSE
IF <something-else> THEN
// may be indexed
cQuery = cQuery + " AND field-name = " + input-value.
etc, which will help you at least try to use indexes where possible.
Replacing MATCHES with indexed searching is more complex. You could look at word indexes and the CONTAINS keyword as a start.

Page Header overlaping content when using Rotativa to generate PDF from HTML

I am try to convert an HTML file to PDF using "Rotativa" lib, but i am facing some problems when using custom headers, here is my code:
string customSwitches = string.Format("--header-html \"{0}\" " +
"--header-spacing \"0\" " +
"--footer-html \"{1}\" " +
"--footer-spacing \"10\" " +
"--footer-font-size \"10\" " +
"--header-font-size \"10\" ", header, footer);
var invoice = new ViewAsPdf("Index", _invoiceRepository.GetInvoice(1))
{
FileName = "MyPDF.pdf",
CustomSwitches = customSwitches,
PageMargins = margin,
PageSize = size,
PageOrientation = orientation
};
return invoice;
The headers and Footers are being successfully injected on the top and bottom of each page like expected but the problem is that the header is overlapping that rest of the content.
how can i reserve space for the header?
I faced similar trouble when setting --header-spacing \"0\" once. So the solution that worked for me was to set higher spacing between header and content.
Please try setting, for example, spacing to 7 (measure is given in mm, as you can review in WkHtmlToPdf documentation). This way, you can check current PDF with one you have generated before, and verify if change solves the problem. Once there, you should be ablo to adjust the measure to the value that is suitable for you.
So, your code should look like:
string customSwitches = string.Format("--header-html \"{0}\" " +
"--header-spacing \"7\" " +
"--footer-html \"{1}\" " +
"--footer-spacing \"10\" " +
"--footer-font-size \"10\" " +
"--header-font-size \"10\" ", header, footer);
I tried your code in one of my projects and seems to work fine.
Hope it would be of help. If trouble continues, it should be useful to inlcude some samples os your HTML header and PDF body content, to chek the specific case.

Beginner question on why my dictionary isn't working

So I'm crash coursing myself though Python and I dont understand why this isn't going through the right way:
>favorite_numbers = {
'mike': 15,
'john': 97
}
print("Mike's favorite number is " + favorite_numbers['mike'].title() + ".")
print("John's favorite number is " + favorite_numbers['john'].title() + ".")
It comes up as:
'int' object has no attribute 'title'
Is there some syntax I'm missing? I'm doing it exactly as the book says. I'm sorry this is so beginner but I want to be really thorough in my understanding.
Try this. It's not clear what you're trying to do with ".title()" on the two references to favorite_numbers. Not only is it not needed, it's incorrect.
>favorite_numbers = {
'mike': 15,
'john': 97
}
print("Mike's favorite number is " + favorite_numbers['mike'] + ".")
print("John's favorite number is " + favorite_numbers['john'] + ".")

PadLeft with spaces

Have a relatively simple request.
I wish to pad left a string with spaces in an HTML page using VB on asp.net
For me the most obvious way to do it is
Response.Write(qty.PadLeft(5, " ") + " x " + part_number)
but as HTML does not render multiple spaces, this does not work
my workaround is
Response.Write(qty.PadLeft(5, "0") + " x " + part_number)
which pads the number with zero's but looks fairly unappealing on the website.
Any suggestions?
Thanks
Update:
Based on replies so far I have tried
"100".PadLeft(5, " ")
but this outputs &&100
OK, I solved it by doing this
rep = string.concat(Enumerable.Repeat(" ", 5-qty.Length))
Response.Write(rep + qty+ " x " + part_number)
Not the best but works.
There's & nbsp; or setting or the css (with white-space) to see spaces. If you want to align information, you might want to also look at having a fixed font.

Replacing a new line character with streamwriter remove everything after it. (ASP.NET, Json, C#)

I'm having an unexpected problem which I'm hoping one of you can help me with.
I have an ASP.NET Web API with a number of end points, one of which takes user input, received as JSON, and converts it into an order object which is written to a file in .CSV format. The following is a small snippet of the full code as an example.
using (StreamWriter writer = new StreamWriter(file))
{
writer.Write(escape + order.Notes + escape + delim);
writer.Write(escape + order.Reference1 + escape + delim);
writer.Write(escape + order.Reference2 + escape + delim);
writer.WriteLine();
writer.Flush();
}
The problem I am having is that some users are inclined to add line breaks in
certain fields, and this is causing havoc with my order file. In order to remove
these new line characters, I have tried both of the following methods.
writer.Write(escape + product.Notes.Replace("\n", " ") + escape + delim);
writer.Write(escape + product.Notes.Replace(System.Environment.NewLine, " ") + escape + delim);
However, it seems that, rather than just remove the new line character and carry on writing the rest of the fields, when a new line is encountered, nothing else gets written.
Either everything else gets replace with the " " or nothing else is being written at all, but I'm not sure which.
If I remove the .Replace() the whole file is written again but with extra line breaks.
I hope somebody has experienced this one and knows the answer!

Resources