#Grunt Need: Node.js installed

Install Steps

  1. Installing the CLI run command
1
npm install -g grunt-cli
  1. edit package.json and Gruntfile.js
1
2
3
4
5
6
{
"devDependencies": {
"grunt": "0.4.1",
"grunt-ts": "latest"
}
}

run npm install in command

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module.exports = function (grunt) {
// load the task
grunt.loadNpmTasks('grunt-ts');

// Configure grunt here

grunt.initConfig({
ts: {
dev: {
// a particular target
src: ['app/**/*.ts'], // The source typescript files, http://gruntjs.com/configuring-tasks#files
html: ['app/**/*.html'], // The source html files, https://github.com/basarat/grunt-ts#html-2-typescript-support
reference: './reference.ts', // If specified, generate this file that you can use for your reference management
out: 'app/app.js', // If specified, generate an out.js file which is the merged js file
watch: 'app',
},
},
});
grunt.registerTask('default', ['ts:dev']);
};

run grunt in command

這樣子 grunt 就會監控 在 app 資料夾下的 ts 檔案異動,並同時做 complie 的動作,如果有錯誤,會產生 complie error 的訊息。

In projectname.csproj 新增

 <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptIncludeComments>true</TypeScriptIncludeComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptIncludeComments>false</TypeScriptIncludeComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />

在重新載入專案

#Form Validation with angularJs Basic: in .js $scope.form = {} $scope.form.$valid ==> 判斷form(name=「form」)內的物件是否有驗證有錯誤的物件存在

用法: formName.inputFieldName.property

Unmodified form A boolean property that tells us if the user has modified the form. This is true if the user hasn’t touched the form, and false if they have:

1
formName.inputFieldName.$pristine;

Modified form A boolean property if and only if the user has actually modified the form. This is set regardless of validations on the form:

1
formName.inputFieldName.$dirty

Valid form A boolean property that tells us that the form is valid or not. If the form is currently valid, then this will be true:

1
formName.inputFieldName.$valid

Invalid form A boolean property that tells us that the form is invalid. If the form is currently invalid, then this will be true:

1
formName.inputFieldName.$invalid

The last two properties are particularly useful for showing or hiding DOM elements. They are also very useful when setting a class on a particular form.

Errors Another useful property that AngularJS makes available to us is the $error object. This object contains all of the validations on a particular form and if they are valid or invalid. To get access to this property, use the following syntax:

1
formName.inputfieldName.$error

###Addtional CSS classes ng-valid Is set if the form is valid. ng-invalid Is set if the form is invalid. ng-pristine Is set if the form is pristine. ng-dirty Is set if the form is dirty.

##Input Validation

1
2
3
4
5
6
7
8
9
10
<input
ng-model="{string}"
[name="{string}"]
[required]
[ng-required="{boolean}"]
[ng-minlength="{number}"]
[ng-maxlength="{number}"]
[ng-pattern="{string}"]
[ng-change="{string}"]>
</input>

####可驗證項目(內建) requried ng-minlength ng-maxlength

####$error所對應的項目 formName.inputfieldName.$error.requried formName.inputfieldName.$error.minlength formName.inputfieldName.$error.maxlength

民國103年1月1日起,網際網路電子發票開始限制發票字軌只能使用丁種字軌,然後又推說如果利用網際網路電子發票開立B2B交易情形,只能接受丁種字軌,這表示,另外一方也必須用網際網路電子發票…看來國稅局在103年度要強推B2B的電子發票了。

不管怎樣,這個也是一個趨勢,雖然現在開立的方法或是平台(還得獎…這好笑了吧, 請個F2E處理一下你的頁面吧。還是說設計者都沒有自己操作過)都還很鳥,如果要利用媒體檔上傳的方式,這個門檻又很高,因為那個該死的規格書又寫的很艱澀。(只是要罵一下)…

帳號申請網址:電子發票整合服務平台

還是稍微整理一下開立流程:

一般開立

  1. 賣方開立發票
  2. 買方收到開立通知
  3. 買方接收開立發票
  4. 賣方收到接收通知
  5. 完成開立動作

退回發票

  1. 賣方開立發票
  2. 買方收到通知
  3. 買方退回發票
  4. 賣方確認發票退回
  5. 完成動作

作廢發要

  1. 賣方作廢發票
  2. 買方收到通知
  3. 買方確認發票作廢
  4. 完成動作

B2B交換資料,發票狀態有幾種,其意義為何?

銷項發票狀態 開立 :已新增發票,尚未憑證寄送 已寄送:已憑證寄送,資料傳送中 已讀取:買方已讀取 尚未完成進項發票寄送確認 已確認:買方已完成進項發票寄送確認 進項發票狀態 開立   :賣方已憑證寄送發票,買方尚未讀取 已讀取  :買方已讀取發票,尚未完成進項發票寄送確認 確認寄送中:進項發票寄送確認,資料傳送中 已確認  :買方已完成進項發票寄送確認

買方營業人若無工商憑證是否可接收發票?

請賣方營業人至基本資料/交易對象資料維護建立買方資料並設定交易暗語,買方即可以交易暗語寄送發票。 惟作廢發票及發票退回確認僅能使用憑證接收,不得使用交易暗語接收。

Tuples

很像list,但是一旦建立後值就沒有辦法被更改 (ex. list[1]= 『b』 <=會出錯) 用途: 用來儲存一些常用(const)變數

Set

set會將重複得值給排除掉(有distinct的味道) 建立set的方式有set() 或 a= {『something』,『something』} 如果要建立空的set,只能透過set()的方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a
{'d', 'r', 'a', 'c', 'b'}
>>> b
{'m', 'l', 'a', 'c', 'z'}
>>> a^b # value in a or b not in both, 不含兩邊都有值
{'r', 'z', 'd', 'b', 'm', 'l'}
>>> a-b # value in a not b
{'d', 'b', 'r'}
>>> a|b # value in a or b
{'r', 'z', 'd', 'a', 'c', 'b', 'm', 'l'}
>>> a&b # value in a and b
{'a', 'c'}

#Dictionaries as c# Dictionary<string, string> 操作方式

  • 指定: dict[key]= value
  • 刪除: del dict[key]
  • 列表: list(dict.key())
  • 排序: sorted(dict.key())

建立的方式

1
2
3
4
>>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
{'sape': 4139, 'jack': 4098, 'guido': 4127}
>>> dict(sape=4139, guido=4127, jack=4098)
{'sape': 4139, 'jack': 4098, 'guido': 4127}

##looping

1
2
3
4
5
6
>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}
>>> for k, v in knights.items():
... print(k, v)
...
gallahad the pure
robin the brave

#More on Conditions 比較的方法:

  • in, not in
  • is, is not
  • and, or : 當遇到第一個成立條件時,就跳出了

比較可以連續串接: eg: a<b==c tests whether a is thess then b and moreover b equals c

比較的順序: 左到右

#Data Structures List的控制

x=value i=index position L=list

  • list.append(x) : 在結尾的地方新增一筆資料
  • list.extend(L) : 新增資料by list
  • list.insert(i,x) : 插入資料
  • list.remove(x) : 移除所輸入的x值
  • list.pop([i]) : 移除所指定index position的值;如果沒有指定[i]時,則傳回並移除最後一筆紀錄(後進先出)
  • list.clear() : 清除list
  • list.index(x) : x值的位置, 如果沒有找到則傳回錯誤
  • list.count(x) : x值的數量
  • list.sort() : 排序
  • list.reverse() : 反轉
  • list.copy() : 複製list

後進先出 : list.pop() 先進先出 : deque deque([list])後,在操作pop或append時,多出了popleft(), appendleft(), extendleft()的方法 用法如下

1
2
3
4
5
6
7
8
9
10
11
12
>>>from collections import deque
>>> queue = deque(["Eric", "John", "Michael"])
>>> queue
deque(['Eric', 'John', 'Michael'])
>>> queue.append("Kevin")
deque(['Eric', 'John', 'Michael', 'Kevin'])
>>> queue.appendleft("Steve")
deque(['Steve', 'Eric', 'John', 'Michael', 'Kevin'])
>>> queue.popleft()
'Steve'
>>> queue
deque(['Eric', 'John', 'Michael', 'Kevin'])

#List Comprehensions ##(計算x) for x in list if condition

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
>>> [x**2 for x in range(10)]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

>>> [x**2 for x in range(10) if x%2==0]
[0, 4, 16, 36, 64]

>>> [(x, y) for x in [1,2,3] for y in [3,1,4] if x != y]
[(1, 3), (1, 4), (2, 3), (2, 1), (2, 4), (3, 1), (3, 4)]

>>> matrix = [
... [1, 2, 3, 4],
... [5, 6, 7, 8],
... [9, 10, 11, 12],
... ]

>>> [[row[i] for row in matrix] for i in range(4)]
[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]

>>> list(zip(*matrix))
[(1, 5, 9), (2, 6, 10), (3, 7, 11), (4, 8, 12)]

#del 移除list中的值by Index

1
2
3
4
5
6
7
8
9
10
>>> a = [-1, 1, 66.25, 333, 333, 1234.5]
>>> del a[0]
>>> a
[1, 66.25, 333, 333, 1234.5]
>>> del a[2:4]
>>> a
[1, 66.25, 1234.5]
>>> del a[:]
>>> a
[]

del can also be used to delete entire variables: 變數消滅

1
2
3
4
5
6
>>> a = [-1, 1, 66.25, 333, 333, 1234.5]
>>> del a
>>> a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined

#demo program

1
2
3
4
5
6
a,b=0,1     # 指定值至變數中
while b<10: # 迴圈
... print(b, end=',') # 顯示文字,結尾加上,
... a,b=b,a+b # 指定值至變數中

1,1,2,3,5,8, # 輸出結果

#Control Flow Tools

if

1
2
3
4
5
6
if x<0:
something something
elif condition:
something something
else:
something something

for

1
2
3
4
5
6
7
words=['cat','window','defenestrate']
for w in words:
print(w,len(w))

cat 3
window 6
defenestrate 12
1
2
3
4
5
6
>>> for w in words[:]:  # Loop over a slice copy of the entire list.
... if len(w) > 6:
... words.insert(0, w) # 將值插入至list中
...
>>> words
['defenestrate', 'cat', 'window', 'defenestrate']

range()

range()主要的目的是要創造一個連續值的list, 例如 range(10)=[0,1,2,3,4,5,6,8,9]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
>>> for i in range(5): # range(5) = range(0,5)
... print(i)
...
0
1
2
3
4

>>> for i in range(5,9):
... print(i)
...
5
6
7
8

>>> for i in range(0,10,2): # = for(i=0;i<10;i=i+2) step 2
... print(i)
...
0
2
4
6
8

# 使用在文字陣列上
>>> a = ['Mary', 'had', 'a', 'little', 'lamb']
>>> for i in range(len(a)):
... print(i,a[i])
...
0 Mary
1 had
2 a
3 little
4 lamb

break, continue, else in Loops

1
2
3
4
5
6
7
for n in range(2,10):
for x in range(2,n):
if n%x ==0:
print(n, 'equals', x, '*', n//x)
break
else:
print(n, 'is a prime number')

else: 是對應到 for x in range(2,n): 意義: a try statement’s else clause runs when no exception occurs

#python coding style

  1. Use 4-space indentation, and no tabs.

    4 spaces are a good compromise between small indentation (allows greater nesting depth) and large indentation (easier to read). Tabs introduce confusion, and are best left out.

  2. Wrap lines so that they don’t exceed 79 characters.

    This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.

  3. Use blank lines to separate functions and classes, and larger blocks of code inside functions.

  4. When possible, put comments on a line of their own.

  5. Use docstrings. 「」" something something something 「」" 可以被呼叫by function.doc

  6. Use spaces around operators and after commas, but not directly inside bracketing constructs: a = f(1, 2) + g(3, 4).

  7. Name your classes and functions consistently; the convention is to use CamelCase for classes and lower_case_with_underscores for functions and methods. Always use self as the name for the first method argument (see A First Look at Classes for more on classes and methods).

  8. Don’t use fancy encodings if your code is meant to be used in international environments. Python’s default, UTF-8, or even plain ASCII work best in any case.

  9. Likewise, don’t use non-ASCII characters in identifiers if there is only the slightest chance people speaking a different language will read or maintain the code.

#String

string可以用 『』 or 「」 在 '『裡面可以用", 在"" 裡面可以用』

string連結的方式 + or 空白

但是如果是要連結變數和文字,則需要使用 +。數字和文字不可以做連接。

string[x] 可以直接將文字轉成陣列, 然後直接讀取

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
>>> word = 'Python'
>>> word[0] # character in position 0
'P'
>>> word[5] # character in position 5
'n'
>>> word[-1] # last character
'n'
>>> word[-2] # second-last character
'o'
>>> word[-6]
'P'
>>> word[0:2] # characters from position 0 (included) to 2 (excluded)
'Py'
>>> word[2:5] # characters from position 2 (included) to 5 (excluded)
'tho'
>>> word[:2] + word[2:]
'Python'
>>> word[:4] + word[4:]
'Python'
>>> word[:2] # character from the beginning to position 2 (excluded)
'Py'
>>> word[4:] # characters from position 4 (included) to the end
'on'
>>> word[-2:] # characters from the second-last (included) to the end
'on'
>>> word[::-1] # reverse a string
'nohtyp'
>>> len(word) # length of a string
6

+---+---+---+---+---+---+
| P | y | t | h | o | n |
+---+---+---+---+---+---+
0 1 2 3 4 5 6
-6 -5 -4 -3 -2 -1

輸出文字:

  1. v2.7 : print 『xxxxx』
  2. v3.3 : print(『xxxx』)

文字重複顯示

1
2
>>> 'something'*3
'somethingsomethingsomething'

#Number 計算方式: 先乘除後加減,有內算到外,有左到右

number分interger and float, 區分方法是有沒有使用小數點

+ - * : 加,減,乘

除有兩個方法:

  1. / : 傳回 float
  2. //: 傳回 integer

% : 傳回餘數 ** : 次方

1
2
3
4
5
6
7
8
>>> 7/4
1.75
>>> 7//4
1
>>> 7%4
3
>>> 2**10
1024

a = b: 將b值指定給a

在interactive mode,可以利用 _ 取得上次的值

1
2
3
4
>>> 1+2
3
>>> 1+_
4

Lists

1
2
3
4
5
6
7
>>> squares = [1, 2, 4, 9, 16, 25]
>>> squares
[1, 2, 4, 9, 16, 25]
>>> squares[1]
2
>>> squares[-1]
25

基本操作可以參考string的部分,一樣可以使用 + 做lists的連結

1
list.append(value) # add value to the list

二維陣列

1
2
3
4
5
6
7
8
9
>>> a = ['a', 'b', 'c']
>>> n = [1, 2, 3]
>>> x = [a, n]
>>> x
[['a', 'b', 'c'], [1, 2, 3]]
>>> x[0]
['a', 'b', 'c']
>>> x[0][1]
'b'

因為Visual Studio 2013可以用來寫python, 所以決定開始來學習python看看。看這個語言能帶給我怎樣的驚喜