Saturday, June 25, 2011

Crystal Report in Visual Studio 2010

Crystal Report is a easy tool for us to design and generate report from data source. But unfortunately, Visual Studio 2010 didn't included it, you need to download from SAP as add-on application. Plus, if you using Visual Studio Express 2010 you may not to using features like editing .rpt file, export as pdf file format, etc. Express version only install runtime which enable you to view crystal report. Another weakness of Crystal Report in Visual Studio 2010 is when you put your crystal report to server, your server need to install runtime in order to view crystal report. It's quite inconvenience for those company which sell their product to client because need to include runtime msi which occupied up to 70MB. For your more information, please take a look here. Thanks~ =)

Wednesday, June 15, 2011

Generate JSON from MySQL using C#

I would like to share this article because I try to search some related posts or articles and found out it was rare when compare with other topics. Hence, I do it by myself and hope you can get what you want from here.

Before start write your coding, please make sure you add reference Newtonsoft.Json. If you haven't get it, please download from here.

Define your mySQL connection first and write your query.
  1. MySqlConnection conn = new MySqlConnection(
  2. "server=localhost;" +
  3. "uid=xx;" +
  4. "pwd=xx;" +
  5. "database=xx;");
  6. MySqlCommand comm = new MySqlCommand();
  7. conn.Open();
  8. comm = conn.CreateCommand();
  9. comm.CommandText = "SELECT name FROM student";
  10. MySqlDataReader reader = comm.ExecuteReader();
  11. List<Student> eList = new List<Student>();
Don't forget to build constructor to get and set.
  1. public class Student
  2. {
  3. public string Name;
  4. }
Read database data line by line.
  1. while (reader.HasRows)
  2. {
  3. if (reader.Read())
  4. {
  5. Student e = new Student();
  6. e.Name = Convert.ToString(reader["Name"]);
  7. eList.Add(e);
  8. }
  9. else
  10. {
  11. break;
  12. }
  13. }
Convert to JSON format.
  1. System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
  2. string ans = oSerializer.Serialize(eList);
  3. string script = "{\"Employee\": " + ans + "}";
  4. ClientScriptManager cs = Page.ClientScript;
  5. cs.RegisterStartupScript(Page.GetType(), "JSON", script, true);
  6. Response.ContentType = "application/json";
  7. Response.Write(script);
Check your aspx file in browser.

Sharing is caring. =)



Sunday, June 12, 2011

Titanium Developer SDK loading Issue

Well, I'm new in Titanium Developer, hence a lot of things still in confuse condition. One of the problem I faced when I start develop my iPhone Application through Titanium Developer was when I run my Test & Package, my SDK appear loading... which mean it doesn't detect any path of my latest SDK version(I using old version Titanium while my Xcode and SDK version are latest one). When you go through Library/Application Support/mobilesdk/osx/ and inside osx folder only contains oldest version such as 1.2.x or 1.4.x folder. So what you need to do is update your version. Click here to download the latest Titanium SDK version. Extract the zip file and move it inside osx folder. Also, you need to recreate your project to make sure your Titanium SDK version is latest version. Check back your Test & Package, loading problem is no longer there.

Sharing is caring~ =)


Friday, June 10, 2011

Page Without Cache in C#

This question have been trouble me for whole day, just because i put my coding in wrong page. So, please make sure your page which don't want store any cache have following coding.

protected void DisableBufferingOnPage()
{
Response.Buffer = true;
Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
// set expiry date in the past
Response.Expires = -1500;
Response.CacheControl = "no-cache";
Response.Cache.SetNoStore();
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Cache-Control", "no-cache");
Response.CacheControl = "no-cache";
Response.Expires = -1;
Response.ExpiresAbsolute = new DateTime(1900, 1, 1);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.Now);
Response.Cache.SetAllowResponseInBrowserHistory(false);
}

Please call this function at Page_Load. Also, if you record your session when log in please make sure it is clear and abandon when log out.

Session.Clear();
Session.Abandon();

So, when you log out even you click back button also cannot go previous page unless you log in.

Sharing is caring~ Cheers~ =)