// .aspx
<%@ Page Title="홈 페이지" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="JsonFileDBInsert.aspx.cs" Inherits="KobitAPI.JsonFileDBInsert" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
var strError = "";
var openFile = function (event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function () {
var text = reader.result;
// alert(JSON.stringify(text));
// alert(JSON.parse(text));
var obj = JSON.parse(text);
var array = eval(obj.bpi);
var strPrice = JSON.stringify(array);
var array = strPrice.split(",");
// BIT_BEFORE_INFO
for (var i = 0; i < array.length; i++) {
var infoArray = array[i].split(":");
var actionUrl = "JsonFileDBInsert.aspx";
actionUrl += "?DB_TYPE=JSONINSERT";
actionUrl += "&DATE=" + escape(infoArray[0].replace(/{/gi, "").replace(/}/gi, "").replace(/\"/gi, ""));
actionUrl += "&PRICE=" + escape(infoArray[1].replace(/{/gi, "").replace(/}/gi, "").replace(/\"/gi, ""));
$.ajax({
type: "POST"
, asyn: true
, dataType: "json"
, url: actionUrl
, data: ""
, contentType: "application/json; charset=utf-8"
, beforeSend: function (req) {
req.setRequestHeader("DBAGENT", "BITCOIN");
}
, success: function (rtnJSON) {
// alert(rtnJSON);
}
, error: function (data, status, err) {
if (i != 0)
strError += "\n\r";
strError += infoArray[0].replace(/{/gi, "").replace(/}/gi, "").replace(/\"/gi, "") + " 날짜 에러"
}
, complete: function (jqXHR, textStatus) {
}
});
}
};
reader.readAsText(input.files[0]);
};
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<input type='file' accept='image/*' onchange='openFile(event)' />
</asp:Content>
// .cs
protected void Page_Load(object sender, EventArgs e)
{
string agent = Convert.ToString(Request.Headers.Get("DBAGENT"));
if (agent == "BITCOIN")
{
string res = "";
string method = Convert.ToString(Request["DB_TYPE"]);
switch (method)
{
case "JSONINSERT":
res = this.jsonFileDBInsert(this.Request.Params);
break;
}
}
}
private string jsonFileDBInsert(System.Collections.Specialized.NameValueCollection parameters)
{
string result = "";
string strDATE = Convert.ToString(Request["DATE"]);
string strPRICE = Convert.ToString(Request["PRICE"]);
#region DB 저장
DacLibrary _dacLib = new DacLibrary();
try
{
_dacLib.BeginTransactionS();
/// TODO : 테이블과 프로시저 생성해서 돌려봐라
_dacLib.ExecuteNonQueryS("BIT_BEFORE_INFO_INSERT", strDATE, strPRICE);
_dacLib.CommitTransactionS();
}
catch (Exception err)
{
_dacLib.RollbackTransactionS();
result = err.Message.ToString();
}
#endregion
return result;
}
'IT > javascript' 카테고리의 다른 글
자바스크립트 try catch (0) | 2018.02.23 |
---|---|
자바스크립트 반올림, 올림, 버림 (0) | 2018.02.13 |
ajax의 여러가지 사용 법 (C#) (0) | 2015.12.23 |
Ajax 사용 (Json) (0) | 2015.07.15 |
.net 자바스크립트 radiobutton Checked (0) | 2015.07.10 |