Thursday, August 21, 2008

Web 2.0 and Indentity

From a long time, discovering passwords and the secret questions were hard to get and almost uses the technical expertise sniffing on ports, and hacking the target computer by applications or even using brute force attack, and getting some information about the domain you would like to hack, and all these stuff. The hardest part was to crack someone's identity over the web. It has to be through the relationship between you and the person you would like to hack. So, you sneak around him/her and watch the different activities he/she does to guess what he/she likes - like pets, furniture, trees, flowers...etc - it was the hardest part. It turns that you are a spy on him/her.


A tag cloud with terms related to Web 2.Web 2.0 has been coming. This sentence has changed the world. Many many people will be writing their stories and experience. The content will be from the users not from the companies. There were a punch of tools like blogging and wiki and other tools that make Web 2.0 more powerful. Yet we have a huge source of information getting from the people themselves and the companies. Pretty Cool huh !!!!



Now it is getting clear enough that Web 2.0 drives the identity to be public and more than that readable by hackers and crackers. I read this article How I Stole Someone's Identity, and I got shocked, not that shock when you touch electricity, but yeah your identity and my identity are public now. Anyone can read it and download it, and spend a day discovering my hobbies and my interests and begin trying to access my e-mail that i gave him. and then trying to access my visa number that I talked about it once in my blog, but not this blog :), and then ta da. I got busted and then I will receive a letter from the bank that I make my balance zero :( :( :( .

I guess from now, secrets should be kept in your mind only. Do not talk about yourself loudly, or you got busted by many hackers...

Tuesday, July 15, 2008

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

If you have this exception, with wired error message and the stack trace is some how freeek.

Simply, this exception occurs when you have a server side call from javascript located at the head tag of the html like that
< head runat="server" >
< script >
var controlClientObject = <%= RadControl1.ClientID %>
...
< / script>


<
body >
...

you should do that

< head runat="server" >

<
body >
< script >
var controlClientObject = <%= RadControl1.ClientID %>
...
< / script >
...

I googled a lot and this is what concluded.

ref. http://www.telerik.com/help/aspnet/menu//menu_move_codeblocks.html
Zemanta Pixie

Monday, May 19, 2008

Excel Export

Microsoft Excel (Windows)Image via WikipediaFaced many problems when loading or exporting to excel files! got many confused when loading data from excel file and it seems that the data you have is less than the data in the file. Needed to do many calculations and formatting!

the problem is we don't know how to deal with excel, and how excel deals with data connectors like ODBC.

I faced these issues and searched a lot to get a result and got these guidelines.

1- for loading an excel file make sure you format the excel file to the desired format you want. example: if you only will get the data in number format, so format the column with the suitable numeric format. so that all the data that you will have is the numbers, if you types a word in this column, excel will not transfer this value to the ODBC driver.

If you want it generic so you will format it as text. so whatever gets into the cell excel will transfer it.

here is a snippet of how loading from excel. [the code is in C#]

public DataTable LoadSheet(string sheetName)
{
DataTable dtSheet = new DataTable();

string excelConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\";";

string command = "select * from [" + sheetName + "$]";

new System.Data.OleDb.OleDbDataAdapter(command, excelConString).Fill(dtSheet);
return dtSheet;
}

this how to load a sheet of excel into DataTable which you can deal with in the rest of your code.

*Trick: when reading, excel considers the first formatted row as the table header [formatted means bordered] if you did not do that the headers will be F1, F2...etc

2- Writing to Excel. the problem begins.
  1. first you have to export to a named sheet
  2. the sheet should be in a table format, if you typed in this sheet before exporting the writing process will begin writing after your writing. example: you write in cell A2, when exporting the excel will begin writing from A3, B3,C3...etc.
  3. any formats should be applied on the previous cell that you want to write in. example: you to begin writing in cell A4, and you want it to be formated as numeric (#.00). So, you have to apply this format on cell A3 only and not the column.
  4. now you need the way to insert the rows.
OleDbConnection connection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + filePath + "';Extended Properties=Excel 8.0;");
connection.Open();
OleDbCommand command;
// insert rows
foreach (object item in items)
{
// insert row
command = CreateInsertCommand(sheetName, fields, connection, item);
command.ExecuteNonQuery();
}
private OleDbCommand CreateInsertCommand(string sheetName, ExcelField[] fields, OleDbConnection connection, object item)
{
StringBuilder builder = new StringBuilder();
string fieldValue;
OleDbParameter parameter = null;
int count = fields.Length;

OleDbCommand command = connection.CreateCommand();

for (int i = 0; i < count; i++)
{
fieldValue = (item is DataRow) ? fields[i].GetDataRowValue(item) : fields[i].GetValue(item);
if (i == 0)
{
builder.AppendFormat("insert into [{0}$] values(?", sheetName);
}
else
builder.Append(", ?");

parameter = new OleDbParameter(string.Format("param{0}", i), GetOleDBType(fields[i].FieldType));
parameter.Value = fieldValue;

command.Parameters.Add(parameter);

if (i == count - 1)
builder.Append(")");
}

command.CommandText = builder.ToString();
return command;
}
and tada it did insert the rows.

*Tricks: make sure you cast the fields values to its proper type.

Now the nightmare part. the calculations and advanced formatting. this is an excel behavior. if you need to do this you have to create a separate sheet for viewing and other sheets to get the data and make a reference from the view sheet to the other sheets.

the calculations will be on the view sheet. your export function will export to those sheets. And you have to open the file to apply the formatting otherwise it will not affected!!!!

Enjooy the excel loading and exporting.

those tips for formatting Excel.

Wednesday, May 7, 2008

This is a test For Zemanta :)

Zemanta Firefox pluginImage by Tom Raftery via FlickrI had added the Zemanta tool for testing it. Simply it is neat. and Now getting images and related articles and labels for the topic you want to write about is now pretty simple. when I writing now about the topic the images is not yet related :D i think Zemanta has no related images!!!






Tuesday, March 4, 2008

Asp.net TreeView state

Don't you ever wanted to preserve the tree status over multiple pages? I searched for many times and found the solution.

  1. use cookies
  2. javascript override functions
  3. TreeView javascript important functions

  1. these script assign a value to cookie:

function getCookieVal (offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < style="color: rgb(51, 51, 255);">var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

function SetCookie (name, value)
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function DeleteCookie (name)
{
var exp = new Date();
exp.setTime (exp.getTime() - 1000000000); // This cookie is history (changed -1 to make it previous time)
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


2-

To override the function in JavaScript, simply define a new variable to hold the old function, and redefine the old function variable as a new function. Here’s the syntax:

var base_TreeView_ToggleNode = TreeView_ToggleNode;

TreeView_ToggleNode = function(data, index, node, lineType, children){

base_TreeView_ToggleNode(data, index, node, lineType, children);

setProfileFolder(data, index,node,children);

return;

}
The setProfileFolder function is our addition to the base method.

see the original reference here.

3- Now you have to see the important functions and concepts about the treeview control

  • TreeView_GetNodeText(node): it takes a node object and returns the node name
believe me it is good, if you want to try to get it by your self you will fail, the structure is so complicated.

  • Facing the similar nodes in text but in different branches:
This is why the index thing exists. The tree view in javascript collect all items in javascript in an array. So, if you have:

Parent
+ child 01
--+child 02
-----leaf

it will be indexed like this

Parent [0]
+ child 01 [1]
--+child 02 [2]
-----leaf [3]

  • you can navigate through the child nodes like this
var childNodes = children.getElementsByTagName("a");
var increment = 0;
for(;incrementvar child_node_name = TreeView_GetNodeText(childNodes[increment]) ;
}


In the server side parse the cookie back and preserve the collapse/expand behaviour.

Tuesday, December 11, 2007

Do not hesitate

Don't you ever get a thought. and wants to make it. May be this idea is big or small.

I was wondering the past days, which idea could change the world, and make me rich :) at the same time. I was reading about many startups the last 2 years. some of them got the high pitch, like youTupe and Facebook

and many many other ideas that make a good leap. but i found this article that talks about good start. you should never think about money. you should never think about the market. Just do it.

Do your idea as simple as it is, make it exciting, and link to public to get their feedback.


Just Do It.

reference: http://www.techcrunch.com/2007/12/05/loic-le-meurs-ten-rules-for-startup-success/

Wednesday, September 12, 2007

SQL Server Reporting Service

Now this is the first tool to view the things, like cubes or even a relational database.

the new version of SQL Reporting service 2005, they added in it 2 features:

1- the report can connect on a cube to build a report in it.
2- the report model concept.

the first one is logical, because they are now building a BI solution. but the second one is fantastic. Although you have a cube in your application or not, Although you meet all the reporting requirements or not. The Client can do his report by him self. and can store it in warehouse to view it multiple times!!!!

The report model make this task easy.

How?

First you generate the Model, from either cube or RDB. Then deploy it. then link the client to the report server. He will find a link named "Report Builder". The wizard will come now.

The Client will open the report builder, selecting the appropriate model. then tada.. he will build a report of huge functionality like navigate through, complex calculations, grouping, ...etc without even writing any minor script. Just drag and drop.

the report model is the business representation of your entities. whether it is cube or RDB. it will generate a business entities that you can change their names to logical names example: instead of "PRODUCT_CATEGORY", you will rename it to: "Product Category".

The Client will generate all his reports and then deploy it in the report server. Then you can link to it from the report you are doing or from your application.

try it by your self, it is cute....

the next time we will apply security on the report and show some troubleshoots.