달력

06

« 2010/06 »

  •  
  •  
  • 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
  •  
  •  
  •  

'2010/06'에 해당되는 글 4

  1. 2010/06/28 AJAX + ASP.NET (1)
  2. 2010/06/18 ASP + AJAX(JSON)
  3. 2010/06/17 Boinc 실적
  4. 2010/06/08 금성-화성-토성이 한번에 보이네요
2010/06/28 01:19

AJAX + ASP.NET General .NET2010/06/28 01:19

ASP.NET을 이용하여 AJAX 통신을 해보겠습니다.

먼저 아래의 그림과 같이 코딩을 합니다.


이미지를 보면 번호가 붙어 있는데요. 각 번호에 대한 설명은 아래와 같습니다.
1번 - AJAX 통신을 위해 ScriptManager를 이용합니다. ScriptManager는 참조경로로 CostService.svc 를 연결합니다.
2번 - HTML 콘트롤로 버튼을 하나 생성합니다. 클릭시 자바스크립트로 연결됩니다. Button1_onclick()를 호출합니다.
3번 - AJAX 통신으로 취합된 데이터를 출력하는 엘리먼트 입니다.


1번에 보여진 svc 설정을 위해 아래의 그림과 같은 절차를 이행합니다.
먼저 프로젝트에서 마우스 우클릭하고, Add > New Item 을 클릭합니다.
.svc 선택을 위해 AJAX-enabled WCF Service를 선택하고 Name CostService.svc 를 적어 줍니다.

Add 버튼을 클릭하고 svc를 추가합니다.
svc의 내용은 다음과 같습니다.
설명은 코드상에 주석으로 표기해 놓았습니다.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Configuration;
using System.Web.Configuration;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using Pesta.Utilities.Helpers;

//네임스페이스는 SandwichServices 입니다.
namespace SandwichServices
{

    [ServiceContract(Namespace = "SandwichServices")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class CostService : BaseCode
    {
        [OperationContract]
        public string CostOfSandwiches()
        {
            //BaseCode에서 연결 문자열을 가져옵니다.
            //코드 내용은아래에 있습니다.
            BaseCode bc = new BaseCode();
            string strConnection = bc.strConnection;

            //데이터베이스에 연결하고 오픈합니다.
            SqlConnection con = new SqlConnection();
            con.ConnectionString = strConnection;
            con.Open();

            //데이터를 가져오기 위한 쿼리 문자열을 생성합니다.
            //운영할 때 편이성을 위해 이렇게 코드에 쿼리를 넣는 것 보다는 SP로 하는게 더 낫습니다.
            string Query = string.Empty;
            Query = "select * from leeho_test";

            SqlCommand cmd = new SqlCommand(Query, con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adp.Fill(ds);

            //데이터 셋을 JSONHelper 객체로 보내 JSON 문자열을 생성합니다.
            Pesta.Utilities.Helpers.JSONHelper jh = new Pesta.Utilities.Helpers.JSONHelper();
            string ss = jh.ToJSON(ds);

            return ss;
           
        }
    }
}

//아래는 JSON 헬퍼 입니다.
//헬퍼 클래스는 2개의 메서드를 가지는데 하나는 데이터 셋을 인자로 받고, 다른 하나는 데이터 테이블을 직접 전달할 수
//있게 되어 있습니다.
namespace Pesta.Utilities.Helpers
{

    public class JSONHelper
    {
        #region Made from datatable of dataset to JSON string
        /// <summary>
        /// WriteDate : 2010-06-14
        /// Author : Jonghyun, Park
        /// Content: Made from DataTable of DataSet to JSON
        /// </summary>
        /// <param name="obj">DataSet</param>
        /// <returns>jsonBuilder</returns>
        public string ToJSON(DataTable dt)
        {
            return MakeData(dt);
        }
        #endregion

        #region Made from DataSet of dataset to JSON
        /// <summary>
        /// WriteDate : 2010-06-14
        /// Author : Jonghyun, Park
        /// Content: Made from DataSet of dataset to JSON
        /// </summary>
        /// <param name="obj">DataSet</param>
        /// <returns>jsonBuilder</returns>
        public string ToJSON(DataSet obj)
        {
            DataTable dt = obj.Tables[0];
            return MakeData(dt);
        }
        #endregion

        #region Make Data
        /// <summary>
        /// WriteDate : 2010-06-14
        /// Author : Jonghyun, Park
        /// Content: Make Data
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <returns></returns>
        private static string MakeData(DataTable dt)
        {
            StringBuilder jsonBuilder = new StringBuilder();
            jsonBuilder.Append("[");
           
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                jsonBuilder.Append("{");
                for (int j = 0; j < dt.Columns.Count; j++)
                {
                    jsonBuilder.Append("\""+ dt.Columns[j].Caption +"\":\"");
                    jsonBuilder.Append(dt.Rows[i][j].ToString());
                    jsonBuilder.Append("\",");
                }
                jsonBuilder.Remove(jsonBuilder.Length - 1, 1);
                jsonBuilder.Append("},");
            }
            jsonBuilder.Remove(jsonBuilder.Length - 1, 1);

            jsonBuilder.Append("]");
            return jsonBuilder.ToString();
        }
        #endregion
    }
}


아래는 BaseCode.cs 입니다.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace SandwichServices
{
    public class BaseCode
    {
        public string DBKEY = string.Empty;
        public string GETKey = tring.Empty;
        private string dbkey {
            get {
                return DBKEY;
            }
            set {
                dbkey = DBKEY;
            }
        }
        public string strConnection = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();
    }
}

   

다 되었으면 2번 내용을 준비합니다.
Button1_onclick() 함수를 자바스크립트로 만들어야 하는데요. 코드는 아래와 같습니다.

설명을 하자면....
1번 Button1_onclick 함수는 svc에서 노출된 함수를 호출합니다. 호출된 json 문자열을 2번 onSuccess 함수에 값으로 전달하게 되고 onsuccess 함수는 전달된 json 문자열을 div 엘리먼트의 id가 dvPrintData 객체에 그 값을 전달하여 출력하게 합니다.

출력 결과는 아래와 같습니다.


이상으로 AJAX + ASP.NET의 가장 기초적인 작성을 해봤습니다.


저작자 표시 비영리 변경 금지
Posted by -세티-
2010/06/18 17:49

ASP + AJAX(JSON) General Web2010/06/18 17:49


ASP 페에지 코딩 부분

호출 페이지로 전달할 데이터를 생성해 낸다.
호출된 데이터는 JSON 타입으로 사용하기 위해 문자열로 만들어준다.

 <%

    response.charset = "utf-8"
   
    dim cmd, db
   
    set db = server.createobject("adodb.connection")
    db.open "provider=sqloledb; data source = IP Address;uid=DBID;pwd=PASSWORD;database=DBNAME"
   
    set cmd = server.createobject("adodb.command")
    cmd.activeconnection = db
    cmd.commandtext = spNAME
    cmd.commandtype = 1
   
    set rs = cmd.execute
   
    if not rs.eof then
        OpenEventCommentList = rs.getrows()
    end if
    rs.close
  
    set rs = nothing

'   ============================================================
'   배열로 저장된 레코드 셋 출력하기.
'   ============================================================
    dim rowCnt, colCnt
    rowCnt = ubound(OpenEventCommentList, 2)    '행
    colCnt = ubound(OpenEventCommentList, 1)    '열
  
    dim json
    if IsArray(OpenEventCommentList) then
        json = json + "["
        for i=0 to rowCnt
            json = json + "{"
            for j=0 to colCnt
                if j=0 then json = json + """UserID"":""" end if
                if j=1 then json = json + """Content"":""" end if
                if j=2 then json = json + """RegDate"":""" end if
                json = json + OpenEventCommentList(j, i)
                json = json + ""","
            next
            json = Mid(json, 1, len(json) -1)
            json = json + "},"
        next
        json = Mid(json, 1, len(json) -1)
       
        json = json + "]"
    end if
   
    response.write json
%>


HTML 호출 페이지
1. createXMLHttpRequest() 호출 객체를 생성한다.
2. 콜백함수를 호출할 getCommentList() 객체를 생성한다.
3. 콜백함수 getCommentList_Callback()를 생성한다.

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>댓글 기능</title>
    <script language="javascript" type="text/javascript">
        var strTable = "";
        function createXMLHttpRequest() {
            if (window.ActiveXObject) {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
            }
        }

        function getCommentList() {
            createXMLHttpRequest();
            xmlHttp.onreadystatechange = getCommentList_Callback;
            xmlHttp.open("GET", "GetCmtList.asp", true);
            xmlHttp.send();
        }

        function getCommentList_Callback() {
            if (xmlHttp.readyState == 4) {
                if (xmlHttp.status == 200) {
                    var obj = eval('(' + xmlHttp.responseText + ')');

                    strTable += "<table border='1' cellpadding='0' cellspacing='0'><tr><td>Idx</td><td>keyword</td><td>writeday</td></tr>";
                    for (var i = 0; i < obj.length; i++) {
                        strTable += "<tr>";
                        strTable += "<td>" + obj[i]["UserID"] + "</td>";
                        strTable += "<td>" + obj[i]["Content"] + "</td>";
                        strTable += "<td>" + obj[i]["RegDate"] + "</td>";
                        strTable += "</tr>";
                    }
                    strTable += "</table>";
                    document.getElementById("CommentList").innerHTML = strTable;
                }
            }
        }
    </script>
</head>
<body>
    <div id="CommentList"></div>
    <form id="eventComment">
        <textarea name="content" id="cheerContent" cols="100" rows="3"></textarea>
        <input type="button" value="comment" />
    </form>
    <script type="text/javascript" language="javascript">
        getCommentList();
    </script>
</body>
</html>



저작자 표시 비영리 변경 금지
Posted by -세티-
2010/06/17 10:03

Boinc 실적 Astronomy2010/06/17 10:03

1999년 부터 참여하고 있는 세티 프로젝트의 최근 기록

Detailed statistics for
"Jong-Hyun Park"

BOINC Cross Project IDentifier d76e17d67d4c5a2432cf0b66a4de7585
URL www.setisigns.net
 
Current Credit (based on incremental update) 93,865.40
Comprising 93,865.40 from the daily update
+ 0.00 since then
BOINC World position based on credit (based on incremental update) 226,981 out of 1,977,011
50 since daily update
 
Recent average credit RAC (projects accumulated) 432.71690
Recent average credit RAC (according to BOINCstats) 410.60581
Recent average position change per day 627.85
BOINC World position based on RAC (based on incremental update) 76,131 out of 1,977,011
Overtake stats  Overtake stats 
 
Contribution to BOINC total credit 0.00004%
Contribution to BOINC total RAC 0.00008%
Accumulated more credit than % of all BOINC users 88.519%
Highest World position ever 53829 at 2005-07-14
 
Set your credit target calculate
Target results
No target set
Set your date target calculate
Target results
No target set
 
Link to users host stats  Host list 
 
Member of team Seti@Home Korea
Position in Team 89 out of 1044
Contribution to Team total credit 0.13336%
Contribution to Team total RAC 0.50471%
Accumulated more credit than % of all Team members 91.475%
 
Resident of Korea, South Korea, South
Position in Country stats 446 out of 7732
Contribution to own country total credit 0.01853%
Contribution to own country total RAC 0.02034%
Accumulated more credit than % of all fellow citizens 94.23176%
 
Cup points 35.61
Cup Rank 150,506
 
URL for user signature graphic http://www.boincstats.com/signature/user_176210.gif
URL for user signature graphic (for this project only) http://www.boincstats.com/signature/user_176210_project-1.gif
URL for user WAP stats http://www.boincstats.com/stats/wap_user.php?id=176210

Best five days
Date Credit
2010-06-08 16:48:12 1,676
2010-05-27 16:46:24 1,470
2010-05-26 16:41:44 1,467
2010-05-12 16:42:20 1,460
2010-05-19 16:42:39 1,373

  Current Credit  Current position  % of total  last day  Cup Rank   
SETI@Home 93,865.40  114,860  100.00  838.86  28,083    







































Last 30 days (based on the daily update numbers):
  2010-06-16 2010-06-15 2010-06-14 2010-06-13 2010-06-12 2010-06-11 2010-06-10 2010-06-09 2010-06-08 2010-06-07
Total Credit 93,865 93,027 93,027 93,027 92,802 92,684 92,513 92,255 92,255 90,579
Credit/day 839 0 0 225 117 172 258 0 1,676 1,345
Position 226,931 228,084 227,939 227,821 228,006 228,013 228,139 228,287 228,164 230,800
Position change 1153 145 118 185 7 126 148 123 2636 2056
Position
in team
89 89 89 89 89 89 89 89 89 91
Position change
in team
0 0 0 0 0 0 0 0 2 0

  2010-06-06 2010-06-05 2010-06-04 2010-06-03 2010-06-02 2010-06-01 2010-05-31 2010-05-30 2010-05-29 2010-05-28
Total Credit 89,234 88,736 88,465 88,344 87,876 87,700 86,381 86,257 85,793 85,464
Credit/day 498 270 121 468 176 1,319 123 465 329 516
Position 232,856 233,591 233,885 233,923 234,581 234,735 236,986 237,130 237,723 238,163
Position change 735 294 38 658 154 2251 144 593 440 698
Position
in team
91 91 91 91 91 91 91 91 91 91
Position change
in team
0 0 0 0 0 0 0 0 0 0

  2010-05-27 2010-05-26 2010-05-25 2010-05-24 2010-05-23 2010-05-22 2010-05-21 2010-05-20 2010-05-19 2010-05-18
Total Credit 84,948 83,478 82,010 81,574 81,574 81,173 80,836 80,602 80,479 79,107
Credit/day 1,470 1,467 437 0 400 337 234 123 1,373 0
Position 238,861 241,406 244,029 244,708 244,588 245,233 245,738 246,032 246,071 248,501
Position change 2545 2623 679 120 645 505 294 39 2430 136
Position
in team
91 93 95 95 95 96 96 95 95 95
Position change
in team
2 2 0 0 1 0 1 0 0 0

저작자 표시 비영리 변경 금지

'Astronomy' 카테고리의 다른 글

경기도 화석정  (0) 2011/06/28
중앙선데이에 별과 사람들  (2) 2010/09/11
Boinc 실적  (0) 2010/06/17
금성-화성-토성이 한번에 보이네요  (0) 2010/06/08
천문학 용어  (0) 2010/05/27
아름다운 밤하늘과 양평국제천문대  (3) 2010/05/16
Posted by -세티-

아까 한 시간전에 하늘을 보니깐 금성, 화성, 토성이 황도상에 직선으로 늘어서 있더라구요.
화성밑에 작은 별이 뭘까 하고 찾아보니깐 사자자리의 레귤러스 더군요.
아래는 다양한 아이폰 애플리케이션으로 본 금성-화성-토성 입니다.

모두 GPS 기반이기에 Star Walk와 동일한 방식으로 동작 합니다.

사본 -Venus_Mars_Saturn.jpg

(Starmap App)

 

 사본 -Venus_Mars_Saturn_2.jpg
(Star Chart App) 

저작자 표시 비영리 변경 금지

'Astronomy' 카테고리의 다른 글

중앙선데이에 별과 사람들  (2) 2010/09/11
Boinc 실적  (0) 2010/06/17
금성-화성-토성이 한번에 보이네요  (0) 2010/06/08
천문학 용어  (0) 2010/05/27
아름다운 밤하늘과 양평국제천문대  (3) 2010/05/16
2010년 대한민국 별축제 안내.  (0) 2010/05/07
Posted by -세티-