Total Pageviews

2014/03/31

How to set Static IP Address from command line

Requirement
Owing I need to move workplace from office to customer site lately, I need to change my laptop's IP address as I change workplace. So I edit a batch file to set my static IP address automatically.

Syntax
Let’s say I want to give my Windows 7 system an IP address of 10.144.38.195, a subnet mask of 255.255.255.0, a default gateway of 10.144.38.254. Type the following command and save as a batch file with encoding with ANSI
 netsh interface ipv4 set address name="區域連線" source=static address=10.144.38.195 mask=255.255.255.0 gateway=10.144.38.254  

The address will be found via netsh interface ipv4 show interfaces command.
Idx   Met     MTU     狀態         名稱  
 --- ---------- ---------- ------------ ---------------------------  
  1     50 4294967295 connected   Loopback Pseudo-Interface 1  
  13     50    1500 disconnected 無線網路連線  
  12      1    1500 disconnected 區域連線  
  19     30    1500 disconnected 區域連線 2  
  16     40    1500 disconnected Bluetooth 網路連線  
  20     20    1500 connected   區域連線 3  

In this case, I would like to configure 區域連線. So the address name="區域連線"

Step by step
Step1. open command prompt.
Step2. execute the batch script file, i.e.SetIP4Office.bat
 C:\Users\albert\Desktop>SetIP4Office.bat  
 C:\Users\albert\Desktop>netsh interface ipv4 set address name="區域連線" source=static address=10.14  
 4.38.195 mask=255.255.255.0 gateway=10.144.38.254  

Well Done!

So you can edit different batch files to set different IP address for different workplace.

Reference
[1] http://www.windowsreference.com/networking/how-to-set-staticdhcp-ip-address-from-command-line/

Bat(Batch) script 執行出現出現中文亂碼問題

Problem
I edit a batch script which be used to set IP address
netsh interface ipv4 set address name="區域連線" source=static address=10.144.38.195 mask=255.255.255.0 gateway=10.144.38.254 

But when I execute this batch script in command prompt, it seems that the Traditional Chinese characters are broken.
C:\Users\albert\Desktop>netsh interface ipv4 set address name="?€?€??" source=static address=10.14  
 4.38.195 mask=255.255.255.0 gateway=10.144.38.254  
 檔案名稱、目錄名稱或磁碟區標籤語法錯誤。  

Solution
This problem results from the encoding of the batch script file. You need to change its encoding from UTF-8 to ANSI.

Reference
[1] http://www.bathome.net/viewthread.php?tid=24088

2014/03/27

投資的最高境界是「不交易」!

這篇文章不錯

[quote 1]「掌握波段,比殺進殺出要賺得多。」

[quote 2]大盤K值從高處滑落到20附近,就開始買,一路往下買,回彈到80以上,就一路往上賣。

[quote 3]「停損」當然是最重要的一招。只要持股跌了10%到15%,就該執行停損,認賠出場。


[quote 4]如果你忘了當初買進的價格,或許你在面對它反彈到相對高價時,你會捨得去賣它。什麼叫「相對高價」?就是技術指標呈現過熱訊號,或是股價來到重要壓力區。

[quote 5]股市還有一句名言:「會買股票不稀奇,會賣股票才是師父。」就算是手上的股票處於獲利狀態,也要懂得「停利」。KD值都來到95以上,這時你若還奢望持股會繼續漲不停,就很可能只是一場「紙上富貴」



http://www.businesstoday.com.tw/article-content-80494-106484?page=1


2014/03/25

How do I insert a record if it does not exist in Oracle?

Requirement
Here has two report items as following:
Each year has its own report items, ex. 102年度--未滿一年之短期融資, 103年度--未滿一年之短期融資, 102年度--公債及賒借收入, 103年度--公債及賒借收入, etc.

This sort of information had been stored in this table.

Our requirement is to generate the two report items automatically next year.

Solution
We can use merge statement to accomplish this requirement.
Step1: Find record(s) in FMS405FA based on our defined search criteria
Step2: Result
2.1: If does not find any record, then insert data into FMS405FA
2.2: If found record(s), then skip it.
MERGE INTO FMS405FA T1 
USING DUAL ON(T1.ACCYR =
     (SELECT TRIM(TO_CHAR(EXTRACT(YEAR FROM SYSDATE)-1911, '000'))  FROM DUAL)
      AND T1.RPT_TYPE='FMS434R'
      AND T1.RPT_NO='0001') 
WHEN NOT MATCHED THEN 
  INSERT(T1.ACCYR, T1.RPT_TYPE, T1.RPT_NO, T1.RPT_NM)
  VALUES(
         (SELECT TRIM(TO_CHAR(EXTRACT(YEAR FROM SYSDATE)-1911, '000'))
          FROM DUAL), 'FMS434R', '0001',

         (SELECT TRIM(TO_CHAR(EXTRACT(YEAR FROM SYSDATE)-1911, '000'))
          FROM DUAL)||'年度--未滿一年之短期融資')


MERGE INTO FMS405FA T1 
USING DUAL 
ON(T1.ACCYR =
   (SELECT TRIM(TO_CHAR(EXTRACT(YEAR FROM SYSDATE)-1911, '000')) FROM DUAL)
   AND T1.RPT_TYPE='FMS434R'
   AND T1.RPT_NO='0002') 
WHEN NOT MATCHED THEN 
  INSERT(T1.ACCYR, T1.RPT_TYPE, T1.RPT_NO, T1.RPT_NM)
  VALUES(
         (SELECT TRIM(TO_CHAR(EXTRACT(YEAR FROM SYSDATE)-1911, '000'))
          FROM DUAL), 'FMS434R', '0002',

         (SELECT TRIM(TO_CHAR(EXTRACT(YEAR FROM SYSDATE)-1911, '000'))
          FROM DUAL)||'年度--公債及賒借收入')

Reference
[1] http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606

2014/03/20

How to create a Boolean field in Oracle

Problem
If we would like to create a field, it will store the information if this datum had create by external system or be added by manual. 
Originally, I would like to crate a field with Boolean data type. But it seems that Oracle does not support Boolean data type.

Solution
We can use the check constraint to limit its value, i.e. 'Y' means adding by manual, 'N' means adding by external system.
ex.
ALTER TABLE FMS435FB ADD CONSTRAINT SELF_ADDED_CHECK CHECK (SELF_ADDED IN ('N',
                                                                           'Y'));


Reference
[1] http://www.techonthenet.com/oracle/check.php

How to set the width of modal dialog

Problem
User claimed they do not want to see the scroll bar in the modal dialog.
How do I set the width of dialog manually?

Solution
We can set the modal dialog thru style.

Step1.  Defined a css style for the modal dialog in the head section of an HTML page, and using the style tag.
 <style type="text/css">  
 .fms435rTab3Dialog {  
   width: 900px;  
   left: 40%;  
 }  
 </style>  

Step2. Assign css into windowClass which is one of modal dialog's parameter
1:  $scope.create = function() {  
2:        openDialog();  
3:      };  
4:      var openDialog = function(){  
5:        var options = {  
6:            templateUrl: 'fms435rTab3Dialog.html',  
7:            controller: 'fms435rTab3Controller',  
8:            windowClass:"fms435rTab3Dialog",  
9:            backdrop: true,  
10:            keyboard: true,  
11:            backdropClick: true  
12:        };  
13:        $modal.open(options);  
14:      };  

See...the width had been adjusted.


Reference

2014/03/13

Error: ng:areq Bad Argument

Problem
I have a html page with 2 tabs.

As I entered this page, it occurred javascript errors with "Error: ng:areq" and link to this page: http://docs.angularjs.org/error/ng/areq?p0=fms435rTab1Controller&p1=not%20a%20function,%20got%20undefined


Trace the Problem
There are three html files to consist of this page. Each html file have its own JavaScript file, and will be imported by mail page.

fms435r.js
 (function() {  
   var app = angular.module("fms435rApp", [ 'ntaCommonModule' ]);  
 })();  

fms435rTab1.js
(function() {  
   var app = angular.module("fms435rApp");  
   app.factory('fms435rService', function(cResource) {  
     return {};  
   });  
   app.controller('fms435rTab1Controller', function($scope, fms435rService,  
       stateManager, alerter, userHolder) {      
   });  
 })(); 

fms435rTab2.js
 (function() {  
   var app = angular.module("fms435rApp", [ 'ntaCommonModule' ]);  
   app.factory('fms435rService', function(cResource) {  
     return {};  
   });  
   app.controller('fms435rTab2Controller', function($scope, fms435rService,  
       stateManager, alerter, userHolder) {  
   });  
 })();  

Root Cause
The problem result from fms435rTab2.js. 
It misuse angular.module, because it create a new module, not to retrieve.
Therefore, you should fix it as bellows:
 (function() {  
   var app = angular.module("fms435rApp");  
   app.factory('fms435rService', function(cResource) {  
     return {};  
   });  
   app.controller('fms435rTab2Controller', function($scope, fms435rService,  
       stateManager, alerter, userHolder) {  
   });  
 })(); 

Here is the syntax
ParamTypeDetails
namestring
The name of the module to create or retrieve.
requires
(optional)
Array.=
If specified then new module is being created.
If unspecified then the module is being retrieved for
further configuration.
configFnFunction
Optional configuration function for the module.
 Same as Module#config().

Reference
[1] http://docs.angularjs.org/api/ng/function/angular.module

2014/03/12

ORACLE/PLSQL: ADD_MONTHS FUNCTION

Requirement
If we would like to do month calculation in SQL, how to do it?

Solution
Oracle provided a build-in ADD_MONTHs function for us, the syntax is as bellow:



For example, if I would like to get last month and in Chinese calendar system format, the SQL statement will be looking like this:


SELECT TRIM(TO_CHAR(EXTRACT(YEAR
                            FROM ADD_MONTHS(SYSDATE, -1))-1911, '000'))|| TRIM(TO_CHAR(EXTRACT(MONTH
                                                                                             FROM ADD_MONTHS(SYSDATE, -1)), '00')) AS LAST_MONTH
FROM DUAL

Reference
[1] http://www.techonthenet.com/oracle/functions/add_months.php
[2] http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions004.htm

2014/03/05

How to resolve ORA-01790

Problem
When I use UNION ALL syntax to union two select SQL statement, Oracle throw "ORA-01790 expression must have same datatype as corresponding expression" error message.

This error result from I would like to union two result with different data type.

Solution
You can make good of CAST function to cast into the same data type and do union all.

For example. 
SELECT CAST(NVL(FMS406FB.DAY_RSLT, 0) AS NVARCHAR2(30)) DAY_RSLT --每日結存數
FROM .....

Reference
[1] http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions016.htm