2010年1月29日 星期五

關於 asSQL 顯示中文的問題

昨天玩了一下 Flex AIR , 使用 asSQL 連接 MySQL DB 取資料時發現中文的部份
會出現亂碼, 經查證是 com.maclema.mysql.ResultSet 裡的Code有問題












internal function initialize(charSet:String):void {
        charSet = charSet;
        ....
}

以上是Source Code的部份, 這樣子是無法將外部定義的charSet傳入
需將 Code  修改為



internal function initialize(charSet:String):void {
        this.charSet = charSet;
        ....
}

然後在MXML中使用MysqlService時, 需定義charSet="utf8"


<assql:MySqlService id="service"
                hostname="localhost"
                username="root"
                password="smile69"
                database="smilelight"
                autoConnect="true"
                charSet="utf8"
                connect="handleConnected(event)"
                sqlError="handleError(event)" />


中文字才會顯示正常

解決Web Service回傳資料筆數過大問題

將 web.config 裡的
<behaviors> 
  <serviceBehaviors>  
    <behavior name="DefaultBehavior">  
      <serviceMetadata httpGetEnabled="true"/>  
      <serviceDebug/> 
    </behavior>  
  </serviceBehaviors> 
</behaviors>
改成
<behaviors> 
  <endpointBehaviors>
    <behavior name="DefaultBehavior">
      <dataContractSerializer maxItemsInObjectGraph="67108864"/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>  
    <behavior name="DefaultBehavior">  
      <serviceMetadata httpGetEnabled="true"/>  
      <serviceDebug/> 
      <dataContractSerializer maxItemsInObjectGraph="67108864"/>
    </behavior>  
  </serviceBehaviors> 
</behaviors>

就可以解決大量筆數的問題了

2010年1月28日 星期四

Send Mail for .Net

Source Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace FFTSendMail
{
  class Program
  {
    static void Main(string[] args)
    {
      try
      {
        string baseDir = AppDomain.CurrentDomain.BaseDirectory;
        SmtpClient smtpClient = new SmtpClient();
        MailMessage mail = new MailMessage();
        Attachment attachment = new Attachment(baseDir + "StaeMJ_0128_WinList.csv");

        //Smtp Server IP/Domain
        smtpClient.Host = "192.168.0.1"; 

        //From Mail
        mail.From = new MailAddress("allen.su@test.com.tw", "allensu");

        //Content
        mail.Body = "test 內容";

        //Subject
        mail.Subject = "test 標題";
        mail.BodyEncoding = System.Text.Encoding.UTF8;

        //To Mail
        mail.To.Add(new MailAddress("allen.su@test.com.tw", "allensu"));

        //Attachment file
        mail.Attachments.Add(attachment);
                        
        smtpClient.Send(mail);
        Console.WriteLine("success");
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
      }

      Console.ReadLine();
    }
  }
}

2010年1月22日 星期五

Replace Into 與 Insert Into

Replace Into 與 Insert Into 的用法

Replace Into 其實就是做了二件事
1. Delete
2. Insert Into

差別在於 Insert Into 遇到 Duplicate 時, 會產生Exception
而 Replace Into 則會將原資料 Delete 再 Insert Into

2010年1月20日 星期三

Select random row for MS SQL

使用 NEWID() 函數

EX.

  SELECT TOP 1 AccountID
  FROM YahooMapID_T 
  WHERE YahooID IS NULL
  ORDER BY NEWID()

2010年1月12日 星期二

千分號顯示

import java.text.DecimalFormat;

DecimalFormat format2 = new DecimalFormat("###,###,###");

int money = 1000;

String moneyComa = format2.format(money);

System.out.pirntln(moneyComa); //1,000;

使用eclipse產生javadoc文件中文亂碼解決

VM options 欄位中輸入
-encoding UTF-8 -charset UTF-8

ComboBox store from remote data

If remote data like :

[{"createDate":"2009-12-04T00:38:38","createUserID":
"System","param_Description":"??","param_Group_Name":
"Locale","param_Name":"EnUS","param_Sort_Order":1,
"param_Status":1,"param_Value":"en_US","serNo":
"PARAM00000000000000000003","updateDate":
"2009-12-04T00:38:41","updateUserID":"System"},
{"createDate":"2009-12-04T00:37:34","createUserID":
"System","param_Description":"??(??)",
"param_Group_Name":"Locale","param_Name":
"ZhTW","param_Sort_Order":0,"param_Status":1,
"param_Value":"zh_TW","serNo":"PARAM00000000000000000002",
"updateDate":"2009-12-04T00:37:55","updateUserID":"System"}]

Step1. New JsonReader object like :
var localeJsonDefine = new Ext.data.JsonReader({}, 
   ['param_Group_Name', 'param_Name', 'param_Value', 'param_Description']);

Step2. New data Store like :
var localeDataStore = new Ext.data.Store({
      proxy : new Ext.data.HttpProxy({
         url : 'http://localhost:6957/SLPortal/getLocaleGroupAction.action' 
      }),
      reader : localeJsonDefine,
      remoteSort : false
   });

Step3. New ComboBox like :
var localeCbx = new Ext.form.ComboBox({
      fieldLabel : localeFieldText,
      store : localeDataStore, 
      editable : false,
      emptyText : localeFieldEmptyText, 
      valueField : 'param_Value',
      displayField : 'param_Description',
      mode : 'remote',
      triggerAction : 'all'
   });

用.Net讀取MySQL Latin文字

先將讀出來的Latin轉成byte[], 再轉成String


1.Encoding.Default.GetString(Encoding.GetEncoding(1252).GetBytes(mysqlReader.GetValue(i).ToString()))


or 


2. Encoding.Default.GetString(Encoding.GetEncoding("big5").GetBytes(mysqlReader.GetValue(i).ToString()))


參考網址 : http://www.programmer-club.com.tw/ShowSameTitleN/adodotnet/1479.html