Sunday, September 04, 2011

jQuery UI Datepicker 1.8.16 民國年 Extender



jQuery UI Datepicker 1.8.16 民國年 Extender


Code Snippet



  1. /*
    * jQuery UI Datepicker 1.8.16
    * Taiwan's Minguo calendar extender
    * This extender modified the year to Taiwan's Minguo calendar
    * Extended by Eddie Chen
  2. */
  3. $.extend($.datepicker,{

  4. /* Parse existing date and initialise date picker. */

  5. _setDateFromField: function(inst, noDefault) {

  6. if (inst.input.val() == inst.lastVal) {

  7. return;

  8. }

  9. var dateFormat = this._get(inst, 'dateFormat');

  10. var dates = inst.lastVal = inst.input ? inst.input.val() : null;

  11. var date, defaultDate;

  12. date = defaultDate = this._getDefaultDate(inst);

  13. var settings = this._getFormatConfig(inst);

  14. try {

  15. //date = this.parseDate(dateFormat, dates, settings) || defaultDate;

  16. if(dates.couny>0)

  17. {

  18. var dateArr = dates.split("/");

  19. var year = parseInt(dateArr[0], 10) + 1911;

  20. var month = parseInt(dateArr[1], 10);

  21. var day = parseInt(dateArr[2], 10);

  22. date = new Date(year, month, day);

  23. }

  24. } catch (event) {

  25. this.log(event);

  26. dates = (noDefault ? '' : dates);

  27. }

  28. inst.selectedDay = date.getDate();

  29. inst.drawMonth = inst.selectedMonth = date.getMonth();

  30. inst.drawYear = date.getFullYear();

  31. inst.selectedYear = date.getFullYear();

  32. inst.currentDay = (dates ? date.getDate() : 0);

  33. inst.currentMonth = (dates ? date.getMonth() : 0);

  34. inst.currentYear = (dates ? date.getFullYear() : 0);

  35. this._adjustInstDate(inst);

  36. },

  37. _daylightSavingAdjust: function(date) {

  38. if (!date) return null;

  39. date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);


  40. if (!date) return null;

  41. if((date.getFullYear()-1911)>0)

  42. date.getFullYear((date.getFullYear()-1911));

  43. else

  44. date.getFullYear((date.getFullYear()));


  45. return date;

  46. },

  47. _taiwanDateAdjust: function(date) {

  48. if (!date) return null;

  49. if((date.getFullYear()-1911)>0)

  50. date.setFullYear((date.getFullYear()-1911),date.getMonth(),date.getDay());

  51. else

  52. date.setFullYear((date.getFullYear()),date.getMonth(),date.getDay());

  53. return date;

  54. },

  55. /* Generate the month and year header. */

  56. _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,

  57. secondary, monthNames, monthNamesShort) {

  58. var changeMonth = this._get(inst, 'changeMonth');

  59. var changeYear = this._get(inst, 'changeYear');

  60. var showMonthAfterYear = this._get(inst, 'showMonthAfterYear');

  61. var html = '<div class="ui-datepicker-title">';

  62. var monthHtml = '';

  63. // month selection

  64. if (secondary || !changeMonth)

  65. monthHtml += '<span class="ui-datepicker-month">' + monthNames[drawMonth] + '</span>';

  66. else {

  67. var inMinYear = (minDate && minDate.getFullYear() == drawYear);

  68. var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);

  69. monthHtml += '<select class="ui-datepicker-month" ' +

  70. 'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'M\');" ' +

  71. '>';

  72. for (var month = 0; month < 12; month++) {

  73. if ((!inMinYear || month >= minDate.getMonth()) &&

  74. (!inMaxYear || month <= maxDate.getMonth()))

  75. monthHtml += '<option value="' + month + '"' +

  76. (month == drawMonth ? ' selected="selected"' : '') +

  77. '>' + monthNamesShort[month] + '</option>';

  78. }

  79. monthHtml += '</select>';

  80. }

  81. if (!showMonthAfterYear)

  82. html += monthHtml + (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '');

  83. // year selection

  84. if ( !inst.yearshtml ) {

  85. inst.yearshtml = '';

  86. if (secondary || !changeYear)

  87. if((drawYear-1911) >0)

  88. html += '<span class="ui-datepicker-year">' + (drawYear-1911) + '</span>';

  89. else

  90. html += '<span class="ui-datepicker-year">' + drawYear + '</span>';

  91. else {

  92. // determine range of years to display

  93. var years = this._get(inst, 'yearRange').split(':');

  94. var thisYear = new Date().getFullYear();

  95. var determineYear = function(value) {

  96. var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :

  97. (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :

  98. parseInt(value, 10)));

  99. return (isNaN(year) ? thisYear : year);

  100. };

  101. var year = determineYear(years[0]);

  102. var endYear = Math.max(year, determineYear(years[1] || ''));

  103. year = (minDate ? Math.max(year, minDate.getFullYear()) : year);

  104. endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);

  105. inst.yearshtml += '<select class="ui-datepicker-year" ' +

  106. 'onchange="DP_jQuery_' + dpuuid + '.datepicker._selectMonthYear(\'#' + inst.id + '\', this, \'Y\');" ' +

  107. '>';


  108. if((drawYear-1911) >0)

  109. {

  110. for (; year <= endYear; year++) {

  111. inst.yearshtml += '<option value="' + year + '"' +

  112. (year == drawYear ? ' selected="selected"' : '') +

  113. '>' + (year-1911) + '</option>';

  114. }

  115. }

  116. else

  117. {

  118. for (; year <= endYear; year++) {

  119. inst.yearshtml += '<option value="' + year + '"' +

  120. (year == drawYear ? ' selected="selected"' : '') +

  121. '>' + (year) + '</option>';

  122. }

  123. }

  124. inst.yearshtml += '</select>';


  125. html += inst.yearshtml;

  126. inst.yearshtml = null;

  127. }

  128. }

  129. html += this._get(inst, 'yearSuffix');

  130. if (showMonthAfterYear)

  131. html += (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '') + monthHtml;

  132. html += '</div>'; // Close datepicker_header

  133. return html;

  134. },

  135. _formatDate : function(inst, day, month, year)


  136. {


  137. if (!day)


  138. {


  139. inst.currentDay = inst.selectedDay;


  140. inst.currentMonth = inst.selectedMonth;


  141. inst.currentYear = inst.selectedYear;


  142. }


  143. var date = (day ? (typeof day == 'object' ? day :


  144. this._daylightSavingAdjust(new Date(year, month, day))) :


  145. this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));


  146. return (date.getFullYear() - 1911) + "/" +


  147. (date.getMonth() < 9 ? "0" + (date.getMonth() + 1) : (date.getMonth() + 1)) + "/" +


  148. (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());


  149. }

  150. });






Saturday, August 27, 2011

How to prevent seeing “\ No newline at end of file” when using Git with Visual Studio

 

1. In Visual Studio menu, select Tools > Macros > Macros IDE

2. Select the Class View tab. Under My Macros, double click the EnvironmentEvents node.

3. select DocumentEvents from the dropdown list on the left, then select DocumentSaved from the dropdown list on the right. This will generate a blank event handler.

4. Paste the following code into the blank  event handler.

Private Sub DocumentEvents_DocumentSaved(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentSaved
        '
        ' This handler will add a newline to end of file if it doesn't already have one.
        '
        Dim textSelection As EnvDTE.TextSelection

        textSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)

        Dim originalLine As Integer
        originalLine = textSelection.AnchorPoint.Line
        Dim originalOffset As Integer
        originalOffset = textSelection.AnchorPoint.LineCharOffset
        Dim viewTop As EnvDTE.TextPoint
        viewTop = textSelection.TextPane.StartPoint

        textSelection.EndOfDocument(False)
        Dim pt As VirtualPoint
        pt = textSelection.BottomPoint()

        textSelection.GotoLine(pt.Line, True)
        If textSelection.Text.Length <> 0 Then
            textSelection.Text = textSelection.Text & vbCrLf
            DTE.ActiveDocument.Save()
        End If
        textSelection.MoveToLineAndOffset(originalLine, originalOffset, False)
        textSelection.TextPane.TryToShow(viewTop, vsPaneShowHow.vsPaneShowTop)
    End Sub

5. Save the macro

From now on all the files saved through Visual Studio will be appended with a new line to avoid the error message in the Git source control.

Sunday, February 20, 2011

Android Development Study Notes 2 - Opiton Menus

strings.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="AllDepartment">List All Depts</string>

<string name="Seach">Search</string>

</resources>

Add the following codes in the activity class


@Override

public boolean onCreateOptionsMenu(Menu menu) {

          menu.add(0, 0, 0,this.getResources().getString(R.string.AllDepartment));

          menu.add(0, 1, 1, this.getResources().getString(R.string.Seach));

return super.onCreateOptionsMenu(menu);

    }

When user click on "menu" button, 2 option menus would appear at the bottom of the screen.

Android Study Notes 1 - "Hello World"

"Hello World"

strings.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="hello">Hello World, DroidActivity!</string>

<string name="app_name">Droid1</string>

<string name="hello1">你好!</string>

</resources>

main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello"

/>

<TextView android:id="@+id/textView1"android:layout_width="wrap_content" android:layout_height="wrap_content"android:text="@string/hello1"></TextView>

</LinearLayout>

DroidAvtivity.java

package com.myandroid.droid1;
import android.app.Activity;
import android.os.Bundle;
public class DroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Wednesday, November 10, 2010

Validation of viewstate MAC failed

Error message:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey & validation algorithm. AutoGenerate cannot be used in a cluster.

Solution:
Disable viewstate change by adding this to the affected aspx page.
EnableViewState="false" EnableEventValidation="false" enableViewStateMac=false

For example:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="myLogin" EnableViewState="false" EnableEventValidation="false" enableViewStateMac=false %>

Cannot convert type ASP.login_aspx to System.Web.UI.WebControls.Login

Today I encountered this weird error after I published my ASP.NET to the server.
Cannot convert type ASP.login_aspx to System.Web.UI.WebControls.Login

Solution:
1. In login.aspx.cs
Change public partial class Login : System.Web.UI.Page to public partial class myLogin : System.Web.UI.Page

2. In login.aspx
Change <%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
to <%@ Page Language="C#" ValidateRequest="false" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="myLogin" %>

Monday, June 07, 2010

SQL script to get table metadata form a SQL server

// SQL script to get table metadata form a SQL server

SELECT u.name + '.' + t.name AS [table], c.name AS [column]
FROM sys.sysobjects AS t INNER JOIN
sys.sysusers AS u ON u.uid = t.uid LEFT OUTER JOIN
sys.extended_properties AS td ON td.major_id = t.id AND td.minor_id = 0 AND td.name = 'MS_Description' INNER JOIN
sys.syscolumns AS c ON c.id = t.id LEFT OUTER JOIN
sys.extended_properties AS cd ON cd.major_id = c.id AND cd.minor_id = c.colid AND cd.name = 'MS_Description'
WHERE (t.type = 'u')
ORDER BY t.name, c.colorder

Tuesday, December 01, 2009

To disable right click event in JavaScript using jQuery

$(function() {
$(this).bind("contextmenu", function(e) {
e.preventDefault();
});
});

Friday, August 07, 2009

WF Activity to send a plurk message


using System;

using System.ComponentModel;

using System.Workflow.Activities;

using System.Workflow.ComponentModel;

namespace SendPlurkMessageActivity

{

public partial class SendPlurkMessageActivity: SequenceActivity

{

public SendPlurkMessageActivity()

{

InitializeComponent();

}

#region Public workflow members

public static DependencyProperty PlurkUserNameProperty = DependencyProperty.Register("PlurkUserName", typeof(string), typeof(SendPlurkMessageActivity));

[DescriptionAttribute("PlurkUserName")]

[CategoryAttribute("PlurkUserName Category")]

[BrowsableAttribute(true)]

[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]

public string PlurkUserName

{

get

{

return ((string)(base.GetValue(SendPlurkMessageActivity.PlurkUserNameProperty)));

}

set

{

base.SetValue(SendPlurkMessageActivity.PlurkUserNameProperty, value);

}

}

public static DependencyProperty PlurkPasswordProperty = DependencyProperty.Register("PlurkPassword", typeof(string), typeof(SendPlurkMessageActivity));

[DescriptionAttribute("PlurkPassword")]

[CategoryAttribute("PlurkPassword Category")]

[BrowsableAttribute(true)]

[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]

public string PlurkPassword

{

get

{

return ((string)(base.GetValue(SendPlurkMessageActivity.PlurkPasswordProperty)));

}

set

{

base.SetValue(SendPlurkMessageActivity.PlurkPasswordProperty, value);

}

}

public static DependencyProperty PlurkMessageBodyProperty = DependencyProperty.Register("PlurkMessageBody", typeof(string), typeof(SendPlurkMessageActivity));

[DescriptionAttribute("PlurkMessageBody")]

[CategoryAttribute("PlurkMessageBody Category")]

[BrowsableAttribute(true)]

[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]

public string PlurkMessageBody

{

get

{

return ((string)(base.GetValue(SendPlurkMessageActivity.PlurkMessageBodyProperty)));

}

set

{

base.SetValue(SendPlurkMessageActivity.PlurkMessageBodyProperty, value);

}

}

#endregion

protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)

{

try

{

PlurkApi.PlurkApi api = new PlurkApi.PlurkApi();

if (api.Login(PlurkUserName, PlurkPassword))

{

api.addMessage("tr_ch", string.Empty, PlurkMessageBody, true, string.Empty);

//api.

//api.addMessage("tr_ch", string.Empty, "Plurking from WWF C# CustomizedAction. Current Taiwan time is " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(), true, string.Empty);

}

}

catch (Exception ex)

{

}

return ActivityExecutionStatus.Closed;

}

}

}