No Picture
C#

[C#] 如何連接UNC path

2016-03-22 C.H. Ling 0

在.net environment, 本身不支援UNC path, 若加上user name /password 設定, 總會throw exception. 網上找來一個class, 它是call windows dll 去進行連結. 若在windows environment 的話, 不失為一個好方法.

No Picture
C#

[C#] 如何為貨幣加上 thoudenson separator

2016-03-22 C.H. Ling 0

在顯示貨幣時, 每隔三個位, 都須要加一個”,”分隔, 在C# 可以自行implement 如下: public static string ConvertToCurrency(double value) { string result = String.Format(“{0:#,##0.##00}”,value); return result; }  

No Picture
C#

[C#] 如何將string encode / decode

2016-03-22 C.H. Ling 0

部份內容須要儲存或傳送, 若plain text 的話會是一個考量, 故須要將它encode. public static string Base64Encode(string plainText) { var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText); return System.Convert.ToBase64String(plainTextBytes); } public static string Base64Decode(string base64EncodedData) { var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData); return System.Text.Encoding.UTF8.GetString(base64EncodedBytes); }  

No Picture
Spring MVC

[Spring MVC] 如何發出電郵

2016-03-22 C.H. Ling 0

public boolean sendMail(EmailMessage emailMessage) { boolean result=false; try { // Generate Spring MIME message and send. // Get system properties Properties properties = System.getProperties(); if(ServerUtil.isWindows()) properties.setProperty(EMAIL_SMTP_HOSTNAME_WIN, smtpHostName); else properties.setProperty(EMAIL_SMTP_HOSTNAME_LINUX, smtpHostName); Session session = Session.getDefaultInstance(properties); MimeMessage […]

No Picture
Quartz

[Quartz] 設定程式定時自動執行

2016-03-22 C.H. Ling 0

Quartz 是一個scheduler API, 可以讓program 於指定時間, 自動執行指令. 相對使用windows的schedule job 或Linux 的cron job, 它少了OS level 的dependency, 即是無須設定執行schedule job 的user account 等. 使用時, 須要implement 其Interface IJob. public class CheckUnsentEmailJob : IJob { public override void Execute(IJobExecutionContext context) { […]

No Picture
C#

[C#] 如何發出電郵

2016-03-22 C.H. Ling 1

在send email 前, 先講如何制造email object. 這裡用了一粒class 去包著須要send的內容. 故砌真. object 時, 這個method 可以定義為adapter 的implementation. private MailMessage createMailMessage(EMAIL email) { MailMessage mail = new MailMessage() { From = new MailAddress(email.FROM_EMAIL_ADDRESS), }; mail.To.Add(new MailAddress(email.TO_EMAIL_ADDRESS)); if (!string.IsNullOrEmpty(email.CC_EMAIL_ADDRESS)) mail.CC.Add(new MailAddress(email.CC_EMAIL_ADDRESS)); […]

No Picture
Bootstrap

[Bootstrap] Extension: DateTime picker

2016-03-22 C.H. Ling 0

有時砌web form 須要user 輸入日期, 但如果用textbox 的話, 其輸入內容會五花八門. 為了統一格式, 以及令user experience 更好, 故找來了bootstrap 的datetime picker. 配合JQuery, 它可作更多的應用. Screenshot: (Source: https://github.com/Eonasdan/bootstrap-datetimepicker) URL: https://github.com/eternicode/bootstrap-datepicker

No Picture
ASP.net MVC

[ASP.net MVC] 如何upload file並經controller 放於Network storage

2016-03-22 C.H. Ling 0

View: 留意須要自行定義encType作multipart/form-data, 不然的話controller 不會接到file value. @using (Html.BeginForm(“CreatePost”, “Email”,FormMethod.Post, new { enctype= “multipart/form-data”, id=”formSendEmail” })) { @Html.AntiForgeryToken() <div class=”form-horizontal”> <input type=”file” id=”attachments” name=”attachments[]” multiple /> <div class=”form-group”> <div class=”col-md-offset-2 col-md-10″> <input type=”submit” value=”Create with file” class=”btn […]

No Picture
C#

[C#] 如何產生Random string

2016-03-22 C.H. Ling 0

若在concurrency中, 有時須要產生一堆random number去做, 但工作上, 要制做一條unique path, 除了用primary key 外, timestamp + random number 亦是一個好選擇. 為了更精準 (或者無聊), 便嘗試了random string. private string RandomString(int size) { Random random = new Random((int)DateTime.Now.Ticks); StringBuilder builder = new StringBuilder(); char ch; […]

No Picture
JQuery

[JQuery] Plug-in: Full Calendar

2016-03-18 C.H. Ling 0

寫Application時, 有 user 要求要在calendar中顯示event, 為了極速開發. 找到了個calendar 做參考. Source: http://www.oodlestechnologies.com/blogs/Fullcalendar-Walk-through-with-AngularJS Full Calendar: http://fullcalendar.io/

1 23 24 25 26 27