Posts

Showing posts from 2012

C# - Entity Framework - GROUP BY/ORDER BY/SELECT WHERE IN

var _inner_query = this.g_db_entity.ACTIVITIES                 .Where(w => (DateTime.Today <= w.ACTIVITY_DATE_TO))                 .GroupBy(g => g.ACTIVITY_DATE_FROM)                 .OrderBy(o => o.Key)                 .Select(s => s.Key)                 .Skip((pageNo - 1) * this.g_page_size)                 .Take(this.g_page_size); LIST<ACTIVITIES> _entity_activity = this.g_db_entity.ACTIVITIES                  .Where(m => _inner_q...

C# - Binary PDF File on Web Broswer via Binary Stream

Your binary PDF File was saved in MSSQL2008 in image data type. Byte[] _binary_document;// you get your binary data from database and assign to this parameter. //Result of binary stream Response.ContentType = "Application/pdf"; Response.AppendHeader("Content-Length", _binary_document.Length.ToString()); Response.BinaryWrite(_binary_document);

C# - Image to Byte Array and vise versa

System.Drawing.Image img = System.Drawing.Image . FromFile ( @"C:\Lenna.jpg" ); byte[] _byte_array = imageToByteArray(img, "jpg");     ------------------------------------------------------   public byte [] imageToByteArray(System.Drawing.Image imageIn , String imageFileType ) {    MemoryStream ms = new MemoryStream();    switch(imageFileType.ToLower()) {   case "gif": imageIn.Save(ms,System.Drawing.Imaging.ImageFormat.Gif); break; case "jpg": case "jpeg":   imageIn . Save ( ms , System . Drawing . Imaging . ImageFormat . Jpeg ); break; }   return ms.ToArray(); }   ------------------------------------------------------   public Image byteArrayToImage( byte [] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); Image returnImage = Image.FromStream(ms); return returnImage; }     web reference: http://www.codep...

JAVA - Check the value exists in an array

Check if a value exists in an array:   Arrays . asList ( someArray ). contains ( value );     ** It's not workd for array of integer, but array of string is ok. 

PHP - if statement (shorthand)

<?php          $input_type = "daily";          echo ($input_type == "daily"? "yes" : "no") ?>

PHP - Fatal error: Call to undefined function curl_init()

Fatal error: Call to undefined function curl_init() Resolve for Windows: 1. Open "php.ini" (AppServ Apache Server -> Start Menu -> All Programs -> AppServ -> Configuration Server -> PHP Edit the php.ini Configuration File) 2. Find the text ";extension=php_curl.dll" 3. Remove "semi-colon" at the first of the text, the text will be "extension=php_curl.dll" 4. Save the file and restart Apache Server ------------------------------------------------------------ If the error is not solve, please try this solution  (Reference to Windows7). 1. Right click on "My Computer" -> Properties -> Advanced system settings 2. Select "Advanced Tab" -> Environment Variables -> System Variables 3. Choose "Variable Path" -> Click Edit 4. Append path of your PHP folder in the current string example. "C:\AppServ\php5;" 5. Click "OK" and restart your computer It...

PHP - Displaying MySQL Column Names and Values via PHP

$result = mysql_query($sql); if ($result) {         $total_row = mysql_num_rows($result); } if ($total_row > 0) {         while ($tableRow = mysql_fetch_assoc($result)) {                $result_body.= "<item>";                foreach ($tableRow as $column => $value) {                     $result_body.= "<{$column}><![CDATA[{$value}]]></{$column}>";                }                $result_body.= "</item>";         } }

PHP - CheckBoxList

# Form Input: < form id =" myForm " method =" post "> < input id =" CheckBoxList[] " type =" checkbox " name =" CheckBoxList[] " value =" 1 " / > < input id =" CheckBoxList[] " type =" checkbox " name =" CheckBoxList[] " value =" 4 " checked =" checked " / > < input id =" CheckBoxList[] " type =" checkbox " name =" CheckBoxList[] " value =" 3 " checked =" checked " / > < input type =" submit " name =" ButtonOK " value =" Save " / > < /form>   # PHP Action: $access_menu_id_array = $_POST["CheckBoxList"]; for($i=0; $i<sizeof($access_menu_id_array); $i++) { $access_menu_id .= $access_menu_id_array[$i]; if ((i+1) < sizeof($access_menu_id_array)) $access_menu_id .= ","; }

PHP - Array 2 Dimension

<?php      $car1[0][1]="Jeep Grand Cherokee";      $car1[0][2]=2002;      $car1[1][1]="Jeep Wrangler";      $car1[1][2]=2002;      $car1[2][1]="Jeep Liberty";      $car1[2][2]=2003;      $car1[3][1]="Jeep Cherokee Briarwood";      $car1[3][2]=2003;      for($x=0; $x<4;$x++)      {           for($i=1; $i<3;$i++)           {                echo $car1[$x][$i]."<br>";           }      } ?> Reference : http://www.pctalknet.com/php/variables.php

C# - Get Path from file path

String _file = "c:\monthly_report\2012\07_JUL\2012_07.xls"; String _path = System.IO.Path.GetDirectoryName(_file); >> Result _path = c:\monthly_report\2012\07_JUL

C# - if statement (shorthand)

In normal statement, we use if statement : Boolean _valid = false; if (_command.ToLower() == "get_data")      _valid = true; else      _valid = false; We can use the shorthand statement:      _valid = _command.ToLower() == "get_data"? true : false;

MSSQL - Date Format

Web Reference : www.sql-server-helper.com Standard Date Formats Date Format SQL Statement Sample Output Mon DD YYYY 1 HH:MIAM (or PM) SELECT CONVERT(VARCHAR(20), GETDATE(), 100) Jan 1 2005 1:29PM 1 MM/DD/YY SELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [MM/DD/YY] 11/23/98 MM/DD/YYYY SELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY] 11/23/1998 YY.MM.DD SELECT CONVERT(VARCHAR(8), GETDATE(), 2) AS [YY.MM.DD] 72.01.01 YYYY.MM.DD SELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD] 1972.01.01 ...

MSSQL - DATEADD Function

Syntax: DATEADD (datepart , number , date ) Datepart Abbreviations year yy, yyyy quarter qq, q month mm, m dayofyear dy, y day dd, d week wk, ww weekday dw, w hour hh mi...

MSSQL - LEFT OUTER JOIN

Example: Left Outer Join SELECT Customers.CustomerName, Sales.SaleDate FROM Customers LEFT OUTER JOIN Sales ON Sales.CustID = Customers.CustID

MSSQL - Alter Column Data Type

In normally in SQL, syntax for alter table is ALTER TABLE table_name MODIFY column_name data_type Example. ALTER TABLE products MODIFY product_name VARCHAR2(50) But if in MSSQL, you have to use "ALTER COLUMN" instead. ALTER TABLE table_name ALTER COLUMN column_name data_type Example. ALTER TABLE products ALTER COLUMN product_name varchar(50)

C# - AES Encrypt

input: string message, string keycode output: string BASE64String using System.Security.Cryptography; RijndaelManaged aesCipher = new RijndaelManaged(); ASCIIEncoding textConverter = new ASCIIEncoding(); Byte[] iv; aesCipher.KeySize = 128; aesCipher.BlockSize = 128; aesCipher.Mode = CipherMode.ECB; aesCipher.Padding = PaddingMode.Zeros; aesCipher.Key = textConverter.GetBytes(keycode); ICryptoTransform crypto = aesCipher.CreateEncryptor(); Byte[] toEncrypt = textConverter.GetBytes(messg); Byte[] cipherText = crypto.TransformFinalBlock(toEncrypt, 0, toEncrypt.Length); String base64Str = ""; base64Str = Convert.ToBase64String(cipherText);

C# - Server Variable

Example: String _user_agent = Request.ServerVariables["HTTP_USER_AGENT"]; String _all_http = Request.ServerVariables["ALL_HTTP"]; Response.Write("user_agent:" + _user_agent + ","); Response.Write("ALL HTTP:" + _all_http); All Server Variable: ALL_HTTP ALL_RAW APPL_MD_PATH APPL_PHYSICAL_PATH AUTH_PASSWORD AUTH_TYPE AUTH_USER CERT_COOKIE CERT_FLAGS CERT_ISSUER CERT_KEYSIZE CERT_SECRETKEYSIZE CERT_SERIALNUMBER CERT_SERVER_ISSUER CERT_SERVER_SUBJECT CERT_SUBJECT CONTENT_LENGTH CONTENT_TYPE GATEWAY_INTERFACE HTTPS HTTPS_KEYSIZE HTTPS_SECRETKEYSIZE HTTPS_SERVER_ISSUER HTTPS_SERVER_SUBJECT INSTANCE_ID INSTANCE_META_PATH LOCAL_ADDR LOGON_USER PATH_INFO PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST REMOTE_USER REQUEST_METHOD SCRIPT_NAME SERVER_NAME SERVER_PORT SERVER_PORT_SECURE SERVER_PROTOCOL SERVER_SOFTWARE URL HTTP_CACHE_CONTROL HTTP_CONNECTION HTTP_ACCEPT HTTP_ACCEPT_ENCODING HT...

MSSQL - How to set Case Sensitive in varchar data type

The default setting of the varchar data type in MSSQL2008 is non-case sensitive. The lower-case is equal the upper-case ex. cat = CaT. If you need the difference between upper-case and lower-case on your data, you can set your field by: 1. Right click on your table and select "Design". 2. Click on your field you need to set " Case-Sensitive " and see at "Column Properties" window below. 3. In "Column Properties" window, find "Table Designer" and click on the right column of "collation" 4. In the pop up window. Choose "windows Collation" -> Dictionary Sort and check on Case Sensitive 5. Click "OK" to finish.