Converting "2.800000000000000e+001" to ""28" in ASP.NET - asp.net

Here is XML received by any web service,
<diy>
<tag1>14</tag1>
<tag2>2.000000000000000e+000</tag2>
<tag3>2.800000000000000e+001</tag3>
</diy>
This is code:
IEnumerable<XElement> xTag = from p in xmlDoc.Elements("document").Elements("xServ").Elements("b")
select p;
string tab = "<Table>";
foreach (var xTags in xTag)
{
tab += "<tr><td>" + Convert.ToString(xTags.Element("r").Element("Exp").Value) + "</td>";
tab += "<td>" + Convert.ToString(xTags.Element("r").Element("diy").Element("tag1").Value) + "</td>";
string s = Convert.ToString(xTags.Element("r").Element("diy").Element("tag2").Value);
string d = Math.Round(Convert.ToDouble(s)).ToString();
tab += "<td>" + d + "</td>";
tab += "<td>" + Convert.ToString(xTags.Element("r").Element("diy").Element("tag3").Value) + "</td>";
tab += "</tr>";
}
divTag.InnerHtml = tab + "</Table>";
When I used Math.Round(), it gives me "2,8E+16" !
how can I convert "2.000000000000000e+000" to "2" and "2.800000000000000e+001" to "28" in ASP.NET ?

Use Math library:
Math.Round(Convert.ToDouble("2.800000000000000e+001")).ToString();
that will return "28" .

How about this:
decimal.Parse("2.800000000000000e+001", System.Globalization.NumberStyles.Float).ToString("0.#");
Edit: added .NET format string to reduce to "28"

public static int function(float tag2)
{
do
{
if(tag2%10==0)
{
tag2=tag2/10.0;
}
else
{
int res = tag2;
return res;
}
}
while(true)
}

well I have to say that my solution is a bit funny! and beside that uses more memory than other ways.although other solutions use more cpu! life is trade off!
string MyNumber = "2.8000000e+1";
int DotIndex = MyNumber.IndexOf('.');
MyNumber = MyNumber.Remove(DotIndex, 1);
if(MyNumber[DotIndex] != '0')
DotIndex++;
MyNumber = MyNumber.Remove(DotIndex, MyNumber.Length - DotIndex);
DotIndex = Int32.Parse(MyNumber);
//MessageBox.Show(MyNumber); just to show the result!
It will return "2" for an input like "2.00000000e+1" AND "28" for "2.8000000e+1"!

Related

How to write script in BS in siebel to store multiple records in the output?

i have a scenario where there is an LOV with High Value as "Package" and TYPE="TO_NEW_PACKAGE" and i have to fetch the value of Low and there are 8 records in Low. I Have to display all the 8 records and their component cost for each record. All this should be gone as a display Message which will be output. Please let me know how to do this.
var sSearchExp = "[Type]= '" + "PACKAGE_PLAN" + "' AND [High] = '" + PACKAGEPLAN + "'"; SetSearchExpr(sSearchExp); ExecuteQuery(); var isRecord = FirstRecord(); while(isRecord) { Slow = GetFieldValue("Low"); Outputs.SetProperty ("NEW_PACKAGE_PLAN",Slow); Outputs.SetProperty("ErrorCode", "00"); Outputs.SetProperty("ErrorDesc", "Success"); i = i+1; isRecord = NextRecord(); }
this is storing only 1 record... i want all the eight records to be displayed!
This should get you started
var sSearchExp = "[Type]= '" + "PACKAGE_PLAN" + "' AND [High] = '" + PACKAGEPLAN + "'";
var Slow = "";
SetSearchExpr(sSearchExp);
ExecuteQuery();
var isRecord = FirstRecord();
while (isRecord) {
Slow += GetFieldValue("Low");
Slow += " ";
i = i + 1;
isRecord = NextRecord();
}
Outputs.SetProperty("NEW_PACKAGE_PLAN", Slow);
Outputs.SetProperty("ErrorCode", "00");
Outputs.SetProperty("ErrorDesc", "Success");
This sample code will print the values downwards:
var boAsset = TheApplication().GetBusObject("List Of Values");
var bcAsset = boAsset.GetBusComp("List Of Values");
with (bcAsset)
{
ActivateField("Value");
var sSearchExp = "[Type]= 'AAG_TABLE_TYPE'";
var Slow = "";
SetSearchExpr(sSearchExp);
ExecuteQuery();
var isRecord = FirstRecord();
while (isRecord)
{
Slow += GetFieldValue("Value");
Slow += "\n";
isRecord = NextRecord();
}
TheApplication().RaiseErrorText(Slow);
}
Output:
AAG Account
AAG Holdg
AAG Portf
AAG Txn
Changing Slow += "\n"; to Slow += " "; will print the values sideways.
Hope you get the trick here.

Log Parser c# error using STRCAT with CASE

I'm having trouble with the log parser, punctually on the use of the function STRCAT parameter with CASE, using log parser the query works perfectly and using a simple STRCAT without CASE the query works even using c#, the problem starts when i use CASE. Am I missing something?
Here's the error:
CLogQueryClass: Error 8007064f: Execute: error parsing query: Syntax Error: : cannot find closing parenthesys for function STRCAT [ SQL query syntax invalid or unsupported. ]
string query = "SELECT " + " STRCAT('" + entry.Name +"'";
query += #", CASE INDEX_OF(SUBSTR(cs-uri-stem,1), '/')
WHEN 'NULL' THEN 'DEFAULTAPPPOOL'
ELSE EXTRACT_TOKEN(cs-uri-stem,1,'/')
END";
query += ") AS APPPOOL";
query += ", '" + Environment.MachineName + "' as server";
query += ", '" + entry.Name + "' as site";
query += ", cs-uri-stem as csUriStem";
query += ", c-ip as cIp, sc-status as scStatus";
query += ", sc-bytes as scBytes";
query += ", cs-bytes as csBytes";
query += ", time-taken as timeTaken";
query += " FROM " + logAddress + "\\" + yesterdayLogName;
// Initialize a LogQuery object
logQuery = new LogQueryClass();
logRecordSet = logQuery.Execute(query,new COMIISW3CInputContextClass());
//SHOWS RESULT
for (; !logRecordSet.atEnd(); logRecordSet.moveNext())
{
logrecord = logRecordSet.getRecord();
int i = 0;
while (i < 9)
{
Console.WriteLine(logrecord.getValue(i));
i++;
}
Thanks
First, it looks like you are mixing types. The CASE INDEX_OF(SUBSTR(cs-uri-stem,1), '/') WHEN 'NULL' compares an integer to string. This should be:
CASE INDEX_OF(SUBSTR(cs-uri-stem,1), '/')
WHEN NULL THEN 'DEFAULTAPPPOOL'
ELSE EXTRACT_TOKEN(cs-uri-stem,1,'/')
END
The error complains about finding the close parenthesis, but I've found that parsing errors can result in misleading error messages with LogParser.
Second, I've tested the following in C# targeted at .NET 3.5 (4.0 had an issue with embedded type. Similar to this...):
string logAddress = "C:\\Path\\to\\consolidatedFile";
string entryName = "blah";
string yesterdayLogName = "fileName.log";
string query = "SELECT " + " STRCAT('" + entryName + "'"
+ ", CASE INDEX_OF(SUBSTR(cs-uri-stem,1), '/') "
+ "WHEN NULL THEN 'DEFAULTAPPPOOL' "
+ "ELSE EXTRACT_TOKEN(cs-uri-stem,1,'/') "
+ "END"
+ ") AS APPPOOL"
+ ", '" + Environment.MachineName + "' as server"
+ ", '" + entryName + "' as site"
+ ", cs-uri-stem as csUriStem"
+ ", c-ip as cIp, sc-status as scStatus"
+ ", sc-bytes as scBytes"
+ ", cs-bytes as csBytes"
+ ", time-taken as timeTaken"
+ " FROM " + logAddress + "\\" + yesterdayLogName;
// Initialize a LogQuery object
COMW3CInputContextClassClass ctx = new COMW3CInputContextClassClass();
//LogQueryClass logQuery = new LogQueryClass();
LogQueryClass logQuery = new LogQueryClassClass();
//ILogRecordset logRecordSet = logQuery.Execute(query, new COMIISW3CInputContextClass());
ILogRecordset logRecordSet = logQuery.Execute(query, ctx);
//SHOWS RESULT
for (; !logRecordSet.atEnd(); logRecordSet.moveNext())
{
ILogRecord logrecord = logRecordSet.getRecord();
int i = 0;
while (i < 9)
{
Console.WriteLine(logrecord.getValue(i));
i++;
}
}
This ran successfully and return results. I commented out the lines initially presented since when I used them nothing returned on the console. That might be a difference of the code not presented. Finally, I substituted a string entryName for the entry.Name object assuming that it returns a string.
I hope this helps.

Create html table as string based on textbox value

I have textbox and a button on my aspx page.
Now I want to create a html table as string on button click event. I have done this task. Please look at my below code:
string stsrtest = "test";
string nWidth="150px";
string strHtml = "<table><tr><td width= '" + nWidth + "'> Authorized By</td><td>Employee </td><td>Status</td><td>Date </td><td>Note</td><td>Signutare</td></tr>";
strHtml += "<tr><td> " + stsrtest + "</td><td> " + stsrtest + "</td><td> " + stsrtest + "</td><td> " + stsrtest + "</td><td> " + stsrtest + "</td><td>test</td></tr>";
strHtml += "</table>";
Now I want to create row and column dyanically based on textbox value.
For Example if textbox value is 15 then I want create a table with 3 column and 5 Rows.
and if textbox value is 6 then I want create a table with 3 column and 2 Rows.
I have use above code to create a simple 2 rows and 5 column.
I have solved this issue using below code:
int nTotal = Convert.ToInt32(txtCell.Text);
int nRows = 0;
int nLast = nTotal % 3;
nRows = nTotal / 3;
string strHmtl = "<table border='1px' cellspacing='0' cellpadding='0' style='height: 28px; width: 647px;' >";
for (int i = 0; i < nTotal - nTotal % 3; i++)
{
if (i == 0 || i % 3 == 0)
strHmtl += "<tr>";
strHmtl += "<td></td>";
if (i % 3 == 2)
strHmtl += "</tr>";
}
if (nTotal % 3 != 0)
{
strHmtl += "<tr>";
if (nLast == 1)
strHmtl += "<td> </td>";
else
{
strHmtl += "<td> </td>";
strHmtl += "<td> </td>";
}
strHmtl += "</tr>";
}
strHmtl += "</table>";
Thanks.
You can just build your table dynamically by setting the number of your columns and looping for each row to build it as string. Take a look at this example:
StringBuilder l_strBuilder= new StringBuilder();
l_strBuilder.AppendLine("<table">");
l_strBuilder.AppendLine("<tr>");
l_strBuilder.AppendLine("<th>Authorized By</th>");
l_strBuilder.AppendLine("<th>Employee</th>");
l_strBuilder.AppendLine("<th>Status</th>");
l_strBuilder.AppendLine("<th>Date</th>");
l_strBuilder.AppendLine("<th>Note</th>");
l_strBuilder.AppendLine("<th>Signutare</th>");
l_strBuilder.AppendLine("</tr>");
for (int i = 0; i < ROWSNUMBER; i++)
{
l_strBuilder.AppendLine("<tr>");
l_strBuilder.AppendLine("<td>column 1 data</td>");
l_strBuilder.AppendLine("<td>column 2 data</td>");
l_strBuilder.AppendLine("<td>column 3 data</td>");
l_strBuilder.AppendLine("<td>column 4 data</td>");
l_strBuilder.AppendLine("<td>column 5 data</td>");
l_strBuilder.AppendLine("<td>column 6 data</td>");
l_strBuilder.AppendLine("</tr>");
}
l_strBuilder.AppendLine("</table>");
After the building the table you can use the asp literal obj to put your table in your page.
<asp:Literal ID="ltrDynTable" runat="server" />
And fill it with your string this way:
ltrDynTable.Text = l_strBuilder.ToString();
Hope it will help.

Flex's AreaChart bug

What's up with Flex's AreaChart bug, does anybody know how to fix it? It causes ones tooltips to display the wrong value for minFields.
I.e. for:
<mx:AreaSeries yField="TotalVariableCost" minField="TotalFixedCost" displayName="Total Cost">
It will show:
Total Cost
high: TotalVariableCost
low: TotalVariableCost
As opposed to:
Total Cost
high: TotalVariableCost
low: TotalFixedCost
This bug is suppose to be in lines 2058 to 2083 of AreaSeries.as - but that stuff is way beyond my comprehension.
--Stephen
Yep, it's a bug in AreaSeries. Due to the stupid way that flex charts are designed, the only real way to fix it is to set a custom dataTipFunction on the AreaChart.
Here's a copy of the relevant code with the bug fixed:
/**
* Create a data tip function for the given AreaSeries. Uses a copy of
* the formatDataTip code from AreaSeries with the minValue bug fixed.
*
* #param series
* #return a data tip function
*
*/
private function createAreaSeriesTipFunc(series:AreaSeries):Function {
var displayName:String = series.displayName;
var dataTransform:DataTransform = series.dataTransform;
var xField:String = series.xField;
var minField:String = series.minField;
// formatDataTip relies on AreaSeries member data so simulate that
// with a closure to minimize code modifications
return function(hd:HitData):String {
var dt:String = "";
var n:String = displayName;
if (n && n != "")
dt += "<b>"+ n + "</b><BR/>";
var xName:String = dataTransform.getAxis(CartesianTransform.HORIZONTAL_AXIS).displayName;
if (xName == "")
xName = xField;
if (xName != "")
dt += "<i>" + xName + ": </i>";
var item:AreaSeriesItem = AreaSeriesItem(hd.chartItem);
var lowItem:AreaSeriesItem = (minField != "") ?
item :
null;
dt += dataTransform.getAxis(CartesianTransform.HORIZONTAL_AXIS).formatForScreen(item.xValue) + "\n";
var yName:String = dataTransform.getAxis(CartesianTransform.VERTICAL_AXIS).displayName;
if (!lowItem)
{
if (yName != "")
dt += "<i>" + yName + ":</i> ";
dt += dataTransform.getAxis(CartesianTransform.VERTICAL_AXIS).formatForScreen(item.yValue) + "\n";
}
else
{
if (yName != "")
dt += "<i>" + yName + " (high):</i> ";
else
dt += "<i>high: </i>";
dt += dataTransform.getAxis(CartesianTransform.VERTICAL_AXIS).formatForScreen(item.yValue) + "\n";
if (yName != "")
dt += "<i>" + yName + " (low):</i> ";
else
dt += "<i>low:</i> ";
dt += dataTransform.getAxis(CartesianTransform.VERTICAL_AXIS).formatForScreen(lowItem.minValue) + "\n";
}
return dt;
};
}
I just changed formatForScreen(lowItem.yValue) to formatForScreen(lowItem.minValue) in one place. You can use it like this:
<mx:AreaChart dataProvider="{chartData}" showDataTips="true" dataTipFunction="{createAreaSeriesTipFunc(areaSeries)}">
<mx:series>
<mx:AreaSeries id="areaSeries" yField="TotalVariableCost" minField="TotalFixedCost" displayName="Total Cost" />
</mx:series>
</mx:AreaChart>

how to use combination of different fields in query when no of fields are uncertain?

I'm using advance search option in library project
Here is idea :
i have 6 different fields to allow search if i give the option for user to enter value in any of 6 option or enter combined fields how to use sql query to retrieve the value.
For example the fields are author, publication, price, subject, edition, bookid
and if user enter only one value i could search but if user enter more than one if i try combinations then there are many combination.
Please suggest me how to define the query?
you can do something like..
string strFilters = string.Empty;
if (author != "" )
{
strFilters += " Author = " + yourAuthorString + " and ";
}
if (publication != "")
{
strFilters += " publication = " + yourpublicationString + " and ";
}
if (price != "")
{
strFilters += " price = " + priceValue + " and ";
}
if (subject != "")
{
strFilters += " subject = " + yoursubjectString + " and ";
}
if (edition != "")
{
strFilters += " edition = " + youreditionString + " and ";
}
if (strFilters.Length > 3)
{
strFilters = strFilters.Remove(strFilters.Length - 5, 5);
}

Resources