2017年5月17日

[CrystalReport] Crystal Report 視窗大小設定

使用者提出 Crystal Report視窗太小,看資料不方便,希望能放大
當初開發時雖然也這麼覺得,但是那時 google了相關的資料找不到解決方案,就先放著不管
現在使用者提出來就逃不掉了
但是一樣 google了一整天,都沒有滿意的方案,無法從 Crystal Report的元件或設定等地方做調整
最後索性使用 js直接調整視窗大小
done

(該不會就是因為解決方案太簡單所以網路上都沒人詢問或分享吧  囧)

window.resizeTo(screen.width, screen.height)

2017年3月31日

小工具開發紀錄

紀錄在工作上為了哪些事情個別寫程式去解決或縮短工作時間:
  • 台新 SPTS
    使用 iBatis.NET + log4net以文字檔儲存 sql紀錄,因為是用參數傳入的語法,若要人工剪下貼上參數,數量一多就很費時費力

    => 寫一支 iBatisLogParser,複製 iBatis的 log貼上,自動轉換成參數已經代入好的 sql句,本質上就是字串內容的辨識及取代
    .
  • 台新 SPTS
    開發環境封閉,無法連外網,有時需要看 Json格式但沒排版過的 log會很痛苦

    => 寫一支 JsonPrettyOffline,排版美化 Json格式的 log,易於閱讀
    .
  • 台新 SPTS
    檢查以 xml格式儲存 key/value的 wording,避免 key值重複取錯值

    => 寫一支 MessageListChecks,自動檢查
    .
  • 台新 SPTS
    每天要從 tfs抓取當天的 bug、CR數量等紀錄,並統計各 PG每天完成哪些 bug、CR

    => 寫一支 WorkItemTracer,自動產生統計表格及產生圖表
    .
  • 遠通 eTag Portal

    => 改寫以 vbs開發的壓縮 txt log程式

2017年1月16日

MS SQL專案 產生 script後使用 sqlcmd執行

利用 SQL專案的結構描述比較功能,在比較並產生指令碼後,產出的結果無法直接在 SSMS上直接執行
大概是長這個樣子
/*
TestDB 的部署指令碼

這段程式由工具產生。
...
*/
...
:setvar DatabaseName "TestDB"
:setvar DefaultFilePrefix "TestDB"
...

/* 偵測 SQLCMD 模式,如果不支援 SQLCMD 模式,則停用指令碼執行。
...
*/
...

使用 sqlcmd執行此 script的方式:
開啟 cmd,輸入下方指令後再按 Enter
sqlcmd -S TestDB -U userId -P password -i C:\TestDB_Update.publish.sql -o C:\output.txt

2016年12月5日

[VS] Visual Studio 更新服務參考過久的問題

開發的方案裡面有 FE、AP兩個專案
AP內有 N個 WCF給 FE使用
更新 FE的 Service Reference時會更新很久,甚至看起來跟當機有 87分像

最後找到問題是 FE專案參考的某些 dll會造成此情況 
此次案例的問題點是 FE有參考 DocumentFormat.OpenXml.dll

解決方式可以在設定 Service Reference時取消勾選重複使用所有組件
改成一個一個勾選且避開 DocumentFormal.OpenXml.dll

或是每次更新 Service Reference前先移除參考 DocumentFormal.OpenXml.dll,更新完再加入

2016年10月19日

金額 format string

var result = '0,0.' + Array(decimalPlace + 1).join('0')
result = result.replace(/\.\s*$/, "");
decimalPlace 0: "0,0"
decimalPlace 1: "0,0.0"
decimalPlace 2: "0,0.00"

參考:

Repeat Character N Times

2016年10月13日

懸浮按鈕 & 自動填入表單

懸浮按鈕
<input type="button" value="Import" style="positionL fixed; z-index: 10000; top: 95%; left: 5px;" onclick="$('#importFile').click()" />
<input id="importFile" type="file" style="position: fixed; z-index: 10000l top: -100px; left: -100px;" onchange="Import(this)" />
function Import(fileInput) {
    var reader;
    if(window.File && window.FileReader && window.FileList && window.Blob) {
        reader = new FileReader();
    }
    else {
        return;
    }

    var txtContent;
    if(fileInput.files && fileInput.files[0]) {
        reader.onload = function (e) {
            txtContent = e.target.result;
            console.log(txtContent);

            // Custom Code
            // End of Custom Code
        }
        reader.readAsText(fileInput.files[0]);

        //Reset
        fileInput.value = '';
    }
}

2016年9月10日

VS 專案 檔案異動沒有自動出現在包含的變更(Pending Changes)

前一陣子應客戶需求
獨立負責令一個專案開發
架構要跟原本開發的案子一樣
所以我直接複製整個專案,改名,再做一些加工後就丟上 TFS

但是修改過的檔案都不會自動出現在包含的變更(Pending Changes)清單
讓人困擾

解決方式:
檔案 → 原始檔控制 → 進階 → 變更原始檔控制 → 全選 繫結 → 簽入

2016年7月21日

Bootstrap modal prevent close (datepicker input in modal)

有個功能是 Bootstrap modal內有 datepicker input,還有一個 OK按鈕
如果不是按 OK就把 modal關閉的話,modal中輸入欄位的值要還原
如果是按 OK關閉 modal的話,檢核輸入值,檢核未過則 modal取消關閉

搜尋取消關閉 modal的範例後寫出大致如下的程式:
$('.modal').on('hide.bs.modal', function (e) {
  if (CheckClosedByBtnOK()) {
    if (!ValidInput()) {
      e.preventDefault();
      e.stopImmediatePropagation();
    }
  }
  else {
    ResetInput();
  }
});
但是發現使用 datepicker選完日期並關閉小視窗後也會觸發 hide.bs.modal,導致每次選完值就還原,有選跟沒選一樣

Bootstrap modal的官方文件中有說明 events還有一種 hidden.bs.modal,直接拿來套用,改成
$('.modal').on('hidden.bs.modal', function (e) { ...
現在不會選完值就還原了,也就是 hidden.bs.modal只有在 modal關閉時才會觸發,datepicker關閉時不會
但是另一個問題又來了,preventDefault、stopImmediatePropagation現在無效了

因為英文不好,對 Bootstrap modal官方文件的 Events說明琢磨了一會還是看不懂差異在哪:
hide.bs.modalThis event is fired immediately when the hide instance method has been called.
hidden.bs.modalThis event is fired when the modal has finished being hidden from the user (will wait for CSS transitions to complete).

只好寫程式來觀察:
$('.modal').on('hide.bs.modal', function (e) {
  console.log(this);
  console.log('hide');
}).on('hidden.bs.modal', function (e) {
  console.log(this);
  console.log('hidden');
});
得出 hidden.bs.modal是在 modal被關閉後才觸發,所以 preventDefault當然沒有效果
hide.bs.modal是關閉前觸發,但是 modal內的 datepicker關閉時也會觸發 hide.bs.modal

所以改成先判斷 hide.bs.modal是否為 datepicker被關閉時觸發即可

var isUsingDatepicker = false;

$('.modal').on('show.bs.modal', function (e) {
  isUsingDatepicker = ($(div.datepicker-dropdown).length > 0);
}).on('hide.bs.modal', function (e) {
  if (!isUsingDatepicker) {
    if (CheckClosedByBtnOK()) {
      if (!ValidInput()) {
        e.preventDefault();
        e.stopImmediatePropagation();
      }
    }
    else {
      ResetInput();
    }
  }
  isUsingDatepicker = ($(div.datepicker-dropdown).length > 0);
});

2016年2月1日

提早 Timeout

客戶反應未到四小時就被登出
檢查 Web程式的 web.config
Session Timeout和 Form Auth Timeout都是設定 240(分)
Log紀錄也有正常的 Timeout紀錄

可能是因為 Load Balance的 Sticky Timeout只設 60(分)

2015年11月16日

瑜珈課的體悟

同一個口令/指示 有多少人就有多少不同的動作

需要老師輔助

超越極限

個體能力不同

2015年10月28日

javascript 一個元件用兩個 class註冊同一種事件的觸發順序

<input class="A B" />

$('.A').keyup(function () {
  ...
});

$(document).delegate('.B', 'keyup', function () {
  ...
});

B會比 A先執行

2015年10月23日

開發時各項工具的選擇 要考慮後續維護使用

做台新專案的經驗
PM堅持 UML用 Astah做
但是接手的台新 IT團隊都用 Enterprise Architech

2015年8月7日

OpenXML將內容控制項替換文字

Template的內容控制項後面如果是接換行符號,不可以用 ↓(Shift+Enter),要用←┘(Enter)
不然替代文字後產生出的文件會有格式問題

2015年7月31日

Log4Net 學習紀錄

1.NuGet install log4net
2.Cerate file log4net.config
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
</configuration>
<configuration>
  <!--logger: 記錄器,可自訂設定屬性(可多個)-->
    <!--appender-ref: 指定參考的Appender設定-->
    <logger name="Rolling">
      <appender-ref ref="RollingFile" />
    </logger>
    <logger name="DB">
      <appender-ref ref="LogDatabase" />
    </logger>
</configuration>
<configuration>
  <!--root logger: 根記錄器,當其他記錄器執行完後最後會執行根記錄器(唯一)-->
    <!--level: 記錄級別設定-->
    <root>
      <level value="DEBUG" />
      <appender-ref ref="RollingFile" />
    </root>
</configuration>
For File
<configuration>
  <!--appender: 內容為輸出格式的設定-->
    <!--type: 輸出類型,例如 ConsoleAppender 為主控台輸出、RollingFileAppender 為文字檔輸出-->
    <!--file: 輸出檔案的路徑位置-->
    <!--layout: 記錄的格式設定-->
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
      <file value="C:\Log\PlayLog.txt" />
      <appendToFile value="true" />
      <maximumFileSize value="1000KB" />
      <maxSizeRollBackups value="2" />
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="[Activity]%newlineActivityId: %property{GUID}%newlineTime: %date{yyyy-MM-dd HH:mm:ss}%newlineLevel: %level%newline%newline[System]%newlineSystem: %property{System}%newline%newline[IP]%newlineServerIP: %property{ServerIP}%newlineClientIP: %property{ClientIP}%newline%newline[Message]%newlineDescription: %property{Description}%newlineException: %property{Exception}%newline%newline[Properties]%newline%message%newline%newline" />
      </layout>
    </appender>
</configuration>
For DB
<configuration>
  <appender name="LogDatabase" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="100" />
      <connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089" />
      <connectionString value="Data Source={Server};Initial Catalog={DBName};User ID={UserID};Password={Password}" />
      <commandText value="INSERT INTO [dbo].[Message] (MessageId, Message) VALUES (@MessageId, @Message)" />
      <parameter>
        <parameterName value="@MessageId" />
        <dbType value="Int32" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%property{MessageId}" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value="@Message" />
        <dbType value="String" />
        <size value="100" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%property{Message}" />
        </layout>
      </parameter>
    </appender>
</configuration>
3.Add Watch in Global.asax Application_Start()
log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(Server.MapPath("~/log4net.config")));


儲存GUID
log4net.ThreadContext.Properties["GUID"] = guidValue;

<parameter>
    <parameterName value="@LogId" />
    <dbType value="Guid" />
    <layout type="log4net.Layout.RawPropertyLayout">
        <key value="GUID" />
    </layout>
</parameter>

Trace log4net debug message by modify web.config
<configuration>
  <appSettings>
    <add key="log4net.Internal.Debug" value="true"/>
  </appSettings>
</configuration>
<configuration>
  <system.diagnostics>
    <trace autoflush="true">
      <listeners>
        <add name="textWriterTraceListener"
             type="System.Diagnostics.TextWriterTraceListener"
             initializeData="C:\Log\log4net.txt"
             />
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>