sqlite SUM result decimal gone - sqlite

Test Code :
> String x = "30000000000.222";
> String y = "20000000000.444";
> double x1 = Double.parseDouble(x);
> double y1 = Double.parseDouble(y);
>
> ContentValues vValue51 = new ContentValues();
> vValue51.put(DatabaseStructure.fTmpAttr_X3 , x1 );
> vDatabase.insertData(DatabaseStructure.cTblTemporary3, vValue51);
> ContentValues vValue61 = new ContentValues();
> vValue61.put(DatabaseStructure.fTmpAttr_X3 , y1 );
> vDatabase.insertData(DatabaseStructure.cTblTemporary3, vValue61);
> vDatabase.closeDatabase();
>
>
>
> List<Map<String, String>> vListData2 = new
> ArrayList<Map<String,String>>(); String vQuerY32;
>
>
> vQuerY32 = "Select SUM(" + DatabaseStructure.fTmpAttr_X3 + " ) 'jik' " +
> "From " + DatabaseStructure.cTblTemporary3;
>
> vDatabase = new DatabaseHandler(getApplicationContext());
> vListData2 = vDatabase.getListData(vQuerY32);
> vDatabase.closeDatabase();
I tried many data type for column
> vQuery = "create table " + cTblTemporary3 +
> "("+
> fTmpAttr_ID3 + " integer primary key, " +
> fTmpAttr_V3 + " DECIMAL(10,5), " +
> fTmpAttr_W3 + " FLOAT , " +
> fTmpAttr_X3 + " REAL, " +
> fTmpAttr_Y3 + " DOUBLE PRECISION, " +
> fTmpAttr_Z3 + " double " +
> ")"; vSQL.execSQL(vQuery);
======================getListDataFunction===========================================
public List<Map<String, String>> getListData(String vQuery)
{
List<Map<String, String>> vListData = new ArrayList<Map<String,String>>();
Cursor vCursor = getCursorData(vQuery);
int vLength = vCursor.getColumnCount();
String[] vFields = new String[vLength];
if (vCursor.getCount() > 0){
for (int i = 0; i < vLength; i++)
vFields[i] = vCursor.getColumnName(i);
vCursor.moveToFirst();
while (!vCursor.isAfterLast()) {
Map<String, String> vMapData = new HashMap<String, String>();
for (int i = 0; i < vLength; i++)
vMapData.put(vFields[i], vCursor.getString(i));
vListData.add(vMapData);
vCursor.moveToNext();
}
}
vCursor.close();
return vListData;
}
i Log the result
Log.d("TEST", vListData2.get(0).get("jik"));
, the result is not 50000000000.666 but 5e+10, How i can get 50000000000.666 for the result? Please help this newbie :(

Related

Unable to convert string to date (dd/MMM,YYYY) format ASP.NET

var LR_No_Of_Days = "";
$("#DateRange").jqxDateTimeInput({ width: 250, height: 25, selectionMode: 'range' }); $("#DateRange").on('change', function (event) {
var selection = $("#DateRange").jqxDateTimeInput('getRange');
if (selection.from != null) {
$("#selection").html("<div>From: " + selection.from.toLocaleDateString() + " <br/>To: " + selection.to.toLocaleDateString() + "</div>");
}
var LR_Request_Date_From = selection.from.toLocaleDateString();
var LR_Request_Date_To = selection.to.toLocaleDateString();
$('#LR_Request_Date_From').val(LR_Request_Date_From);
$('#LR_Request_Date_To').val(LR_Request_Date_To);
NoOfdays();
function NoOfdays() {
var LR_No_Of_Days = Math.floor((Date.parse(LR_Request_Date_To) - Date.parse(LR_Request_Date_From)) / 86400000); if (LR_No_Of_Days == '0') {LR_No_Of_Days = 1;} else { LR_No_Of_Days-1; }; alert(LR_Request_Date_From + " &&& " + LR_Request_Date_To + " No of days:" + LR_No_Of_Days);
$("#LR_No_Of_Days").val(LR_No_Of_Days);}});
I'm unable to convert the string variable(LR_Request_Date_From and LR_Request_Date_To) to date format. I receive error converting string to date.
You have to use MM instead of mm and CultureInfo.InvariantCulture as second parameter
string dt = DateTime.Parse(txtVADate.Text.Trim()).ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);

Want to get data from other website in asp.net

I am trying to get data from other website using NuGet but its not get anything.
var aTags showing null value.
var getHtmlWeb = new HtmlWeb();
var document = getHtmlWeb.Load("https://www.google.com");
var aTags = document.DocumentNode.SelectNodes("//a");
int counter = 1;
if (aTags != null)
{
foreach (var aTag in aTags)
{
Label1.Text += counter + ". " + aTag.InnerHtml + " - " + aTag.Attributes["href"].Value + "\t" + "<br />";
counter++;
}
}

Creating a Dynamic Menu

I want to created a vertical dynamic menu with menu items that pop when needed. For example, menu has all country names and when you roll over a country, sub menu city names becomes visible. I chose the UL method to do this. So far I can make the menu list etc, but I have no idea how to make the sub menus visible and hide on roll over of country. Here is the code I got.
qString = "SELECT t.cID, t.cCountry, t.cPlace, t.cRating FROM tplaces AS t ORDER BY t.cCountry ASC, t.cPlace";
dtMenuPlaces = GetTable(qString);
int placeMenuWidth = 130;
int placeMenuHeight = 40;
if (dtMenuPlaces != null)
{
int menuY = 0;
string previousCountry = "";
int previousBGColor = 0;
Random rand = new Random();
string fnMenuBG = "blankblockBlue";
HtmlGenericControl mainLI = new HtmlGenericControl("li");
HtmlGenericControl subUL = new HtmlGenericControl("ul");
for (int x = 0; x < dtMenuPlaces.Rows.Count; x++)
{
int rnMenuBG = rand.Next(1, arrayMenuButtonNames.Length) - 1;
int cPlaceID = Convert.ToInt32(dtMenuPlaces.Rows[x][0]);
string cCountry = dtMenuPlaces.Rows[x][1].ToString();
string cPlace = dtMenuPlaces.Rows[x][2].ToString();
int cRating = Convert.ToInt32(dtMenuPlaces.Rows[x][3]);
string tempUrl = cCountry + cPlace + ".aspx";
tempUrl = tempUrl.Replace(" ", "");
tempUrl += "?fVar1=place&" + "fVar2=" + cPlace + "&fVar3=" + cCountry;
System.Text.StringBuilder tString = new System.Text.StringBuilder();
// used to make multiline buttons.
if (cPlace != "")
{
// tString.Append(Environment.NewLine);
tString.AppendLine(cPlace);
}
else
{
tString.AppendLine(cCountry);
}
if (previousCountry != cCountry)
{
rnMenuBG = rand.Next(1, arrayMenuButtonNames.Length) - 1;
while (rnMenuBG == previousBGColor)
{
System.Diagnostics.Debug.WriteLine("Random - #" + rnMenuBG + " P " + previousBGColor);
rnMenuBG = rand.Next(1, arrayMenuButtonNames.Length) - 1;
}
fnMenuBG = "blankblock" + arrayMenuButtonNames[rnMenuBG];
mainLI = new HtmlGenericControl("li");
menuPlaces.Controls.Add(mainLI);
HtmlGenericControl mainA = new HtmlGenericControl("a");
mainA.Attributes.Add("href", tempUrl);
mainA.InnerText = tString.ToString();
// mainA.Attributes.Add("onmouseover", "mainLI.style.display='none'");
// mainA.Attributes.Add("onmouseout", "mainLI.style.display='block'");
mainA.Attributes.Add("style", "text-decoration: none;width:" + placeMenuWidth + "px;height:" + placeMenuHeight + "px;line-height:" + placeMenuHeight + "px;");
mainLI.Controls.Add(mainA);
subUL = new HtmlGenericControl("ul");
mainLI.Controls.Add(subUL);
mainLI.ID = "mainList";
previousCountry = cCountry;
previousBGColor = rnMenuBG;
// mainLI.Style["Background-image"] = "url:('images/gfx/" + fnMenuBG + ".gif'); no-repeat;";
mainLI.Attributes.Add("style", "display:block;position:absolute;top:" + menuY + "px;font-size:14px;font-family:century gothic;text-align: center;font-weight:bold;background:url('images/gfx/" + fnMenuBG + ".gif'); background-repeat:no-repeat;");
// mainLI.Attributes.Add("style", "background:url('images/gfx/" + fnMenuBG + ".gif'); background-repeat:no-repeat;");
menuY += placeMenuHeight + 5;
}
else
{
rnMenuBG = previousBGColor;
fnMenuBG = "blankblock" + arrayMenuButtonNames[rnMenuBG];
/// add SUB place if not main country.
HtmlGenericControl subLI = new HtmlGenericControl("li");
subUL.Controls.Add(subLI);
subUL.Attributes.Add("style", "display:block;position:relative;top:-" + placeMenuHeight + "px;left:" + placeMenuWidth + "px;margin: 0px; padding:0px;width:" + placeMenuWidth + "px;list-style-type:none;");
HtmlGenericControl subA = new HtmlGenericControl("a");
subA.Attributes.Add("href", tempUrl);
// subA.Attributes.Add("onmouseover", "this.style.color=\"red\"");
// subA.Attributes.Add("onmouseout", "this.style.color=\"black\"");
// subA.Attributes.Add("onclick", "this.style.color=\"yellow\"");
subA.Attributes.Add("style", "text-decoration: none;display:block;width:" + placeMenuWidth + "px;height:" + placeMenuHeight + "px;line-height:" + placeMenuHeight + "px;");
subA.InnerText = tString.ToString();
subLI.Controls.Add(subA);
// subLI.Style["Background-image"] = "url:('images/gfx/" + fnMenuBG + ".gif'); no-repeat;";
subLI.Attributes.Add("style", "width:" + placeMenuWidth + "px;height:" + placeMenuHeight + "px;margin:0px;margin-bottom:5px;;padding:0px;font-size:14px;font-family:century gothic;text-align: center;font-weight:bold;background:url('images/gfx/" + fnMenuBG + ".gif'); background-repeat:no-repeat;");
// subLI.Attributes.Add("style", "font-size:14px;font-family:century gothic;text-align: center;font-weight:bold");
// subLI.Attributes.Add("style", "background:url('images/gfx/" + fnMenuBG + ".gif'); background-repeat:no-repeat;");
}
}
}
Also is it better to create HTMLGENERICCONTROLS or adding literal controls to a string builder?
heres a snippet of Jquery that might help you for the mouseover and mouseout, i picked it from a Jquery plugin :
$(document).ready(function(){
var el = $('li');
var hidden_ul = $('.hidden')
el.on('mouseover mouseout', function(e) {
$(this).find('.hidden').css({'display' : 'block'});
e.type == 'mouseout' && $(this).find('.hidden').css({'display' : 'none'});
}); //---------------------------- End on function.
});
I have constructed a simple responsive menu , which might help you understand , what i mean as a whole check out the fiddle below :
fiddle
incase you are not comfortable with Jquery , just remove the Jquery code and add the following peice of CSS in the stylesheet :
ul li a:hover + ul ,.hidden:hover{
display: block;
}
The original menu i build was intended to be CSS only , but i am giving you both a CSS as well as a Jquery solution , you can pick whichever one is more suited to you. :)
Cheers.
I was close to getting to work with HTMLGENERIC method, but I decided to rewrite the whole thing using stringbuilder and it worked. adding like u said to main.css plus in C#.
System.Text.StringBuilder sbMenu = new System.Text.StringBuilder();
qString = "SELECT t.cID, t.cCountry, t.cPlace, t.cRating FROM tplaces AS t ORDER BY t.cCountry ASC, t.cPlace";
dtMenuPlaces = GetTable(qString);
if (dtMenuPlaces != null)
{
string previousCountry = "";
int previousBGColor = 0;
Random rand = new Random();
string fnMenuBG = "blankblockBlue";
// HtmlGenericControl mainLI = new HtmlGenericControl("li");
// HtmlGenericControl subUL = new HtmlGenericControl("ul");
for (int x = 0; x < dtMenuPlaces.Rows.Count; x++)
{
int rnMenuBG = rand.Next(1, arrayMenuButtonNames.Length) - 1;
int cPlaceID = Convert.ToInt32(dtMenuPlaces.Rows[x][0]);
string cCountry = dtMenuPlaces.Rows[x][1].ToString();
string cPlace = dtMenuPlaces.Rows[x][2].ToString();
int cRating = Convert.ToInt32(dtMenuPlaces.Rows[x][3]);
string tempUrl = cCountry + cPlace + ".aspx";
tempUrl = tempUrl.Replace(" ", "");
tempUrl += "?fVar1=place&" + "fVar2=" + cPlace + "&fVar3=" + cCountry;
System.Text.StringBuilder tString = new System.Text.StringBuilder();
// used to make multiline buttons.
if (cPlace != "")
{
// tString.Append(Environment.NewLine);
tString.AppendLine(cPlace);
}
else
{
tString.AppendLine(cCountry);
if (x != 0)
{
sbMenu.Append("</ul>");
}
}
if (previousCountry != cCountry)
{
rnMenuBG = rand.Next(1, arrayMenuButtonNames.Length) - 1;
while (rnMenuBG == previousBGColor)
{
System.Diagnostics.Debug.WriteLine("Random - #" + rnMenuBG + " P " + previousBGColor);
rnMenuBG = rand.Next(1, arrayMenuButtonNames.Length) - 1;
}
fnMenuBG = "blankblock" + arrayMenuButtonNames[rnMenuBG];
sbMenu.Append("<li class='subMenuPlaces' style = background:url('images/gfx/" + fnMenuBG + ".gif');background-repeat:no-repeat;><a href='" + tempUrl + "'>" + tString.ToString() + "</a><ul class='subList'>");
previousCountry = cCountry;
previousBGColor = rnMenuBG;
}
else
{
rnMenuBG = previousBGColor;
fnMenuBG = "blankblock" + arrayMenuButtonNames[rnMenuBG];
sbMenu.Append("<li class='subMenuPlaces' style = background:url('images/gfx/" + fnMenuBG + ".gif');background-repeat:no-repeat;><a href='" + tempUrl + "'>" + tString.ToString() + "</a></li>");
}
}
menuPlaces.InnerHtml = sbMenu.ToString();
}

how we get Uncheckitems CheckBoxList control in asp.net 3.5?

when user uncheckitems items.how we get that uncheckitems
for (int i = 0; i < ChkLstUserRoles.Items.Count; i++)
{
if (ChkLstUserRoles.Items[i].Selected == true)
{
URoles = URoles + "|" + ChkLstUserRoles.Items[i].Value;
ActivityLog = ActivityLog + "Grant the " + ChkLstUserRoles.Items[i].Text + " to user [" + CboUserName.Text + "]çGrantRole|";
}
}
Use this condition,
ChkLstUserRoles.Items[i].Selected == false

emptydatatext is not displaying when binding datatable to gridview

I am creating a datatable and adding rows dynamically and am binding datatable to gridview when there are no records am displaying as no records found using emptydatatext but this is not working.Here is my code
protected void show_fence_report(object sender, EventArgs e)
{
int drp_fence_id = common.make_int(common.get_request("drp_fence"));
string fence_start_date_time1 = common.get_request("fence_start_date_time");
string fence_end_date_time1 = common.get_request("fence_end_date_time");
//Delete data from datatable and gridview
dt_fence.Clear();
if (gridview_fence.DataSource != null)
{
((DataView)gridview_fence.DataSource).Table.Clear();
}
gridview_fence.DataBind();
gridview_fence.EmptyDataText = "Records Not Found";
hid_fence_id.Value = drp_fence_id.ToString();
hid_fence_start_datetime.Value = fence_start_date_time1;
hid_fence_end_datetime.Value = fence_end_date_time1;
display_fence_report();
gridview_fence.EmptyDataText = "Records Not Found";
}
public void display_fence_report()
{
string fence_id1 = "", fence_name1, fence_type1 = "", fence_status;
float default_size = 100000, landmark_latitude1 = 0, landmark_longitude1 = 0, fence_latitude1 = 0, fence_longitude1 = 0, fence_size1 = 0, longitude_x = 0, latitude_y = 0;
int points_polygon = 0;
ArrayList vertices_x = new ArrayList();
ArrayList vertices_y = new ArrayList();
query = "select latitude,longitude,added_date_time,speed,location,(select object_value from tracking_master_objects where object_id = a.object_id) as object from tracking_data_domain a where object_id in(select object_id from tracking_assign_fence a where fence_id = '" + hid_fence_id.Value + "' and is_active = '1') and (added_date_time between convert(datetime, '" + hid_fence_start_datetime.Value + "', 105) and convert(datetime, '" + hid_fence_end_datetime.Value + "', 105)) order by gps_id asc";
dr = common.run_query(query, db, cm, dr, 0);
if (dr.HasRows)
{
//To Build Fence Latitudes and Longitudes
query = "select fence_id,fence_name,fence_type,landmark_latitude,landmark_longitude,fence_latitude,fence_longitude,fence_size from tracking_master_fences where domain_id = '" + domain_id1 + "' and fence_id = '" + hid_fence_id.Value + "' and is_active = '1'";
dr2 = common.get_row(query, db2, cm2, dr2, 0);
if (dr2.HasRows)
{
fence_id1 = dr2["fence_id"].ToString();
fence_name1 = dr2["fence_name"].ToString();
fence_type1 = dr2["fence_type"].ToString();
landmark_latitude1 = common.make_float(dr2["landmark_latitude"].ToString());//fs_lat
landmark_longitude1 = common.make_float(dr2["landmark_longitude"].ToString());//fs_long
fence_latitude1 = common.make_float(dr2["fence_latitude"].ToString());//sec_lat
fence_longitude1 = common.make_float(dr2["fence_longitude"].ToString());//sec_long
fence_size1 = common.make_float(dr2["fence_size"].ToString());
}
dr2.Close();
//Build POlygon Vertices
if (fence_type1 == "4")
{
query = "select polygon_latitude,polygon_longitude from tracking_master_fence_polygons where fence_id = '" + hid_fence_id.Value + "' and domain_id = '" + domain_id1 + "'";
dr1 = common.run_query(query, db1, cm1, dr1, 0);
if (dr1.HasRows)
{
while (dr1.Read())
{
vertices_x.Add(dr1["polygon_latitude"]);
vertices_y.Add(dr1["polygon_longitude"]);
}
}
dr1.Close();
points_polygon = vertices_x.Count;
}
//Create a Datatable of 14 rows
dt_fence.Columns.Add("fence_id", typeof(string));
dt_fence.Columns.Add("Date", typeof(string));
dt_fence.Columns.Add("Speed", typeof(string));
dt_fence.Columns.Add("Location", typeof(string));
dt_fence.Columns.Add("landmark_latitude", typeof(string));
dt_fence.Columns.Add("landmark_longitude", typeof(string));
dt_fence.Columns.Add("fence_latitude", typeof(string));
dt_fence.Columns.Add("fence_longitude", typeof(string));
dt_fence.Columns.Add("latitude", typeof(string));
dt_fence.Columns.Add("longitude", typeof(string));
dt_fence.Columns.Add("fence_size", typeof(string));
dt_fence.Columns.Add("fence_type", typeof(string));
dt_fence.Columns.Add("fence_status", typeof(string));
dt_fence.Columns.Add("object", typeof(string));
while (dr.Read())
{
fence_status = "";
float latitude = common.make_float(dr["latitude"].ToString());
float longitude = common.make_float(dr["longitude"].ToString());
if (fence_type1 == "1" || fence_type1 == "2")
{
if (((landmark_latitude1 * 100000) < (latitude * 100000) && (fence_latitude1 * 100000) > (latitude * 100000)) && ((landmark_longitude1 * 100000) < (longitude * 100000) && (fence_longitude1 * 100000) > (longitude * 100000)))
{
fence_status = "Inside";
}
else
{
fence_status = "Outside";
}
}
else if (fence_type1 == "3")
{
float ft = ((latitude * 100000) - (landmark_latitude1 * 100000));
float st = ((longitude * 100000) - (landmark_longitude1 * 100000));
float sqrt = common.make_float(Math.Sqrt((ft * ft) + (st * st)).ToString());
if (fence_size1 < sqrt)
{
fence_status = "Out Side";
}
else
{
fence_status = "In Side";
}
}
else if (fence_type1 == "4")
{
longitude_x = common.make_float(dr["latitude"].ToString());
latitude_y = common.make_float(dr["longitude"].ToString());
int i = 0, j = 0, c = 0;
for (i = 0, j = points_polygon - 1; i < points_polygon; j = i++)
{
float vertices_y_i_val = common.make_float(vertices_y[i].ToString());
float vertices_y_j_val = common.make_float(vertices_y[j].ToString());
float vertices_x_i_val = common.make_float(vertices_x[i].ToString());
float vertices_x_j_val = common.make_float(vertices_x[j].ToString());
if (((vertices_y_i_val > latitude_y != (vertices_y_j_val > latitude_y)) &&
(longitude_x < (vertices_x_j_val - vertices_x_i_val) * (latitude_y - vertices_y_i_val) / (vertices_y_j_val - vertices_y_i_val) + vertices_x_i_val)))
{
c = 1;
}
}
if (c == 1)
{
fence_status = "In Side";
}
else
{
fence_status = "Out Side";
}
}
dt_fence.Rows.Add(fence_id1, dr["added_date_time"], dr["speed"], dr["location"], landmark_latitude1, landmark_longitude1, fence_latitude1, fence_longitude1, latitude, longitude, fence_size1, fence_type1, fence_status, dr["object"]);
}//End of while Loop
//hid_ds_fence.Value = dt_fence.ToString();
gridview_fence.DataSource = dt_fence;
gridview_fence.DataBind();
}
dr.Close();
fence_modalpopup.Show();
}
In your code you're assigning EmptyDataText value after DataBind. It should be before DataBind. If "Message" is not going to change, you should rather define in HTML source as suggested.
You can use something like this
<Columns>
<Columns>
<EmptyDataTemplate>
<asp:Label ID="lblEmptydata" runat="server" Text="No Data here"></asp:Label>
</EmptyDataTemplate>
</asp:GridView>
Or can try this
in my remark gridview's row_databoundevent i wrote
if (e.Row.Cells[0].Text == " ") // to display text when there is no data
{
e.Row.Cells[0].Text = "No Data Found";
}
Or can try this too
dt.Rows.Add(dt.NewRow());
grid1.DataSource = dt;
grid1.DataBind();
int totalcolums = grid1.Rows[0].Cells.Count;
grid1.Rows[0].Cells.Clear();
grid1.Rows[0].Cells.Add(new TableCell());
grid1.Rows[0].Cells[0].ColumnSpan = totalcolums;
grid1.Rows[0].Cells[0].Text = "No Data Found";

Resources