2010. 5. 3. 17:50
Posted by CoolDragon
2010. 5. 3. 15:48
출처 : http://virtuelvis.com/archives/2004/02/css-ie-only

IE 버전별 CSS 적용하기
<link rel="stylesheet" type="text/css" href="common.css" />

<!--[if IE]>
  <link rel="stylesheet" type="text/css" href="all-ie.css" />
<![endif]-->

<!--[if IE 6]>
  <link rel="stylesheet" type="text/css" href="ie-6.0.css" />
<![endif]-->

<!--[if lt IE 6]>
  <link rel="stylesheet" type="text/css" href="ie-5.0+5.5.css" />
<![endif]-->
<!--[if IE]>
  <style type="text/css">
    @import url(ie-styles.css);
  </style>
<![endif]-->

Posted by CoolDragon
2010. 4. 30. 17:27
솔직히 지네릭은 기존에 있는것만 사용했지
내가 만들어 쓴적은 거의(?) 없는 듯 하다.
잘만하면 정말 괜찮은 녀석인데 ㅋㅋ

생각만 잘하면 확장성 있게 쓸 수 있지 않을까 싶다.
    public static T IIF<T>(bool compare, T a, T b)
    {
        return compare ? a : b;
    }
   (위 샘플은 3항 연산자를 써도 될듯 하지만 말이다...ㅋ)
Posted by CoolDragon
2010. 4. 29. 17:09
어디서나 빠지지 않고 사용되는 페이징

참고 안하고 만들여보려니 절라 빡시단걸 알게 됐다.
이거 잘 만든 소스인지는 잘 모르겠네만.. 내가 만든거니 이거 쓸란다.ㅋㅋ

[결과]


[샘플]
Posted by CoolDragon
2010. 4. 29. 10:07
출처 : http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=18&MAEULNo=8&no=1228&ref=1228
--------------------------------------------------------------------------------------------------

//양력은 음력으로변환 테스트
private void button1_Click(object sender, EventArgs e)
{
    label1.Text =음력변환(2007, 1, 1);
    label2.Text = 음력변환(DateTime.Now);
}

//음력을 양력으로 변환 테스트
private void button2_Click(object sender, EventArgs e)
{
    label2.Text = 양력변환(2006,11,13,false).ToShortDateString();
}

private string 음력변환(DateTime dt)
{
    int n윤월;
    int n음력년, n음력월, n음력일;
    bool b윤달 = false;
    System.Globalization.KoreanLunisolarCalendar 음력 =
new System.Globalization.KoreanLunisolarCalendar();

    n음력년 = 음력.GetYear(dt);
    n음력월 = 음력.GetMonth(dt);
    n음력일 = 음력.GetDayOfMonth(dt);
    if (음력.GetMonthsInYear(n음력년) > 12)             //1년이 12이상이면 윤달이 있음..
    {
b윤달 = 음력.IsLeapMonth(n음력년, n음력월);     //윤월인지
n윤월 = 음력.GetLeapMonth(n음력년);             //년도의 윤달이 몇월인지?
if (n음력월 >= n윤월)                           //달이 윤월보다 같거나 크면 -1을 함 즉 윤8은->9 이기때문
   n음력월--;
    }
    return n음력년.ToString() + "-" + (b윤달 ? "*" : "") + n음력월.ToString() + "-" + n음력일.ToString();
}

private string 음력변환(int n양력년, int n양력월, int n양력일)
{
    DateTime dTemp = new DateTime(n양력년, n양력월, n양력일); //양력
    return 음력변환(dTemp);
}

private DateTime 양력변환(int n음력년, int n음력월, int n음력일, bool b달)
{
    int n윤월;
    System.Globalization.KoreanLunisolarCalendar 음력 =
new System.Globalization.KoreanLunisolarCalendar();

    if (음력.GetMonthsInYear(n음력년) > 12)
    {
n윤월 = 음력.GetLeapMonth(n음력년);
if (b달)
   n음력월++;
if (n음력월 > n윤월)
   n음력월++;
    }
    return 음력.ToDateTime(n음력년, n음력월, n음력일, 0, 0, 0, 0);
}



Posted by CoolDragon
2010. 4. 26. 17:31
HTTP Header를 이용한 파일 다운로드

ASP.NET도  거의 코드가 동일한 가능하다.

Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & file.Name)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(file.FullName)
Response.End
Posted by CoolDragon
2010. 4. 20. 18:10
asp에서 다른 도메인(Cross Domain)의 데이터를 주고 받기 위한 방법으로도 사용된다.
(다른 방법으로는 JSONP를 이용할 수 있다.)

1. C#. XMLWebService 프로젝트로 XML 웹서비스를 개발한다.
  - 도메인 : ws.cooldragon.co.kr
2. asp에서 웹서비스를 호출하는 클라이언트 페이지를 개발한다.
  - 도메인 : www.cooldragon.co.kr
3. 개발된 사이트를 IIS를 설정한다.
4. 브라우저에서 테스트 해본다.
※ ws.cooldragon.co.kr, www.cooldragon.co.kr 은 가상의 도메인이며
   예외 처리는 개발자의 몫으로 돌린다. ^^;;
-------------------------------------------------------------------------

1. [XML 웹서비스 개발]
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class Service1 : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string SayHello(string name)
        {
            return "Hello " + name;
        }

        [WebMethod]
        public int Sum(int x, int y)
        {
            return x + y;
        }

        [WebMethod]
        public int Subtract(int x, int y)
        {
            return x - y;
        }
    }


2. [asp 개발]
<%
' 구현부
Dim reqTy
Dim url
Dim param

url = "http://ws.cooldragon.co.kr/Service1.asmx/SayHello"
param = "name=cooldragon"
Response.Write "result=" & CallWebService(url, param) & "<br/>"

url = "http://ws.cooldragon.co.kr/Service1.asmx/Sum"
param = "x=1&y=2"
Response.Write "result=" & CallWebService(url, param) & "<br/>"

url = "http://ws.cooldragon.co.kr/Service1.asmx/Subtract"
param = "x=1&y=2"
Response.Write "result=" & CallWebService(url, param) & "<br/>"

url = "http://ws.cooldragon.co.kr/Service1.asmx/HelloWorld"
param = ""
Response.Write "result=" & CallWebService(url, param) & "<br/>"
...

'웹서비스 호출 함수
Function CallWebService(url, param)

    Dim result
Dim xmlhttp
Set xmlhttp = Server.CreateObject("MSXML2.XMLHTTP")
    xmlhttp.Open "POST", url, false
    xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xmlhttp.send param
    
    result = xmlhttp.responseText
    set xmlhttp = nothing    
           
    CallWebService = result

End Function 
%>


3. IIS 설정
   - www.cooldragon.co.kr

  - ws.cooldragon.co.kr

4. 실행결과를 확인할 수 있다.


참고URL :
http://www.codeproject.com/KB/asp/Web_Service_Call_From_ASP.aspx
Posted by CoolDragon
2010. 4. 20. 12:17
공통모듈(컴포넌트)이 개발되면 여러 비지니스 로직에서 사용할 수 있다.

예를 들면 (COM+과 같은) 암호화 컴포넌트가 있는경우
암호화 컴포넌트는 asp, asp.net, sql server 2005(sqlclr을 통하여)에서 동일하게 사용이 가능하다.
성능상 로컬 라이브러리보다는 떨어지겠지만 개발생산성은 클 것이라 생각된다.

이러한 측면에서 SQLCLR은 개발자에게 이러한 것을 제공하며 제작하는 방법을 작성해본다~

1. VS2008 시작
2. 프로젝트 생성 
   C# > 데이터베이스 > SQL Server 프로젝트
3. SP 또는 Function을 개발 후 빌드
public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlString Hello(string str)
    {
        // 여기에 코드를 입력합니다.
        return new SqlString("Hello " + str);
    }
};

4. SQL Server에서 어셈블리 등록
  1) clr 권한생성
EXEC sp_configure 'clr enabled' , '1' 
go 
reconfigure; 

  2) 어셈블리 등록
CREATE ASSEMBLY 등록명 FROM '경로\dll명'

  3) 개발 SP 또는 Function 등록
CREATE FUNCTION Hello 
@str NVARCHAR(1000)
RETURNS NVARCHAR(1000)
AS EXTERNAL NAME SqlServerProject1.UserDefinedFunctions.Hello

참고 URL
http://msdn.microsoft.com/en-us/library/ms345135(SQL.90).aspx
Posted by CoolDragon
2010. 4. 19. 16:35

dll 참조를 한다. (설치경로 참조)
 - Common.Logging.dll 1.2.0.0
 - Common.Logging.Log4Net.dll 1.2.0.2
 - log4net.dll 1.2.10.0

logging adaper에는 4가지의 로그를 설정할 수 있다.
 - NoOpLoggerFactoryAdapter : 설정없이 기본으로 사용된다.
 - ConsoleOutLoggerFactoryAdapter : console창에 로그가 나타난다.
 - TraceLoggerFactoryAdapter : System.Diagnostics.Trace for logging output 과 동일하다.
 - Log4NetLoggerFactoryAdapter : 

app.config 파일에서 아래와 같이 설정이 가능하다.

▲ configSection 설정
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler,              Common.Logging" />
    </sectionGroup>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>
   ...
</configuration>


▲ Common.Logging.Simple.TraceLoggerFactoryAdapter, Common.Logging 설정방식
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections ...>
   ...
    <common>
      <logging>
        <factoryAdapter type="Common.Logging.Simple.TraceLoggerFactoryAdapter, Common.Logging">
          <arg key="level" value="DEBUG" />
          <arg key="showLogName" value="true" />
          <arg key="showDataTime" value="true" />
          <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
        </factoryAdapter>
      </logging>
    </common>
   ...
</configuration>

▲ Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging 설정방식
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections ...>
   ...
  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter, Common.Logging">
        <arg key="level" value="DEBUG" />
        <arg key="showLogName" value="true" />
        <arg key="showDataTime" value="true" />
        <arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
      </factoryAdapter>
    </logging>
  </common>
   ...
</configuration>

▲ Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net 설정방식

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections ...>
   ...
  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
        <!-- choices are INLINE, FILE, FILE-WATCH, EXTERNAL-->
        <!-- otherwise BasicConfigurer.Configure is used   -->
        <!-- log4net configuration file is specified with key configFile-->
        <arg key="configType" value="INLINE" />
      </factoryAdapter>
    </logging>
  </common>
   ...
  <log4net debug="false">
    <root>
      <!-- TRACE, DEBUG, ERROR, FATAL, INFO, WARN -->
      <level value="ERROR"/>
      <appender-ref ref="RollingLogFileAppender_Piggy"/>
    </root>

    <logger name="HelloApp.Program">
      <level value="ERROR" />
    </logger>

    <logger name="Spring">
      <level value="INFO" />
    </logger>

    <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
      <param name="File" value="Logs\Application.log.txt"/>
      <param name="datePattern" value="MM-dd HH:mm"/>
      <param name="AppendToFile" value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>                         </layout>
    </appender>
    <appender name="HttpTraceAppender" type="log4net.Appender.ASPNetTraceAppender">
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
      </layout>
    </appender>
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
      </layout>
    </appender>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="Logs\Log.txt"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="10"/>
      <param name="MaximumFileSize" value="5MB"/>
      <param name="RollingStyle" value="Size"/>
      <param name="StaticLogFileName" value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
      </layout>
    </appender>
    <appender name="RollingLogFileAppender_Piggy"                                                      
                    type="log4net.Appender.RollingFileAppender">
      <param name="File" value="Logs\ExceptionLog"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="10"/>
      <param name="MaximumFileSize" value="5MB"/>
      <param name="RollingStyle" value="Date"/>
      <param name="StaticLogFileName" value="false"/>
      <param name="DatePattern" value="yyyyMMdd&quot;.log&quot;"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
      </layout>
    </appender>
  </log4net>
   로그를 찍는방법에는 종류는 4가지가 있다.
        - INLINE
        - FILE
        - FILE-WATCH
        - EXTERNAL

▲  c#에서 사용
using Common.Logging;
.......
ILog Log = LogManager.GetLogger(네임스페이스.클래스명);
Log.Debug("Debug");
Log.Fatal("Fatal");
Log.Error("Error");
Log.Info("Info");
Log.Warn("Warn");

참고
Posted by CoolDragon
2010. 4. 19. 11:55
DI를 하기위한 spring.net에서 제공하는 object 기본 생성 방식은 아래같다.
아래와 같은 방법외에 더 있다면 있는데로 추가하도록 하겠다.

▲ dll 참조추가
 - Spring.Core

▲ configSection 설정
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="spring">
      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
    </sectionGroup>
  </configSections>
   ...
</configuration>


▲ object 설정

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

  <!-- 1. 같은 config 내에서 object 설정-->
  <spring>
    <context>
      <resource uri="config://spring/objects" />
    </context>
    <objects xmlns="http://www.springframework.net">
      <object name="name" type="namespace.class_name, assembly_name" singleton="true/false" />
      ...
    </objects>

  <!-- 2. 포함리소스 방식 -->
  <spring>
    <context>
      <resource uri="assembly://Spring.IocQuickStart.MovieFinder/
                         Spring.IocQuickStart.MovieFinder/AppContext.xml"/>
    </context>
  </spring>

  <!-- 3. object 별로 xml 분리하여 설정 -->
  <spring>
    <context>
      <resource uri="~/Config/CommonObjects.xml"/>

      <resource uri="~/Config/Production/Services.xml"/>

      <resource uri="file://%PROGRAMFILES%/myapp/ioc.config" />
    </context>
  </spring>

</configuration>

2번으로 할 경우는 필히 잊지말고 관련파일을 해당프로젝트(assembly)에 포함리소스로 변경해주어야 한다.



1,2,3을 혼용해서 사용이 가능한지 모르겠지만 개인적으로 3번처럼 구성하는게 좋아보인다.


▲ config에서 객체생성
  - 기본객체 생성
  - 프로퍼티 형식으로 객체 주입하여 생성
  - constructor의 생성자에 인자로 객체생성 방법

c#
using Spring.Context;
using Spring.Context.Support;
...
IApplicationContext ctx = ContextRegistry.GetContext();
IHello hello = (IHello)ctx.GetObject("MyHello");  // config의 object의 name과 일치
string result = hello.Say("CoolDragon");
Console.WriteLine(result);


Posted by CoolDragon