'MS Dev.'에 해당되는 글 24건
- 2009.02.16 VSTO에서 메세지 서브클래싱..
- 2009.02.16 SQL Server 2005 Database Backup and Restore using C# and .NET 2.0
- 2009.02.16 정규식 Regular Expression
- 2009.02.15 [유니코드] 한글 음절과 자모의 영역/주소 - Unicode Hangul Code Point Map
- 2009.02.14 Code 128 Specification
- 2009.02.08 asp.net 2.0 iis 재설치
- 2009.02.08 ASP.NET State Service error 해결 방안
- 2009.02.08 c# 정규 표현식
- 2009.02.08 C# Regular Expressions
- 2009.02.08 유니코드 코드표
VSTO에서 메세지 서브클래싱..

오피스 2007의 '리본X UI'에서 OfficeMenu(좌측 상단의 동그란 MS마크의 메뉴) 의 동작을 runtime 시에 동적으로 disable 시키고 싶었는데 그게 안되더라. 는 것이었다.
애초부터 안되는거 아니냐고? 설마! 그랬으면 내가 이런 일말의 희망을 가지고 이틀동안 인터넷을 떠돌아 다녔을리가 없다.
실제로 다음과 같이 리본 메뉴 스키마를 작성하면 disable 시킬수가 있다.
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
<ribbon>
<officeMenu>
<button idMso="FileNew" enabled ="false"/>
</officeMenu>
<tabs>
<tab idMso="TabAddIns">
<group id="MyGroup"
label="My Group">
<toggleButton id="toy" label="연습" size="large" onAction="OnToggle" imageMso="HappyFace"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
근데.. 왠지 될거 같지 않은가? 왠지 모르게.. 저걸 읽어서 UI에 변화를 줄수 있다면 반대로 변화도 줄수 있을거야. MS가 나보다는 똑똑하니까, 분명히 무슨 함수라던지 속성이라던지가 있을꺼야.. 이러면서 이틀간 인터넷에서 사경을 헤멨(응?)..
근데, 암만 찾아봐도 dynamic하게 변경은 못하는것 같더라. 그래서 또 생각했다. 그러면 저 '리본 메뉴 스키마'를 2개(enable/disable)만들어 둬서 reload하면 될꺼야. 또 뒤졌다... 분명히 뭔가 있기는 있다. 그런데 이해가 안되더라.
.NET 환경에서 작성된 내용도 아닌거 같고..(난 영어가 시러염!!!) 어쨌든 오늘도 그렇게 무료히 시간을 죽이고 있었더니..
invalidate라는 함수가 눈에 띄었다. (사실 어제부터 눈에 거슬렸으나.. 정확한 용법이 없으니 이게 뭘 하는지 모르겠는거라..)
MSDN을 뒤졌다. 오예~ 예제가 있다. 우선 살짝쿵 훑었다. 뭐 별거 없네.. 하고 닫으려는 순간 눈에 밟히는 문장이 있었으니..
[Instead of the Save dialog box appearing, the custom dialog box appears, as shown in Figure 2.]...
disable이 안된다면 내가 원하는대로 돌리면 되지(아놔.. '돼지' 야? '되지' 야?)..!!
그래서 결과 코드는 다음과 같이..
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
<!-- QAT(Quick Access Toolbar) 부분 -->
<commands>
<command idMso="FileSave" onAction="MySave" />
</commands>
<ribbon startFromScratch="false">
<!-- OfficeMenu 부분 -->
<officeMenu>
<button idMso="FileSave" enabled ="true" onAction ="MySave"/>
</officeMenu>
<tabs>
<tab idMso="TabAddIns">
<group id="MyGroup"
label="My Group">
<toggleButton description="this is test" id="toy" label="연습" size="large" onAction="OnToggle" imageMso="HappyFace"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Public Sub MySave(ByVal control As Office.IRibbonControl, ByRef cancelDefault As Boolean)
If (repurposing) Then
System.Windows.Forms.MessageBox.Show("로컬 컴퓨터에 저장할수 없음.")
cancelDefault = True
Else
cancelDefault = False
End If
End Sub
#Region "Smile Toggle Button Action"
Public Sub OnToggle(ByVal control As Office.IRibbonControl, ByVal isPressed As Boolean)
If (isPressed) Then
ReportTaskPane.Visible = True
Else
ReportTaskPane.Visible = False
End If
repurposing = isPressed
ribbon.Invalidate()
End Sub
#End Region
referenced from: http://msdn2.microsoft.com/en-us/library/bb462633.aspx
SQL Server 2005 Database Backup and Restore using C# and .NET 2.0

Introduction
The following article describes accessing a SQL Server 2005 database backup and restoring it programmatically using C#.NET 2.0 and SMO. This article provides coding samples to perform the task.
SQL Server Management Objects (SMO) is a collection of objects that are designed for programming all aspects of managing Microsoft SQL Server.
The following namespaces can be used to access SQL Server 2005 programmatically:
Microsoft.SqlServer.management
Microsoft.SqlServer.Management.NotificationServices
Microsoft.SqlServer.Management.Smo
Microsoft.SqlServer.Management.Smo.Agent
Microsoft.SqlServer.Management.Smo.Broker
Microsoft.SqlServer.Management.Smo.Mail
Microsoft.SqlServer.Management.Smo.RegisteredServers
Microsoft.SqlServer.Management.Smo.Wmi
Microsoft.SqlServer.Management.Trace
Pre-Requisite
You need to reference the following namespaces before using this code:
- Microsoft.SqlServer.Management.Smo;
- Microsoft.SqlServer.Management.Common;
I used these two class to perform the backup and restore operations:
- Microsoft.SqlServer.Management.Smo.Backup
- Microsoft.SqlServer.Management.Smo.Restore
For more information, regarding these two class, check MSDN:
Backup database
public void BackupDatabase(String databaseName, String userName,
String password, String serverName, String destinationPath)
{
Backup sqlBackup = new Backup();
sqlBackup.Action = BackupActionType.Database;
sqlBackup.BackupSetDescription = "ArchiveDataBase:" +
DateTime.Now.ToShortDateString();
sqlBackup.BackupSetName = "Archive";
sqlBackup.Database = databaseName;
BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlBackup.Initialize = true;
sqlBackup.Checksum = true;
sqlBackup.ContinueAfterError = true;
sqlBackup.Devices.Add(deviceItem);
sqlBackup.Incremental = false;
sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;
sqlBackup.FormatMedia = false;
sqlBackup.SqlBackup(sqlServer);
}
Restore Database
public void RestoreDatabase(String databaseName, String filePath,
String serverName, String userName, String password,
String dataFilePath, String logFilePath)
{
Restore sqlRestore = new Restore();
BackupDeviceItem deviceItem = new BackupDeviceItem(filePath, DeviceType.File);
sqlRestore.Devices.Add(deviceItem);
sqlRestore.Database = databaseName;
ServerConnection connection = new ServerConnection(serverName, userName, password);
Server sqlServer = new Server(connection);
Database db = sqlServer.Databases[databaseName];
sqlRestore.Action = RestoreActionType.Database;
String dataFileLocation = dataFilePath + databaseName + ".mdf";
String logFileLocation = logFilePath + databaseName + "_Log.ldf";
db = sqlServer.Databases[databaseName];
RelocateFile rf = new RelocateFile(databaseName, dataFileLocation);
sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName, dataFileLocation));
sqlRestore.RelocateFiles.Add(new RelocateFile(databaseName+"_log", logFileLocation));
sqlRestore.ReplaceDatabase = true;
sqlRestore.Complete += new ServerMessageEventHandler(sqlRestore_Complete);
sqlRestore.PercentCompleteNotification = 10;
sqlRestore.PercentComplete +=
new PercentCompleteEventHandler(sqlRestore_PercentComplete);
sqlRestore.SqlRestore(sqlServer);
db = sqlServer.Databases[databaseName];
db.SetOnline();
sqlServer.Refresh();
}
The portion of code uses full backup features. If you want, you can perform incremental and differential backup as well.
Updates: June 8, 2008
In order to use this code, your SQL Server authentication mode needs to be
configured as Mixed Mode authentication. If you use Windows Authentication, then
you need to modify the ServerConnection
:
SqlConnection sqlCon = new SqlConnection ("Data Source=Bappi; Integrated Security=True;");
ServerConnection connection = new ServerConnection(sqlCon);
Modify the ServerConnection
portion of both code samples using
this code in order to use Windows Security.
Conclusion
As this code uses the SQL Server 2005 backup/restore facility, the code follows the rules of SQL Server 2005 while backing up or restoring databases.
(1) ^ (caret) : 라인의 처음이나 문자열의 처음을 표시
예 : ^aaa (문자열의 처음에 aaa를 포함하면 참, 그렇지 않으면 거짓)
(2) $ (dollar) : 라인의 끝이나 문자열의 끝을 표시
예 : aaa$ (문자열의 끝에 aaa를 포함하면 참, 그렇지 않으면 거짓)
(3) . (period) : 임의의 한 문자를 표시
예 : ^a.c (문자열의 처음에 abc, adc, aZc 등은 참, aa 는 거짓)
a..b$ (문자열의 끝에 aaab, abbb, azzb 등을 포함하면 참)
(4) [] (bracket) : 문자의 집합이나 범위를 나타냄, 두 문자 사이의 "-"는 범위를 나타냄
[]내에서 "^"이 선행되면 not을 나타냄
이외에도 "문자클래스"를 포함하는 [:문자클래스:]의 형태가 있다.
여기에서 "문자클래스"에는 alpha, blank, cntrl, digit, graph, lower,
print, space, uppper, xdigit가 있다.
이에 대한 자세한 내용은 C언어의 <ctype.h>를 참조하면 된다.
예를 들어 [:digit:]는 [0-9]와 [:alpha:]는 [A-Za-z]와 동일하다.
이외에 [:<:]와 [:>:]는 어떤 단어(숫자, 알파벳, '_'로 구성됨)의 시작과 끝
을 나타낸다.
예 : [abc] (a, b, c 중 어떤 문자, "[a-c]."과 동일)
[Yy] (Y 또는 y)
[A-Za-z0-9] (모든 알파벳과 숫자)
[-A-Z]. ("-"(hyphen)과 모든 대문자)
[^a-z] (소문자 이외의 문자)
[^0-9] (숫자 이외의 문자)
[[:digit:]] ([0-9]와 동일)
(5) {} (brace) : {} 내의 숫자는 직전의 선행문자가 나타나는 횟수 또는 범위를 나타냄
예 : a{3} ('a'의 3번 반복인 aaa만 해당됨)
a{3,} ('a'가 3번 이상 반복인 aaa, aaaa, aaaa, ... 등을 나타냄)
a{3,5} (aaa, aaaa, aaaaa 만 해당됨)
ab{2,3} (abb와 abbb 만 해당됨)
[0-9]{2} (두 자리 숫자)
doc[7-9]{2} (doc77, doc87, doc97 등이 해당)
[^Zz]{5} (Z와 z를 포함하지 않는 5개의 문자열, abcde, ttttt 등이 해당)
.{3,4}er ('er'앞에 세 개 또는 네 개의 문자를 포함하는 문자열이므로 Peter, mother 등이 해당)
(6) * (asterisk) : "*" 직전의 선행문자가 0번 또는 여러번 나타나는 문자열
예 : ab*c ('b'를 0번 또는 여러번 포함하므로 ac, ackdddd, abc, abbc, abbbbbbbc 등)
* (선행문자가 없는 경우이므로 임의의 문자열 및 공백 문자열도 해당됨)
.* (선행문자가 "."이므로 하나 이상의 문자를 포함하는 문자열, 공백 문자열은 안됨)
ab* ('b'를 0번 또는 여러번 포함하므로 a, accc, abb, abbbbbbb 등)
a* ('a'를 0번 또는 여러번 포함하므로 k, kdd, sdfrrt, a, aaaa, abb, 공백문자열 등)
doc[7-9]* (doc7, doc777, doc778989, doc 등이 해당)
[A-Z].* (대문자로만 이루어진 문자열)
like.* (직전의 선행문자가 '.'이므로 like에 0 또는 하나 이상의 문자가 추가된 문자열이 됨, like, likely, liker, likelihood 등)
(7) + (asterisk) : "+" 직전의 선행문자가 1번 이상 나타나는 문자열
예 : ab+c ('b'를 1번 또는 여러번 포함하므로 abc, abckdddd, abbc, abbbbbbbc 등, ac는 안됨)
ab+ ('b'를 1번 또는 여러번 포함하므로 ab, abccc, abb, abbbbbbb 등)
like.+ (직전의 선행문자가 '.'이므로 like에 하나 이상의 문자가 추가된 문자열이 됨, likely, liker, likelihood 등, 그러나 like는 해당안됨)
[A-Z]+ (대문자로만 이루어진 문자열)
(8) ? (asterisk) : "?" 직전의 선행문자가 0번 또는 1번 나타나는 문자열
예 : ab?c ('b'를 0번 또는 1번 포함하므로 abc, abcd 만 해당됨)
(9) () (parenthesis) : ()는 정규식내에서 패턴을 그룹화 할 때 사용
(10) | (bar) : or를 나타냄
예 : a|b|c (a, b, c 중 하나, 즉 [a-c]와 동일함)
yes|Yes (yes나 Yes 중 하나, [yY]es와 동일함)
korea|japan|chinese (korea, japan, chinese 중 하나)
(11) \ (backslash) : 위에서 사용된 특수 문자들을 정규식내에서 문자를 취급하고 싶을 때 '\'를 선행시켜서 사용하면됨
예 : filename\.ext ("filename.ext"를 나타냄)
[\?\[\\\]] ('?', '[', '\', ']' 중 하나)
정규식에서는 위에서 언급한 특수 문자를 제외한 나머지 문자들은 일반 문자로 취급함
정규식은 Unix의 대표적인 유틸리티인 vi, emacs, ed, sed, awk, grep, egrep 등에서 사용할 수 있다. 다음은 grep에서 정규식을 활용한 예를 보여 주고 있다.
(1) $ 명령어 | grep '정규식'
<= 명령어의 결과를 grep이 입력받아 정규식을 이용하여 패턴을 찾아냄
예 : $ who | grep 'hgkim' <= hgkim이라는 사용자가 login 해 있는지를 알아봄
$ ls -al | grep '^d.*' <= ls -al 의 결과 'd'로 시작하는 라인(즉 디렉토리들)
만을 출력
$ ls -al | grep '^d.*' <= ls -al 의 결과 'd'로 시작하는 라인(즉 디렉토리들)
만을 출력
$ ls -al | grep '^[^d]..x..x..x' <= 디렉토리는 제외하고("[^d]") 누구나
실행가능한 파일("..x..x..x")들 찾기
(2) $ grep '정규식' 파일이름
<= 파일을 입력받아 정규식을 이용하여 패턴을 찻아냄
예: $ grep 'telnet' /etc/inetd.conf
이외의 명령어들도 grep과 유사한 형태로 이용된다. 따라서 정규식을 잘 이용하면 유닉스의 활용이 배가 될 것이다.
PHP에서는 정규식과 관련하여 다음의 네가지 함수를 제공한다.
int ereg(string givenPattern, string givenString, array matched);
- givenString을 "string1stringAstring2stringBstring3 ... string9stringI" 로 주어져 있다고 하자. 이때 stringA, stringB, ... , stringI는 NULL 이어도 상관이 없다(즉 givenString은 "string1string2string3 ... string9" 인 경우임).
- givenString이 위와 같이 주어진 경우,
givenPattern은 "(pattern1)stringA(pattern2)stringB(pattern3) ... (pattern9)stringI"로 입력하여야 한다. 즉 pattern1, pattern2, ..., pattern9는 각각 string1, string2, ... , string9에서 찾고자하는 정규식인 것이다.
- 이때 pattern1이 string1에서 발견한 패턴은 $matched[1]에 저장되고, pattern2가 string2에서 발견한 패턴은 $matched[2]에 저장되고, ..., pattern9가 string9에서 발견한 패턴은 $matched[9]에 저장된다. PHP3의 경우 ereg에서는 최대 9개 까지의 pattern을 찾을 수 있도록 설정되어 있음에 유의하자.
- 그리고 $matched[0]에는 $matched[1]stringA$matched[2]stringB ... $matched[9]stringI가 저장된다.
- ereg가 반환하는 값은 $matched[0]에 저장된 문자열의 개수이다.
- ereg는 case sensitive
- eregi는 case insensitive
예1 :
코드 => print(ereg ("(.*)ef([abc].*)","abcdefabc",$matched));
print("<br>");
while (list($a,$b)=each($matched))
if ($b)
print("$a, $b <br>");
결과 => 9
0, abcdefabc
1, abcd
2, abc
예2 :
코드 => print(ereg ("(.*)d(.*)e(.*)qrs(.*)","abcdefghijklmnopqrstuvwxyz",$matched));
print("<br>");
while (list($a,$b)=each($matched))
if ($b)
print("$a, $b <br>");
결과 => 26
0, abcdefghijklmnopqrstuvwxyz
1, abc
3, fghijklmnop
4, tuvwxyz
예 3 :
코드 => $date="1999-11-17";
if (ereg("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs))
print("$regs[3].$regs[2].$regs[1]");
else print("Invalid date format: $date");
결과 => 17.11.1999
예 4 :
코드 => $joomin="711011-1234567";
if (ereg("([0-9]{2})([01]{1}[09]{1}[0-3]{1}[0-9]{1})-([12]{1}[0-9]{6})",$date, $regs))
print("Valid");
else print("Invalid format: $joomin");
int eregi(string givenPattern, string givenString, array matched);
- ereg의 'case insensitive' 버젼
예 :
코드 => $email="xs9_tx-abc.yyy_c@cne.kyungsung.ac.kr";
eregi("(^[_\.0-9a-z-]+)@(([0-9a-z][0-9a-z-]+\.)+)([a-z]{2,3}$)",$email,$matched);
while (list($a,$b)=each($matched))
if ($b) print("$a, $b <br>");
결과 => 0, xs9_tx-abc.yyy_c@cne.kyungsung.ac.kr
1, xs9_tx-abc.yyy_c
2, cne.kyungsung.ac.
3, ac.
4, kr
코드 => eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$email,$matched);
while (list($a,$b)=each($matched))
if ($b) print("$a, $b <br>");
결과 => 0, xs9_tx-abc.yyy_c@cne.kyungsung.ac.kr
1, ac.
string ereg_replace(string givenPattern, string replacementPattern, string givenString);
- givenString에서 givenPattern에 부합하는 텍스트(matched text)를 찾아서,
replacementPattern으로 대체
- givenPattern이 "(패턴)"으로 묶인 문자열들을 포함하고 있으면, replacementPattern에는 이에 대응하는 "\\digit(문자열)" 형태의 문자열들을 포함하고 있어야 한다(digit는 0, 1, ... ,9 중 하나). 그리고 givenString은 "(패턴)"을 이용해 찾은 결과들을 "\\digit(문자열)"에 있는 "문자열"들로 대체하게 된다. "\\0" 는 givenString 전체에 대해 "(패턴)"의 결과를 적용할 때 이용된다.
- 변경된 문자열을 리턴
- case sensitive
예 :
코드 => $string = "This is a test";
print(ereg_replace(" is", " was",$string)); print("<br>");
print(ereg_replace("( )is","\\1was",$string)); print("<br>");
print(ereg_replace("(( )is)","\\2was",$string)); print("<br>");
print(ereg_replace("(( )is)(( )a)(( )test)", "\\1was\\2an\\3exam",$string));
결과 => "This was a test";
"This was a test";
"This was a test";
"This was an exam";
예 2 : redundant whitespace 없애기
코드 => $str ="~ s/\s+/ /g";
$str = eregi_replace("[[:space:]]+", " ", $str);
print("$str<br>");
결과 => ~ s/\s+/ /g
string eregi_replace(string givenPattern, string replacementPattern, string givenString);
- ereg_replace의 'case insensitive' 버젼
[펌] http://phpschool.com/bbs2/inc_view.html?id=11581&code=tnt2
[유니코드] 한글 음절과 자모의 영역/주소 - Unicode Hangul Code Point Map

한글 자모 (Hangul Jamo)
한글 초성 ㄱ: 1100
~
한글 종성, 여린히읗:11F9
※ 여린히읗(된이응)은, "ㅎ"에서 맨 위의 점이 없는 것입니다. 즉, 수평선 밑에 동그라미 하나가 있는 모양입니다.
* 한글 호환 자모 (Hangul Compatibility Jamo)
ㄱ: 3131
~
아래아 이: 318E
※ "아래아 이"는 현대 한글의 "이"와 같지만, 이응 대신에 아래아가 있습니다. 즉, 동그라미 대신에 점이 한 개 찍혀 있습니다.
※ 키보드로 한글 자모(ㄱㄴㄷㄹ, ㅏㅑㅓㅕ)를 입력할 때 이 영역이 사용됩니다.
* 한글 음절 (Hangul Syllables)
가: AC00
~
힣: D7A3
※ 가장 중요한 한글 영역입니다. 현대 한글 낱자 11172자가 모두 들어 있습니다.
한글 반각 자모 (Halfwidth Jamo / Halfwidth Hangul variants)
(반각) ㄱ: FFA1
~
(반각) ㅣ: FFDC
※ 위의, "ㅣ" 는, 숫자1이나, 알파벳l이 아니라, 한글 모음 "이"입니다.
※ 이 부분은 쓰이지 않는 것 같습니다.
유니코드에 한글 자모들이 중복되어 있는데, 실제로 사용되는 것은 "한글 호환 자모 (Hangul Compatibility Jamo)"였습니다. uniview.pl 유틸리티로, 실제 한글 자모들의 코드 포인트를 알아본 결과입니다:
3131:ㄱ
3134:ㄴ
3137:ㄷ
3139:ㄹ
3141:ㅁ
3142:ㅂ
3145:ㅅ
3147:ㅇ
3148:ㅈ
314A:ㅊ
314B:ㅋ
314C:ㅌ
314D:ㅍ
314E:ㅎ
314F:ㅏ
3151:ㅑ
3153:ㅓ
3155:ㅕ
3157:ㅗ
315B:ㅛ
315C:ㅜ
3160:ㅠ
3161:ㅡ
3163:ㅣ
AC00:가
D7A3:힣
Code 128 Specification
CODE 128 allows the full ASCII 128 character set to be encoded. By using 4 different bar and space widths it achieves a more compact symbol than would be possible using the older binary (Two bar/space widths) barcode symbologies.
Code 128 may be scanned bidirectionally and there is no restriction on the number of characters allowed in each symbol. There will however be a practical limit determined by the physical size of the resulting barcode and the scanning equipment.
Code 128 has three different character sets defined in the table below as Code Set A, Code Set B and Code Set C. Any of these codes may be selected by appropriate selection of start character. Special 'shift' characters in each Code Set enable an alternative Code Set to be substituted during the scanning process. In this way the physical size of symbol may be minimised by pseudo intelligent algorithms in printing software like Barcode Mill. If the data consists only of numeric data then Code Set C provides twice the packing density of Code Sets A and B. Each code set has one or more characters reserved for special functions.
The Code 128 Specification requires the inclusion of a check digit. The barcode symbol structure consists of...
- A quiet zone, or white space to the left of the bars
- Start character
- A variable number of data characters
- Check digit
- Stop character
- A quiet zone or white space to the right of the bars
The quiet zone should be at least ten times the width of the narrowest bar/space element.
Each character in the barcode symbol is composed of three bars and three spaces. (The stop character has four bars and three spaces as the final symbol will always have a final (extra) bar.)
Each bar or space can be one of four different unit widths. The narrowest possible bar or space will thus be one quarter the width of the widest. The table holds the bar/space widths for all the Code 128 character set. Notice that the sum of the barwidths in any character is always even, and the sum of the space widths is odd. The first column in the table,'The Value', is the value used to calculate the check digit.
The Code 128 specification allows for Human readable information to be printed anywhere outside of the symbol area.
Check Digit Calculation
The check digit is a Modulus 103 checksum. It is calculated by summing the start code 'value' to the products of each character's 'value' multiplied by its position in the barcode string. The left most character is position 1. The sum of the start code value and the products is divided by 103. The remainder is the check digits 'value'. Our Barcode Mill software calculates the check digit for you.
Example... To calculate the check digit for the barcode data string 'Code 128'
Value Total ===== ===== Start Code B 104 104 Position 1 C 35 1 x 35 = 35 Position 2 o 79 2 x 79 = 158 Position 3 d 68 3 x 68 = 204 Position 4 e 69 4 x 69 = 276 Position 5 0 5 x 0 = 0 Position 6 1 17 6 x 17 = 102 Position 7 2 18 7 x 18 = 126 Position 8 8 24 8 x 24 = 192 ===== 1197 ===== 1197/103 = 11 remainder 64 The check digit is the character from the table with value 64
Code 128 Barcode Table
Value | Code Set A | Code Set B | Code Set C | Bar/Space Pattern B S B S B S |
---|---|---|---|---|
0 | SP | SP | 00 | 2 1 2 2 2 2 |
1 | ! | ! | 01 | 2 2 2 1 2 2 |
2 | " | " | 02 | 2 2 2 2 2 1 |
3 | # | # | 03 | 1 2 1 2 2 3 |
4 | $ | $ | 04 | 1 2 1 3 2 2 |
5 | % | % | 05 | 1 3 1 2 2 2 |
6 | & | & | 06 | 1 2 2 2 1 3 |
7 | ' | ' | 07 | 1 2 2 3 1 2 |
8 | ( | ( | 08 | 1 3 2 2 1 2 |
9 | ) | ) | 09 | 2 2 1 2 1 3 |
10 | * | * | 10 | 2 2 1 3 1 2 |
11 | + | + | 11 | 2 3 1 2 1 2 |
12 | , | , | 12 | 1 1 2 2 3 2 |
13 | - | - | 13 | 1 2 2 1 3 2 |
14 | . | . | 14 | 1 2 2 2 3 1 |
15 | / | / | 15 | 1 1 3 2 2 2 |
16 | 0 | 0 | 16 | 1 2 3 1 2 2 |
17 | 1 | 1 | 17 | 1 2 3 2 2 1 |
18 | 2 | 2 | 18 | 2 2 3 2 1 1 |
19 | 3 | 3 | 19 | 2 2 1 1 3 2 |
20 | 4 | 4 | 20 | 2 2 1 2 3 1 |
21 | 5 | 5 | 21 | 2 1 3 2 1 2 |
22 | 6 | 6 | 22 | 2 2 3 1 1 2 |
23 | 7 | 7 | 23 | 3 1 2 1 3 1 |
24 | 8 | 8 | 24 | 3 1 1 2 2 2 |
25 | 9 | 9 | 25 | 3 2 1 1 2 2 |
26 | : | : | 26 | 3 2 1 2 2 1 |
27 | ; | ; | 27 | 3 1 2 2 1 2 |
28 | < | < | 28 | 3 2 2 1 1 2 |
29 | = | = | 29 | 3 2 2 2 1 1 |
30 | > | > | 30 | 2 1 2 1 2 3 |
31 | ? | ? | 31 | 2 1 2 3 2 1 |
32 | @ | @ | 32 | 2 3 2 1 2 1 |
33 | A | A | 33 | 1 1 1 3 2 3 |
34 | B | B | 34 | 1 3 1 1 2 3 |
35 | C | C | 35 | 1 3 1 3 2 1 |
36 | D | D | 36 | 1 1 2 3 1 3 |
37 | E | E | 37 | 1 3 2 1 1 3 |
38 | F | F | 38 | 1 3 2 3 1 1 |
39 | G | G | 39 | 2 1 1 3 1 3 |
40 | H | H | 40 | 2 3 1 1 1 3 |
41 | I | I | 41 | 2 3 1 3 1 1 |
42 | J | J | 42 | 1 1 2 1 3 3 |
43 | K | K | 43 | 1 1 2 3 3 1 |
44 | L | L | 44 | 1 3 2 1 3 1 |
45 | M | M | 45 | 1 1 3 1 2 3 |
46 | N | N | 46 | 1 1 3 3 2 1 |
47 | O | O | 47 | 1 3 3 1 2 1 |
48 | P | P | 48 | 3 1 3 1 2 1 |
49 | Q | Q | 49 | 2 1 1 3 3 1 |
50 | R | R | 50 | 2 3 1 1 3 1 |
51 | S | S | 51 | 2 1 3 1 1 3 |
52 | T | T | 52 | 2 1 3 3 1 1 |
53 | U | U | 53 | 2 1 3 1 3 1 |
54 | V | V | 54 | 3 1 1 1 2 3 |
55 | W | W | 55 | 3 1 1 3 2 1 |
56 | X | X | 56 | 3 3 1 1 2 1 |
57 | Y | Y | 57 | 3 1 2 1 1 3 |
58 | Z | Z | 58 | 3 1 2 3 1 1 |
59 | [ | [ | 59 | 3 3 2 1 1 1 |
60 | \ | \ | 60 | 3 1 4 1 1 1 |
61 | ] | ] | 61 | 2 2 1 4 1 1 |
62 | ^ | ^ | 62 | 4 3 1 1 1 1 |
63 | _ | _ | 63 | 1 1 1 2 2 4 |
64 | NUL | ` | 64 | 1 1 1 4 2 2 |
65 | SOH | a | 65 | 1 2 1 1 2 4 |
66 | STX | b | 66 | 1 2 1 4 2 1 |
67 | ETX | c | 67 | 1 4 1 1 2 2 |
68 | EOT | d | 68 | 1 4 1 2 2 1 |
69 | ENQ | e | 69 | 1 1 2 2 1 4 |
70 | ACK | f | 70 | 1 1 2 4 1 2 |
71 | BEL | g | 71 | 1 2 2 1 1 4 |
72 | BS | h | 72 | 1 2 2 4 1 1 |
73 | HT | i | 73 | 1 4 2 1 1 2 |
74 | LF | j | 74 | 1 4 2 2 1 1 |
75 | VT | k | 75 | 2 4 1 2 1 1 |
76 | FF | I | 76 | 2 2 1 1 1 4 |
77 | CR | m | 77 | 4 1 3 1 1 1 |
78 | SO | n | 78 | 2 4 1 1 1 2 |
79 | SI | o | 79 | 1 3 4 1 1 1 |
80 | DLE | p | 80 | 1 1 1 2 4 2 |
81 | DC1 | q | 81 | 1 2 1 1 4 2 |
82 | DC2 | r | 82 | 1 2 1 2 4 1 |
83 | DC3 | s | 83 | 1 1 4 2 1 2 |
84 | DC4 | t | 84 | 1 2 4 1 1 2 |
85 | NAK | u | 85 | 1 2 4 2 1 1 |
86 | SYN | v | 86 | 4 1 1 2 1 2 |
87 | ETB | w | 87 | 4 2 1 1 1 2 |
88 | CAN | x | 88 | 4 2 1 2 1 1 |
89 | EM | y | 89 | 2 1 2 1 4 1 |
90 | SUB | z | 90 | 2 1 4 1 2 1 |
91 | ESC | { | 91 | 4 1 2 1 2 1 |
92 | FS | | | 92 | 1 1 1 1 4 3 |
93 | GS | } | 93 | 1 1 1 3 4 1 |
94 | RS | ~ | 94 | 1 3 1 1 4 1 |
95 | US | DEL | 95 | 1 1 4 1 1 3 |
96 | FNC 3 | FNC 3 | 96 | 1 1 4 3 1 1 |
97 | FNC 2 | FNC 2 | 97 | 4 1 1 1 1 3 |
98 | SHIFT | SHIFT | 98 | 4 1 1 3 1 1 |
99 | CODE C | CODE C | 99 | 1 1 3 1 4 1 |
100 | CODE B | FNC 4 | CODE B | 1 1 4 1 3 1 |
101 | FNC 4 | CODE A | CODE A | 3 1 1 1 4 1 |
102 | FNC 1 | FNC 1 | FNC 1 | 4 1 1 1 3 1 |
103 | Start A | Start A | Start A | 2 1 1 4 1 2 |
104 | Start B | Start B | Start B | 2 1 1 2 1 4 |
105 | Start C | Start C | Start C | 2 1 1 2 3 2 |
106 | Stop | Stop | Stop | 2 3 3 1 1 1 2 |
웹 사이트 등록 정보에 asp.net 탭이 없고, 웹 서비스 확장에 ASP.NET v2.0.50727 항목이 없는 경우,
아래와 같이 해결하면 된다.
Visual Studio 2008 or 2005 명령 프롬프트를 실행한 후에,
aspnet_regiis -i 를 실행하면 된다.
대충 아래와 같이 서버의 세션 상태에 대한 에러 메시지가 나타나면,
iis가 운영 중인 웹 서버의 관리도구 - 서비스 에서 "ASP.NET State Service" 항목을 시작을 눌러서 서비스 실행 상태로 만들어 준다.
error
'/ECMobileMain' 응용 프로그램에 서버 오류가 있습니다.
|
현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 생성되었습니다. 아래의 예외 스택 추적을 사용하여 예외의 원인 및 위치 정보를 확인할 수 있습니다. |
스택 추적:
|
버전 정보: Microsoft .NET Framework 버전:2.0.50727.3082; ASP.NET 버전:2.0.50727.3082
해결 방안
출처 : http://cutecars.tistory.com/category
정규 표현식은 책으로도 1권 될 정도로 분량도 많고 복잡하기도 하고 나에겐 매우 어렵다..ㅡ,.ㅡ;
그래서 네이년한테 물어봤더니 쫘~~~~악~~ 그것도 한글로 나오는데 읽어도 읽어도 당췌 뭔소린지
알수가 없다...ㅡ,.ㅡ;;;; 고로 거창하게는 아니고 그냥 프로젝트하다가 적용한 사례 정도만 나중에 혹시
사용할일이 있지 않을까해서 정리해논다(사실 정리 안됨..ㅡ,.ㅡ;;)
본인은 C, C++이 주 언어지만(그렇다고 절대로!! 잘하는건 아님) C#코드로 구현했기 때문에
개발자답게(?) 고대로 Copy & Paste와 간단한 설명을 남긴다.
참고로 C#인지 닷넷인지뭔지 몰라도 이놈은 정규식을 완벽히 지원한단다.
using System.Text.RegularExpressions
bool IsVaildStr(string strText)
{
string Pattern = @"^[a-zA-Z0-9가-힣]*$";
return Regex.IsMatch(strText, Pattern);
}
간단히 설명하자면 strText의 문자열이 대-소문자 알파벳, 숫자, 한글인지를 체크하는 정규식이다
유저 계정 만들때 사용한 정규식인데 아이디에 특수문자를 사용할수 없게끔하는 식이다
특이하게 한글이 들어간 이유는 모 포탈 사이트에서는(한게임인가로 기억됨...아님 말고...^^)
한글 계정도 지원한다기에 그냥 넣어봤다
자세한 내용은 아래 설명 참조!
※ 정규식 설명
^
입력의 시작 위치를 의미한다. 여러 줄 모드에서는 줄바꿈 뒤도 의미한다
/^A/
"An A"에서 시작 위치 바로 뒤의 A는 일치하지만 마지막의 A는 일치하지 않는다.
^[a-z]
첫 글자는 반드시 소문자 a-z 사이의 문자를 뜻한다
$
입력의 마지막 위치를 의미한다. 여러 줄 모드에서는 줄바꿈 앞도 의미한다.
/a$/
"Cocoa"에서 마지막에 있는 'a'와 일치한다.
[a-z]$
마지막 글자는 반드시 소문자 a-z사이의 문자를 뜻한다
*
* 앞의 문자가 0번 이상 반복됨을 의미한다.
선택 기호: "|" 기호는 여러 식 중에서 하나를 선택한다.
"abc|adc"는 abc라는 문자열과 adc라는 문자열을 모두 포함한다.
묶기 기호: (와 )로 여러 식을 하나로 묶을 수 있다.
"abc|adc"와 "a(b|d)c"는 같은 의미를 가진다.
[] : [과 ] 사이의 문자 중 하나를 선택한다. "|"를 여러 개 쓴 것과 같은 의미를 가진다.
[abc]d는 ad, bd, cd를 뜻한다. 또한, "-" 기호와 함께 쓰면 문자의 범위를 지정할 수 있다.
[a-z]는 a부터 z까지 중 하나, [1-9]는 1부터 9까지 중의 하나를 뜻한다.
[^] : [^과 ] 사이의 문자를 제외한 나머지 하나를 선택한다.
[^abc]d는 ad, bd, cd는 포함하지 않고 ed, fd 등을 포함한다.
[^a-z]는 알파벳 소문자로 시작하지 않는 모든 문자를 나타낸다.
※ POSIX 문자 그룹(character Classes)
Dos를 사용하던 시절에는 *, !, ?, <>, [] 같은 wildcard 문자를 사용하여 다양한 작업을 했었습니다.
이 방식은 지금도 unix 계열에서는 사랑받는 방식입니다.
그리고 현재도 콘솔에서 프로그램 뒤에 파라미터를 넣는 방식은 널리 사용되고 있습니다.
정규 표현식은 이런 정의된 문자를 사용해서 패턴을 만들고 그 패턴을 이용해서 원하는 문자를 가져오거나 바꾸는 데 사용되는 방식입니다.
C#에서도 이런 정규 표현식을 작업하기 쉽도록 지원해 줍니다. 그럼 정규 표현식을 지원하는 클래스 들을 알아보겠습니다.
일단 정규 표현식 관련 클래스들은 System.Text.RegularExpressions 에 있습니다.
그리고 System.Text.RegularExpressions 에는 Regex 클래스가 존재합니다.
이 Regex 클래스에는 정적 메서드가 여러 개 포합되어 있어서 Regex 개체를 명시적으로 만들지 않고도 정규식을 사용할 수 있습니다.한번 사용한 다음 소멸시킨다는 점에서 정적 메서드를 사용하는 것은 Regex 개체를 만드는 것과 같습니다. Regex 클래스 자체는 스레드로부터 안전하며 읽기 전용으로, 변경할 수 없습니다. 즉, Regex 개체는 모든 스레드에서 만들어질 수 있고 또한 스레드 간에 공유될 수 있으며 관련 메서드는 전역 상태에 전형 영향을 주지 않으면서 모든 스레드에 대해 호출될 수 있습니다. 그러나 Regex 에서 반환하는 Match 및 MatchCollection 과 같은 결과 개체는 단일 스레드에서만 사용해야 합니다.
Regex 클래스에서 자주 사용되는 메서드들은 다음과 같습니다.
l IsMatch(string) - 정규식이 입력 문자열에서 일치하는 항목을 찾을 것인지 여부를 나타냅니다.
l Match(string) - 입력 문자열에 정규식이 있는지 검사하고 정확한 결과를 단일 Match 개체로 반환합니다.
l Matches(string) - Match를 여러 번 호출한 것처럼 입력 문자열에 있는 정규식을 모두 검색하고 성공적인 일치 항목을 모두 반환합니다.
l Replace(pattern, string) - 정규식에 의해 정의된 문자 패턴이 발견되면 지정된 대체 문자열로 모두 바꿉니다.
l Split(string, pattern) - 정규식 일치에 의해 정의된 위치에서 부분 문자열로 이루어진 배열로 입력 문자열을 분할합니다.
이제 간단한 예제들을 보여 드리겠습니다.
언제나 그러하듯 아래 예제들은 제가 msdn 및 기타 사이트 들에서 긁어온 것들을 살짝 변경하였습니다.
IsMatch() 와 Match() 메서드의 사용법을 알수 있는 예제입니다.
(http://msdn.microsoft.com/ko-kr/library/system.text.regularexpressions.regex_members(VS.80).aspx)
using System; using System.Text.RegularExpressions; public class Test { public static void Main() { // 정규 표현식을 정의합니다. Regex rx = new Regex(@"^-?\d+(\.\d{2})?$"); // 입력될 스트링을 정의합니다. string[] tests = { "-42", "19.99", "0.001", "100 USD" }; // 테스트 코드입니다. foreach (string test in tests) { if (rx.IsMatch(test)) Console.WriteLine("{0} is a currency value.", test); else Console.WriteLine("{0} is not a currency value.", test); } Console.ReadLine(); } } |
이번에도 IsMatch() 와 Match() 메서드의 사용법을 알수 있는 예제입니다. (http://www.mikesdotnetting.com/Article.aspx?ArticleID=50)
using System; using System.Text.RegularExpressions; namespace TestCode03 { class Program { static void Main(string[] args) { string input = "A12"; //Regex 개체를 생성하는 예제입니다. //@"[a-z]\d": 알파벳이 나온 후 integer 형이 나옵니다. //RegexOptions.IgnoreCase: 대소문자를 구문하지 않는 옵션입니다. Regex re = new Regex(@"[a-z]\d", RegexOptions.IgnoreCase); Match m = re.Match(input); if (re.IsMatch(input)) { Console.Write(m.Value + "\n"); } Console.Write(re.IsMatch(input) + "\n"); //정정 메소드인 Regex를 생성하지 않는 예제입니다. Match m2 = Regex.Match(input, @"[a-z]\d"); if (Regex.IsMatch(input, @"[a-z]\d")) { Console.Write(m2.Value + "\n"); } Console.Write(Regex.IsMatch(input, @"[a-z]\d") + "\n"); Console.ReadLine(); } } } |
MatchCollection 클래스와 Match 클래스의 사용법을 알수 있는 예제입니다.
(http://msdn.microsoft.com/ko-kr/library/system.text.regularexpressions.regex_members(VS.80).aspx)
using System; using System.Text.RegularExpressions; public class Test { public static void Main() { // 반복을 위한 정규 표현식입니다. Regex rx = new Regex(@"\b(?<word>\w+)\s+(\k<word>)\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); // 입력되는 문자열입니다. string text = "The the quick brown fox fox jumped over the lazy dog dog."; // 일치하는 문자열을 찾습니다. MatchCollection matches = rx.Matches(text); // 표현식과 일치하는 문자열의 갯수를 나타냅니다. Console.WriteLine("{0} matches found.", matches.Count); // 일치한 문자열을 표시합니다. foreach (Match match in matches) { string word = match.Groups["word"].Value; int index = match.Index; Console.WriteLine("{0} repeated at position {1}", word, index); } Console.ReadLine(); } } |
MatchCollection 클래스와 Match 클래스의 사용법을 알수 있는 예제입니다.
(http://www.mikesdotnetting.com/Article.aspx?ArticleID=50)
using System; using System.Text.RegularExpressions; namespace TestCode04 { class Program { static void Main(string[] args) { string input = "A12 B34 C56 D78"; //Regex 개체를 생성합니다. Regex re = new Regex(@"[a-z]\d", RegexOptions.IgnoreCase); MatchCollection mc = re.Matches(input); foreach (Match mt in mc) { Console.Write(mt.ToString() + "\n"); } Console.Write(mc.Count.ToString() + "\n"); //Regex는 정적클래스 이므로 개체를 생성하지 않아도 됩니다. MatchCollection mc2 = Regex.Matches(input, @"[a-z]\d", RegexOptions.IgnoreCase); foreach (Match mt in mc) { Console.Write(mt.ToString() + "\n"); } Console.Write(mc2.Count.ToString() + "\n"); Console.ReadLine(); } } } |
Replace메서드의 사용법을 알수 있는 예제입니다. 알파벳을 “XX”로 변환합니다.
using System; using System.Text.RegularExpressions; namespace TestCode05 { class Program { static void Main(string[] args) { string input = @"A12 B34 C56 D78 E12 F34 G56 H78"; //Regex 개체 생성 Regex re = new Regex(@"[a-z]\d", RegexOptions.IgnoreCase); string newString = re.Replace(input, "XX"); Console.Write(newString); //Regex 개체를생성하지 않아도 됩니다. string newString2 = Regex.Replace(input, @"[A-Z]\d", "XX"); Console.Write(newString2); Console.ReadLine(); } } } |
Split메서드의 사용법을 알수 있는 예제입니다. 알파벳을 “XX”로 변환합니다.
using System; using System.Text.RegularExpressions; namespace TestCode06 { class Program { static void Main(string[] args) { string input = "AB1 DE2 FG3 HI4 JK5 LM6 NO7 PQ8 RS9"; //Regex 개체 생성 Regex re = new Regex(@"\s"); string[] parts = re.Split(input); foreach (string part in parts) { Console.Write(part + "\n"); } //Regex 개체를생성하지 않아도 됩니다. 스페이스를 기준으로 문자열을 분할합니다. string[] parts2 = Regex.Split(input, @"\s"); foreach (string part2 in parts2) { Console.Write(part2 + "\n"); } Console.ReadLine(); } } } |
End.
유니코드도 버전별로 지원하는 문자가 틀리군...
가끔 DB에 저장된 데이터가 브라우저에 표시될 때 표시할 수 없는 경우가 있다.
이 경우에는 해당 클라이언트의 유니코드 버전이 낮아서 그런 것 같다.
해결 방안은 정규식을 이용해서 해당 유니코드를 치환하거나 alert 창을 띄우거나 해야겠다.
상세한 해결 방안은 나중에...
C# .NET에서의 Regular Expression 사용 예제
(Example for Regular Expression with C# .NET)