問題情境:
一個表單,上半部要先填條件後帶出資料,才繼續填下半部
下半部的ui先用blockUI罩起來,中間顯示「請填上半部的資料」
結果那個顯示文字在BOOTSTRAP的表單置中樣式套用後就歪掉了
解法:
顯示訊息的時候指定
centerX: false,
centerY: false
參考:
Why does my div not center properly?http://stackoverflow.com/questions/2518465/why-does-my-div-not-center-properly
2015年12月23日 星期三
2015年12月21日 星期一
沒有權限存取資料夾 的IIS 資料夾權限設定
網站有個功能需要刪除資料夾內的檔案
但預設沒有權限可以存取
解決方法:
對該資料夾按右鍵→內容→安全性
新增使用者名稱填入
IIS AppPool\(在IIS的集區名字)
按確定,就會多出一個集區使用者,就可以針對他來做權限設定了
但預設沒有權限可以存取
解決方法:
對該資料夾按右鍵→內容→安全性
新增使用者名稱填入
IIS AppPool\(在IIS的集區名字)
按確定,就會多出一個集區使用者,就可以針對他來做權限設定了
2015年12月4日 星期五
ASP.NET GridView Header flow by scroll up and down use JQuery | WebForm的Gridview 欄標題 以JQuery置頂的方法
WebForm的Gridview元件想要讓欄標題可以置頂的方法
我的Gridview是用template做版面的,資料很多很長,捲下去時就看不見欄標題,很不方便,
解法參考來源:
http://stackoverflow.com/questions/2177983/how-to-make-div-follow-scrolling-smoothly-with-jquery
answered by ajax333221
1.原本是只有設定HeaderText,現在要加上HeaderTemplate,然後用div包起來標題文字
2.div給一個css class,這個class加上fixed時就會固定置頂
3.JQUERY
2015/12/25 追記:
如果有GridView是不要一進網頁就databinding的,那網頁ready的時候就沒有欄位標題可以註冊,
這樣就讓效果無效了,我想到的兩種解決方法:
一種是把Jquery部分改放到function pageLoad() { }事件,
這個事件會在aspx postback回來後觸發
但要判斷有沒有註冊過window scroll 才去註冊那個事件
不然每次post back都會註冊一次 就會有問題
我沒有把這方法做完,改用我想到的第二種方法
第二種比較簡單的方法是,設定gridview屬性ShowHeaderWhenEmpty="true"
然後在page load事件給gridview空的source後bind
gv.DataSource = new DataTable();
gv.DataBind();
這樣就會沒資料但顯示標頭,就可以讓javascript註冊事件
我的Gridview是用template做版面的,資料很多很長,捲下去時就看不見欄標題,很不方便,
解法參考來源:
http://stackoverflow.com/questions/2177983/how-to-make-div-follow-scrolling-smoothly-with-jquery
answered by ajax333221
1.原本是只有設定HeaderText,現在要加上HeaderTemplate,然後用div包起來標題文字
<asp:TemplateField HeaderText="標題" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
<div class="divTH">
<label>標題</label>
</div>
</HeaderTemplate>
<ItemTemplate>
......
</ItemTemplate>
</asp:TemplateField>
2.div給一個css class,這個class加上fixed時就會固定置頂
.divTH.fixed {
position: fixed;
top: 0;
}
3.JQUERY
$(document).ready(function () {
if (!($.browser == "msie" && $.browser.version < 7)) {
var target = ".divTH", top = $(target).offset().top - parseFloat($(target).css("margin-top").replace(/auto/, 0));
$(window).scroll(function (event) {
if (top <= $(this).scrollTop()) {
$(target).addClass("fixed");
} else {
$(target).removeClass("fixed");
}
});
}
});
2015/12/25 追記:
如果有GridView是不要一進網頁就databinding的,那網頁ready的時候就沒有欄位標題可以註冊,
這樣就讓效果無效了,我想到的兩種解決方法:
一種是把Jquery部分改放到function pageLoad() { }事件,
這個事件會在aspx postback回來後觸發
但要判斷有沒有註冊過window scroll 才去註冊那個事件
不然每次post back都會註冊一次 就會有問題
我沒有把這方法做完,改用我想到的第二種方法
第二種比較簡單的方法是,設定gridview屬性ShowHeaderWhenEmpty="true"
然後在page load事件給gridview空的source後bind
gv.DataSource = new DataTable();
gv.DataBind();
這樣就會沒資料但顯示標頭,就可以讓javascript註冊事件
標籤:
表格標題置頂,
asp.NET,
GridView,
header flow,
JQuery
2015年11月20日 星期五
asp.Net ObjectDataSource output parameter
一個查詢功能
有與DB溝通的Class,查詢方法會回拋DataTable
前端做GridView+ObjectDataSource
現在想要做後端驗證
驗證的方式是在傳入參數加入一個自訂類別 myValidClass的 output參數叫msg
在函式開頭就會先做驗證
有錯誤的時候msg的status屬性就會是false
並且msg的msg屬性會塞錯誤訊息
在網頁端的ODS加上
<asp:Parameter Type="Object" Direction="Output" Name="msg" />
並且加入OnSelected方法ods_Selected
<asp:ObjectDataSource runat="server" ID="ods" .... OnSelected="ods_Selected">
.cs端的ods_Selected方法
protected void ods_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
myValidClass msg = (myValidClass)e.OutputParameters["msg"];
if (!msg.status)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "alert", "alert('"+msg.msg+"');", true);
}
}
DB溝通class的方法
public DataTable search(string parameter1, out myValidClass msg)
{
DataTable dt=new DataTable();
//Do your validate method
msg=new myValidClass();
msg.status=true;
if(string.IsNullOrEmpty(parameter1))
{
msg.status=false;
msg.msg="參數1不可為空";
}
if(msg.status)
{
dt=db.getData(parameter1);
}
return dt;
}
這樣在做完查詢後ods_Selected方法就會檢查msg有沒有錯誤,
有錯誤就會alert錯誤訊息
2015年11月18日 星期三
[C#][擴充方法] 取得西元日期的民國年月日
/// <summary> 將西元日期轉民國日期 回傳 字串陣列[0]民國年YYY [1]月MM [2]日DD</summary>
/// <param name="datetime">要轉換的日期</param>
/// <returns>字串陣列[0]民國年YYY [1]月MM [2]日DD</returns>
public static string[] ToSimpleTaiwanDate(this DateTime datetime)
{
TaiwanCalendar taiwanCalendar = new TaiwanCalendar();
return new string[]{
taiwanCalendar.GetYear(datetime).ToString(),
datetime.Month.ToString().PadLeft(2,'0'),
datetime.Day.ToString().PadLeft(2,'0')};
}
/// <summary> 將西元日期轉民國日期 回傳 字串陣列[0]民國年YYY [1]月MM [2]日DD</summary>
/// <param name="datetime">要轉換的日期</param>
/// <returns>字串陣列[0]民國年YYY [1]月MM [2]日DD</returns>
public static string ToSimpleTaiwanDate_YYYMMDD(this DateTime datetime)
{
TaiwanCalendar taiwanCalendar = new TaiwanCalendar();
return
taiwanCalendar.GetYear(datetime).ToString()+
datetime.Month.ToString().PadLeft(2,'0')+
datetime.Day.ToString().PadLeft(2,'0');
}
標籤:
日期,
民國年,
西元年,
C#,
Extension Method
[C#][擴充方法] 取得日期的統一發票期別
/// <summary> 傳入日期傳出發票期別的兩個數字 [1 2] [3 4]...</summary>
/// <param name="datetime">要判斷的日期</param>
/// <returns> 整數陣列[0]期別第一個月份 [1]期別第二個月份 </returns>
public static int[] ToInvoiceMonthRange(this DateTime datetime)
{
//2 4 6 8...->餘0 ->[2-1,2][4-1,4]
//1 3 5 7...->餘1 ->[1,1+1][3,3+1]
return (datetime.Month % 2) == 0
? new int[] { datetime.Month - 1, datetime.Month }
: (datetime.Month % 2) == 1
? new int[] { datetime.Month, datetime.Month+1 }
: new int[] { 0, 0 };
}
標籤:
日期,
期別,
統一發票,
C#,
Extension Method
2015年10月30日 星期五
C# call AS400 RPG program
markdown
# 背景
因為有RPG程式老舊但一時間又不能轉出來,只能先靠程式去呼叫,
所以就用C#引用AS400元件去呼叫RPG,得到結果。
# 使用DLL
`C:\Program Files (x86)\IBM\Client Access\Shared\cwbx.dll`
# 加入參考的時候要注意內嵌 Interop 型別的問題
REF:http://blog.miniasp.com/post/2010/06/21/dot-net-4-Interop-type-cannot-be-embedded-Use-the-applicable-interface-instead.aspx
# 程式碼參考:
REF:http://forums.asp.net/t/1817332.aspx?calling+as400+programs+from+c+
```C#
using cwbx; public string getRPGProgramReturnValue(string functionName, string LibraryName, string ProgramName, ProgramParameters parameters, string outputParameterName, out CUDResult msg) { msg = new CUDResult(); string result = string.Empty; StringConverter stringConverter = new StringConverterClass(); AS400System system = new AS400System(); try { // 定義 AS400 連線資訊 system.Define("AS400"); system.UserID = "你的帳號"; system.Password = "你的密碼"; //注意:一定要是IP,用domain網址會跳一個"CWB4016 - cwbCO_SetIPAddressW 傳回錯誤碼 87"的錯誤 system.IPAddress = "你的伺服器IP"; system.Connect(cwbcoServiceEnum.cwbcoServiceRemoteCmd); // 有連線才繼續 if (system.IsConnected(cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 1) { // 宣告程式物件 連到系統 cwbx.Program program = new cwbx.Program(); program.LibraryName = LibraryName; program.ProgramName = ProgramName; program.system = system; // 呼叫程式 try { program.Call(parameters); } catch (Exception ex) { msg.status = false; msg.msg += "呼叫程式時發生錯誤:" + ex.Message + "\n"; if (system.Errors.Count > 0) { msg.msg += "呼叫程式時發生system錯誤:"; foreach (cwbx.Error error in system.Errors) { msg.status = false; msg.msg += error.Text + "\n"; } } if (program.Errors.Count > 0) { msg.msg += "呼叫程式時發生program錯誤:"; foreach (cwbx.Error error in program.Errors) { msg.status = false; msg.msg += error.Text + "\n"; } } } result = stringConverter.FromBytes(parameters[outputParameterName].Value); } else { msg.status = false; msg.msg += "無法連線到AS400 ServiceRemoteCmd\n"; } system.Disconnect(cwbcoServiceEnum.cwbcoServiceAll); msg.status = true; } catch (Exception ex) { system.Disconnect(cwbcoServiceEnum.cwbcoServiceAll); msg.status = false; msg.msg += "執行" + functionName + "時發生錯誤:" + ex.Message + "\n"; } return result; } ```
# 追記
20180530 在改寫舊程式時我把IP換成DOMAIN,因應管理要求,
結果就跳出一個`CWB4016 - cwbCO_SetIPAddressW 傳回錯誤碼 87`的錯誤,
研究了半天想說自己沒改什麼東西,google也查不到什麼,
回頭看自己改的東西才想到那個欄位是IP,該不會不能填網址,
就改回IP,就正常了,算踩到一個雷。
但他還有一個`IPAddressLookupMode`屬性,我是沒試過。
# 背景
因為有RPG程式老舊但一時間又不能轉出來,只能先靠程式去呼叫,
所以就用C#引用AS400元件去呼叫RPG,得到結果。
# 使用DLL
`C:\Program Files (x86)\IBM\Client Access\Shared\cwbx.dll`
# 加入參考的時候要注意內嵌 Interop 型別的問題
REF:http://blog.miniasp.com/post/2010/06/21/dot-net-4-Interop-type-cannot-be-embedded-Use-the-applicable-interface-instead.aspx
# 程式碼參考:
REF:http://forums.asp.net/t/1817332.aspx?calling+as400+programs+from+c+
```C#
using cwbx; public string getRPGProgramReturnValue(string functionName, string LibraryName, string ProgramName, ProgramParameters parameters, string outputParameterName, out CUDResult msg) { msg = new CUDResult(); string result = string.Empty; StringConverter stringConverter = new StringConverterClass(); AS400System system = new AS400System(); try { // 定義 AS400 連線資訊 system.Define("AS400"); system.UserID = "你的帳號"; system.Password = "你的密碼"; //注意:一定要是IP,用domain網址會跳一個"CWB4016 - cwbCO_SetIPAddressW 傳回錯誤碼 87"的錯誤 system.IPAddress = "你的伺服器IP"; system.Connect(cwbcoServiceEnum.cwbcoServiceRemoteCmd); // 有連線才繼續 if (system.IsConnected(cwbcoServiceEnum.cwbcoServiceRemoteCmd) == 1) { // 宣告程式物件 連到系統 cwbx.Program program = new cwbx.Program(); program.LibraryName = LibraryName; program.ProgramName = ProgramName; program.system = system; // 呼叫程式 try { program.Call(parameters); } catch (Exception ex) { msg.status = false; msg.msg += "呼叫程式時發生錯誤:" + ex.Message + "\n"; if (system.Errors.Count > 0) { msg.msg += "呼叫程式時發生system錯誤:"; foreach (cwbx.Error error in system.Errors) { msg.status = false; msg.msg += error.Text + "\n"; } } if (program.Errors.Count > 0) { msg.msg += "呼叫程式時發生program錯誤:"; foreach (cwbx.Error error in program.Errors) { msg.status = false; msg.msg += error.Text + "\n"; } } } result = stringConverter.FromBytes(parameters[outputParameterName].Value); } else { msg.status = false; msg.msg += "無法連線到AS400 ServiceRemoteCmd\n"; } system.Disconnect(cwbcoServiceEnum.cwbcoServiceAll); msg.status = true; } catch (Exception ex) { system.Disconnect(cwbcoServiceEnum.cwbcoServiceAll); msg.status = false; msg.msg += "執行" + functionName + "時發生錯誤:" + ex.Message + "\n"; } return result; } ```
# 追記
20180530 在改寫舊程式時我把IP換成DOMAIN,因應管理要求,
結果就跳出一個`CWB4016 - cwbCO_SetIPAddressW 傳回錯誤碼 87`的錯誤,
研究了半天想說自己沒改什麼東西,google也查不到什麼,
回頭看自己改的東西才想到那個欄位是IP,該不會不能填網址,
就改回IP,就正常了,算踩到一個雷。
但他還有一個`IPAddressLookupMode`屬性,我是沒試過。
標籤:
AS400,
C#,
cwbx.dll,
RPG program
2015年10月28日 星期三
DB2 numeric 百分比 除法
兩個numeric欄位 A與B 都是兩位數
計算(B/A)*100的比率,如果是0就顯示0,或65.43的小數點表示
當A為0時,會無法計算,所以就直接顯示0
重點是CAST轉型為DECIMAL時要記得小數位數是包含在長度內的
如果要顯示123.45這樣三位數字與兩位小數點,長度就是3+2=5
計算(B/A)*100的比率,如果是0就顯示0,或65.43的小數點表示
當A為0時,會無法計算,所以就直接顯示0
重點是CAST轉型為DECIMAL時要記得小數位數是包含在長度內的
如果要顯示123.45這樣三位數字與兩位小數點,長度就是3+2=5
CASE WHEN A is null or A=0 then varchar(0)
else varchar(round(CAST((CAST(COALESCE(B,0) AS FLOAT)/
CAST(COALESCE(A,0) AS FLOAT))*100 AS decimal(5,2)),2))
END AS RATE
標籤:
比率,
除法,
DB2,
divided,
SQL.DECIMAL
2015年10月21日 星期三
Microsoft Exchange server SMTP mail send slowly
SMTP寄信,每封信都要DELAY30秒,
明明已經收到信,但程式還卡在寄信指令那行無法前進,
經查為Exchange Server 有延遲設定,為了做陰影備援
請MIS將所有主機的延遲用以下指令設為零後,寄信都秒送了。
set-ReceiveConnector -Identity "MyExchangeName\Default MyExchangeName" -MaxAcknowledgementDelay 0
參考:
標籤:
Email,
ExchangeServer,
SMTP
2015年10月19日 星期一
VM install Windows Server 2012 accoured error 0x80070570
VM install Windows Server 2012 accoured error 0x80070570
solution: check the md5 code,maybe ISO file not complete.
解法:檢查MD5,不一樣就重抓ISO
來源:LINE群
solution: check the md5 code,maybe ISO file not complete.
解法:檢查MD5,不一樣就重抓ISO
來源:LINE群
標籤:
0x80070570,
VM,
Windows Server 2012
2015年10月13日 星期二
asp.net gridview number format dynamic decimal
Text='<%# Eval("column_name","{0:#0.#}") %>'
0→00.1→0.1
標籤:
asp.NET,
GridView,
number format
2015年10月7日 星期三
2015年10月2日 星期五
ORA-12704 字元設定不符合
我在做小計總計報表
用了group by rollup來做群組,還有grouping(欄位名稱)來判斷小計行跟總計行
因為小計跟總計行的時候被群組的欄位會留白,要塞一些字進去
就用了case when grouping.... then '這是小計'的判斷
然後就跳錯ORA-12704
查很多網頁都說字串引號前面加一個N來轉型
但是很討厭的是加上去後,那個字串後developer裡面的sql全部都會變成字串顏色
解決方法就是把這個字串轉型就好了
cast('總計' as nvarchar2(20))
用了group by rollup來做群組,還有grouping(欄位名稱)來判斷小計行跟總計行
因為小計跟總計行的時候被群組的欄位會留白,要塞一些字進去
就用了case when grouping.... then '這是小計'的判斷
然後就跳錯ORA-12704
查很多網頁都說字串引號前面加一個N來轉型
但是很討厭的是加上去後,那個字串後developer裡面的sql全部都會變成字串顏色
解決方法就是把這個字串轉型就好了
cast('總計' as nvarchar2(20))
標籤:
group by rollup,
grouping,
ORA-12704,
Oracle
2015年9月25日 星期五
How jquery.validate.js do multi remote rule
使用jquery.validate做前端驗證,搭配remote做AJAX到後端驗證
有一個需求
新增紀錄時驗證客戶編號欄位:
1.存在資料庫
然後新需求的驗證是
2.本月份紀錄中若有成交紀錄則不可新增
我試著對一個欄位加兩個remote屬性,他會取最後加的那個,所以不行這樣,
於是就把原本的方法改成
然後把原本的ERROR MESSAGE拿掉,
這樣回傳是字串時,jquery.validate就會把字串當成錯誤訊息
回傳TRUE時,就會判定驗證通過了
有一個需求
新增紀錄時驗證客戶編號欄位:
1.存在資料庫
然後新需求的驗證是
2.本月份紀錄中若有成交紀錄則不可新增
我試著對一個欄位加兩個remote屬性,他會取最後加的那個,所以不行這樣,
於是就把原本的方法改成
if (資料庫存在此客編)
{
if(本月此客編無成交紀錄)
{
return JsonConvert.SerializeObject(true);
}
else
{
return JsonConvert.SerializeObject("本月此客編已有成交紀錄");
}
}
else
{
return JsonConvert.SerializeObject("此客編不存在");
}
然後把原本的ERROR MESSAGE拿掉,
這樣回傳是字串時,jquery.validate就會把字串當成錯誤訊息
回傳TRUE時,就會判定驗證通過了
標籤:
前端驗證,
AJAX,
asp.NET,
javascript,
JQuery,
jquery.validate.js,
validate,
WebMethod
2015年9月24日 星期四
NPOI write to Stream get Can't open closed Stream error
用NPOI寫EXCEL檔案
然後轉成串流,再轉乘Attachment給Email夾帶
但是一直發生無法存取關閉的串流錯誤
爬到這篇
http://www.codeproject.com/Tips/813187/Csharp-Read-and-Write-Excel-xls-and-xlsx-Files-Con
底下的留言
他先把串流轉byte 再開新串流byte轉串流
試了一下後果然可以了
但效能上如何就沒測了
然後轉成串流,再轉乘Attachment給Email夾帶
但是一直發生無法存取關閉的串流錯誤
爬到這篇
http://www.codeproject.com/Tips/813187/Csharp-Read-and-Write-Excel-xls-and-xlsx-Files-Con
底下的留言
他先把串流轉byte 再開新串流byte轉串流
試了一下後果然可以了
但效能上如何就沒測了
var arrBites = stream.ToArray();
MemoryStream newStream = new MemoryStream(arrBites);
標籤:
匯出excel,
asp.NET,
Attachment,
C#,
Email,
File,
MemoryStream,
NPOI,
SMTP,
Stream
2015年9月7日 星期一
jquery.validate.js的數字驗證沒有驗證逗點跟小數點
早上又被call程式出錯...又是數字欄位塞了逗點進去
我用jquery.validate.js作前端驗證,不過後端的驗證只有insert寫了,
在update事件忘了寫整數驗證
就那麼剛好user使用了update事件去塞了錯誤的內容
程式就當了
參考
http://blog.rebuildall.net/2011/03/02/jquery_validate_and_the_comma_decimal_separator
他是寫成js去include
我直接把他的方法寫在document ready事件裡面
然後正規表達式改成
這樣逗點跟小數點都過濾掉了
我用jquery.validate.js作前端驗證,不過後端的驗證只有insert寫了,
在update事件忘了寫整數驗證
就那麼剛好user使用了update事件去塞了錯誤的內容
程式就當了
參考
http://blog.rebuildall.net/2011/03/02/jquery_validate_and_the_comma_decimal_separator
他是寫成js去include
我直接把他的方法寫在document ready事件裡面
然後正規表達式改成
//接受不限長度的整數
/^\d*$/
這樣逗點跟小數點都過濾掉了
標籤:
整數驗證,
javascript,
JQuery,
jquery.validate.js,
validate
2015年9月3日 星期四
Response.Write 在IE 10無法輸出檔案
網站有功能使用Response.Write去輸出EXCEL檔案
有客戶端IE按下按鈕後毫無反應
但是其他相同環境的客戶端卻沒有問題,正常運作
GOOGLE了老半天,什麼RESPONSE要用END還是CLOSE結尾、
HEADER的CONTENT TYPE要怎麼設定等等,
但是都無法解決
後來遠端過去看客戶端IE設定
發現是他勾選了安全性裡面的ActiveX篩選這個設定
取消掉後就正常了
有客戶端IE按下按鈕後毫無反應
但是其他相同環境的客戶端卻沒有問題,正常運作
GOOGLE了老半天,什麼RESPONSE要用END還是CLOSE結尾、
HEADER的CONTENT TYPE要怎麼設定等等,
但是都無法解決
後來遠端過去看客戶端IE設定
發現是他勾選了安全性裡面的ActiveX篩選這個設定
取消掉後就正常了

2015年7月23日 星期四
在MVC 實體資料模型Entity Framework Model加入Oracle 無PK的View的方法
markdown
我有個功能,主要參照的TABLE因為一些問題而沒有設定PK,但是又想用MVC EF來開發,
於是我照著MVC課程的做法,建了一個VIEW,裡面包了一個虛擬的PK值,
Oracle View做法: ``` select ROWNUM as ID,table1.* from table1 ```
結果跳ERROR2003錯誤,EF無法辨認哪個是PK,
我在虛擬ID的欄位使用了nvl(null,1) as ID、nvl(ROWNUM,1) as ID, ROWNUM as ID、
都還是一樣跳ERROR 2003,
後來有人建議我手動去編輯EDMX的XML,就編修了半天,終於成功帶出資料了
基本上就是複製其他的格式來用
EDMX有三大區塊
1.SSDL content 資料庫的TABLE
2.CSDL content 模型的TABLE
3.C-S mapping content 對照用的區塊
原本正常加入的模型,系統會自動產生這三大區塊的XML碼,
但是現在這個出錯的模型在xml只有加入SSDL區,而且還被註解
``` <!--錯誤 6013: 資料表/檢視 '' 未定義主索引鍵,也無法推斷有效的主索引鍵。此資料表/檢視已被排除。如果要使用此實體,您必須檢閱您的結構描述,加入正確的索引鍵,並將它取消註解。 <EntityType Name="my_view"> <Property Name="ID" Type="number" Precision="38" Scale="0" Nullable="false" /> <Property Name="ORDER_NUMBER" Type="nvarchar2" MaxLength="11" /> <Property Name="CORRECT_ORDER" Type="number" Precision="38" Scale="0" /> <Property Name="SEND_DATE" Type="nvarchar2" MaxLength="8" /> <Property Name="EM_ID" Type="nvarchar2" MaxLength="4" /> <Property Name="CM_ID" Type="nvarchar2" MaxLength="8" /> <Property Name="COST" Type="number" Precision="38" Scale="0" /> </EntityType>--> ```
現在把註解移除,加上KEY值
``` <EntityType Name="my_view"> <Key> <PropertyRef Name="ID" /> </Key> <Property Name="ID" Type="number" Precision="38" Scale="0" Nullable="false" /> <Property Name="ORDER_NUMBER" Type="nvarchar2" MaxLength="11" /> <Property Name="CORRECT_ORDER" Type="number" Precision="38" Scale="0" /> <Property Name="SEND_DATE" Type="nvarchar2" MaxLength="8" /> <Property Name="EM_ID" Type="nvarchar2" MaxLength="4" /> <Property Name="CM_ID" Type="nvarchar2" MaxLength="8" /> <Property Name="COST" Type="number" Precision="38" Scale="0" /> </EntityType> ```
EntityType 加上去後,要去SSDL區最後一塊EntityContainer裡面加上一行
``` <EntityContainer Name="ModelStoreContainer"> <EntitySet Name="table1" EntityType="Self.table1" Schema="myDB" store:Type="Tables" /> <EntitySet Name="table2" EntityType="Self.table2" Schema="myDB" store:Type="Tables" /> <EntitySet Name="table3" EntityType="Self.table3" Schema="myDB" store:Type="Tables" /> <!--這行--> <EntitySet Name="my_view" EntityType="Self.my_view" Schema="myDB" store:Type="Tables" /> </EntityContainer> ```
再來是CSDL的部分,這區系統就完全沒有產生XML了,同樣要填入EntityType 與EntityContainer,
但要注意的是這區的欄位Type是C#的型態,
例如number就是Decimal,nvarchar2就是String,
如果是String欄位,好像還要加上 FixedLength="true/false" Unicode="true/false"屬性
把前面SSDL的架構複製貼上到這區,並且修改TYPE為C#型態
``` <EntityType Name="my_view"> <Key> <PropertyRef Name="ID" /> </Key> <Property Name="ID" Type="Decimal" Precision="38" Scale="0" Nullable="false" /> <Property Name="ORDER_NUMBER" Type="String" MaxLength="11" FixedLength="false" Unicode="true" /> <Property Name="CORRECT_ORDER" Type="Decimal" Precision="38" Scale="0" /> <Property Name="SEND_DATE" Type="String" MaxLength="8" FixedLength="false" Unicode="true"/> <Property Name="EM_ID" Type="String" MaxLength="4" FixedLength="false" Unicode="true" /> <Property Name="CM_ID" Type="String" MaxLength="8" FixedLength="false" Unicode="true"/> <Property Name="COST" Type="Decimal" Precision="38" Scale="0" /> </EntityType> ```
再來同樣在EntityContainer加上一行
``` <EntityContainer Name="myDBEntities" annotation:LazyLoadingEnabled="true"> <EntitySet Name="table1" EntityType="Self.AS400_ZDF201" /> <EntitySet Name="table2" EntityType="Self.AS400_ZDF203" /> <EntitySet Name="table3" EntityType="Self.AS400_ZDF25A" /> <!--這行--> <EntitySet Name="my_view" EntityType="Self.my_view" /> </EntityContainer> ```
最後是CS-SS對應區,加上這個view的EntitySetMapping
``` <EntitySetMapping Name="my_view"> <EntityTypeMapping TypeName="Model.my_view"> <MappingFragment StoreEntitySet="my_view"> <ScalarProperty Name="ID" ColumnName="ID" /> <ScalarProperty Name="ORDER_NUMBER" ColumnName="ORDER_NUMBER" /> <ScalarProperty Name="CORRECT_ORDER" ColumnName="CORRECT_ORDER" /> <ScalarProperty Name="SEND_DATE" ColumnName="SEND_DATE" /> <ScalarProperty Name="EM_ID" ColumnName="EM_ID" /> <ScalarProperty Name="CM_ID" ColumnName="CM_ID" /> <ScalarProperty Name="COST" ColumnName="COST" /> </MappingFragment> </EntityTypeMapping> </EntitySetMapping> ```
然後F6編譯,雖然還是會出現ERROR2003,但是建立Controller之後我已經可以撈出資料了!
不過不知道這樣手動增加,之後還會跑出什麼問題...
我有個功能,主要參照的TABLE因為一些問題而沒有設定PK,但是又想用MVC EF來開發,
於是我照著MVC課程的做法,建了一個VIEW,裡面包了一個虛擬的PK值,
Oracle View做法: ``` select ROWNUM as ID,table1.* from table1 ```
結果跳ERROR2003錯誤,EF無法辨認哪個是PK,
我在虛擬ID的欄位使用了nvl(null,1) as ID、nvl(ROWNUM,1) as ID, ROWNUM as ID、
都還是一樣跳ERROR 2003,
後來有人建議我手動去編輯EDMX的XML,就編修了半天,終於成功帶出資料了
基本上就是複製其他的格式來用
EDMX有三大區塊
1.SSDL content 資料庫的TABLE
2.CSDL content 模型的TABLE
3.C-S mapping content 對照用的區塊
原本正常加入的模型,系統會自動產生這三大區塊的XML碼,
但是現在這個出錯的模型在xml只有加入SSDL區,而且還被註解
``` <!--錯誤 6013: 資料表/檢視 '' 未定義主索引鍵,也無法推斷有效的主索引鍵。此資料表/檢視已被排除。如果要使用此實體,您必須檢閱您的結構描述,加入正確的索引鍵,並將它取消註解。 <EntityType Name="my_view"> <Property Name="ID" Type="number" Precision="38" Scale="0" Nullable="false" /> <Property Name="ORDER_NUMBER" Type="nvarchar2" MaxLength="11" /> <Property Name="CORRECT_ORDER" Type="number" Precision="38" Scale="0" /> <Property Name="SEND_DATE" Type="nvarchar2" MaxLength="8" /> <Property Name="EM_ID" Type="nvarchar2" MaxLength="4" /> <Property Name="CM_ID" Type="nvarchar2" MaxLength="8" /> <Property Name="COST" Type="number" Precision="38" Scale="0" /> </EntityType>--> ```
現在把註解移除,加上KEY值
``` <EntityType Name="my_view"> <Key> <PropertyRef Name="ID" /> </Key> <Property Name="ID" Type="number" Precision="38" Scale="0" Nullable="false" /> <Property Name="ORDER_NUMBER" Type="nvarchar2" MaxLength="11" /> <Property Name="CORRECT_ORDER" Type="number" Precision="38" Scale="0" /> <Property Name="SEND_DATE" Type="nvarchar2" MaxLength="8" /> <Property Name="EM_ID" Type="nvarchar2" MaxLength="4" /> <Property Name="CM_ID" Type="nvarchar2" MaxLength="8" /> <Property Name="COST" Type="number" Precision="38" Scale="0" /> </EntityType> ```
EntityType 加上去後,要去SSDL區最後一塊EntityContainer裡面加上一行
``` <EntityContainer Name="ModelStoreContainer"> <EntitySet Name="table1" EntityType="Self.table1" Schema="myDB" store:Type="Tables" /> <EntitySet Name="table2" EntityType="Self.table2" Schema="myDB" store:Type="Tables" /> <EntitySet Name="table3" EntityType="Self.table3" Schema="myDB" store:Type="Tables" /> <!--這行--> <EntitySet Name="my_view" EntityType="Self.my_view" Schema="myDB" store:Type="Tables" /> </EntityContainer> ```
再來是CSDL的部分,這區系統就完全沒有產生XML了,同樣要填入EntityType 與EntityContainer,
但要注意的是這區的欄位Type是C#的型態,
例如number就是Decimal,nvarchar2就是String,
如果是String欄位,好像還要加上 FixedLength="true/false" Unicode="true/false"屬性
把前面SSDL的架構複製貼上到這區,並且修改TYPE為C#型態
``` <EntityType Name="my_view"> <Key> <PropertyRef Name="ID" /> </Key> <Property Name="ID" Type="Decimal" Precision="38" Scale="0" Nullable="false" /> <Property Name="ORDER_NUMBER" Type="String" MaxLength="11" FixedLength="false" Unicode="true" /> <Property Name="CORRECT_ORDER" Type="Decimal" Precision="38" Scale="0" /> <Property Name="SEND_DATE" Type="String" MaxLength="8" FixedLength="false" Unicode="true"/> <Property Name="EM_ID" Type="String" MaxLength="4" FixedLength="false" Unicode="true" /> <Property Name="CM_ID" Type="String" MaxLength="8" FixedLength="false" Unicode="true"/> <Property Name="COST" Type="Decimal" Precision="38" Scale="0" /> </EntityType> ```
再來同樣在EntityContainer加上一行
``` <EntityContainer Name="myDBEntities" annotation:LazyLoadingEnabled="true"> <EntitySet Name="table1" EntityType="Self.AS400_ZDF201" /> <EntitySet Name="table2" EntityType="Self.AS400_ZDF203" /> <EntitySet Name="table3" EntityType="Self.AS400_ZDF25A" /> <!--這行--> <EntitySet Name="my_view" EntityType="Self.my_view" /> </EntityContainer> ```
最後是CS-SS對應區,加上這個view的EntitySetMapping
``` <EntitySetMapping Name="my_view"> <EntityTypeMapping TypeName="Model.my_view"> <MappingFragment StoreEntitySet="my_view"> <ScalarProperty Name="ID" ColumnName="ID" /> <ScalarProperty Name="ORDER_NUMBER" ColumnName="ORDER_NUMBER" /> <ScalarProperty Name="CORRECT_ORDER" ColumnName="CORRECT_ORDER" /> <ScalarProperty Name="SEND_DATE" ColumnName="SEND_DATE" /> <ScalarProperty Name="EM_ID" ColumnName="EM_ID" /> <ScalarProperty Name="CM_ID" ColumnName="CM_ID" /> <ScalarProperty Name="COST" ColumnName="COST" /> </MappingFragment> </EntityTypeMapping> </EntitySetMapping> ```
然後F6編譯,雖然還是會出現ERROR2003,但是建立Controller之後我已經可以撈出資料了!
不過不知道這樣手動增加,之後還會跑出什麼問題...
標籤:
asp.NET,
Entity Framework,
Model,
MVC,
Oracle,
Primary Key,
View
2015年7月14日 星期二
System.Data.OracleClient與Oracle.DataAccess的變數問題
System.Data.OracleClient跟Oracle.DataAccess.dll 好像對變數的處理不一樣
我有一個查詢語法,日期處理是
跳出ORA-01008 : Not all variables bound
我要把後面的變數換個名稱,加入兩次變數,才能正常執行
我有一個查詢語法,日期處理是
DATE between to_date(:DATE || ' 00:00:00','yyyy-mm-dd hh24:mi:ss') and TO_DATE(:DATE || ' 23:59:59','yyyy-mm-dd hh24:mi:ss')
在用前者的時候變數只需要加入一次
Command.Parameters.Add(new OracleParameter("DATE", DATE));
但在用後者的時候,後面那個變數會被認為未給值,跳出ORA-01008 : Not all variables bound
我要把後面的變數換個名稱,加入兩次變數,才能正常執行
DATE between to_date(:DATE || ' 00:00:00','yyyy-mm-dd hh24:mi:ss') and TO_DATE(:DATE2 || ' 23:59:59','yyyy-mm-dd hh24:mi:ss')
Command.Parameters.Add(new OracleParameter("DATE", DATE));
Command.Parameters.Add(new OracleParameter("DATE2", DATE));
不過同樣的sql在oracle sql developer執行,他也只會要我輸入一次變數值就是了
2015年6月24日 星期三
oracle 找一筆找不到的資料 oracle find null record
假設資料表有一個欄位 10筆資料 數值為1~10
下查詢 WHERE 此欄位=11
就會回傳0列
但想要他回傳0列時顯示某字串
就先套一個max 再去套nvl 或decode之類的case功能
下查詢 WHERE 此欄位=11
就會回傳0列
但想要他回傳0列時顯示某字串
就先套一個max 再去套nvl 或decode之類的case功能
select nvl(max(column),'0') AS something from table
where 不能找到資料的條件
2015年6月18日 星期四
WEB METHOD JSON MAX LENGTH
使用JSON.NET來轉換物件為JSON
STRING出來了但是WEBMETHOD丟出去時說太大
在WEB.CONFIG加入此設定值就可以提高上限了
STRING出來了但是WEBMETHOD丟出去時說太大
在WEB.CONFIG加入此設定值就可以提高上限了
<configuration>
<system .web.extensions="">
<scripting>
<webservices>
<jsonserialization maxjsonlength="2147483644">
</jsonserialization></webservices>
</scripting>
</system>
</configuration>
標籤:
asp.NET,
C#,
JSON.NET,
JsonMaxLength
2015年6月8日 星期一
2015年5月22日 星期五
ORACLE在C# 執行多行指令的方法
我要刪除一個資料,順便刪除相關的資料表中屬於此資料SID的資料
但是一直執行SQL也很煩,找了可以一次執行多行的寫法
重點是要用分號隔開
StringBuilder sb = new StringBuilder();
sb.Append(@"BEGIN
delete from table1 where SID=:SID ;
delete from table2 where SID=:SID ;
delete from table3 where SID=:SID ;
delete from table4 where SID=:SID ;
delete from table5 where SID=:SID ;
END;
");
try
{
cnn.Open();
using (OracleCommand cmm = new OracleCommand(sb.ToString(), cnnTSTM))
{
cmm.Parameters.Clear();
cmm.Parameters.Add(new OracleParameter("SID", SID));
cmm.ExecuteNonQuery();
}
cnn.Close();
}
但是一直執行SQL也很煩,找了可以一次執行多行的寫法
重點是要用分號隔開
StringBuilder sb = new StringBuilder();
sb.Append(@"BEGIN
delete from table1 where SID=:SID ;
delete from table2 where SID=:SID ;
delete from table3 where SID=:SID ;
delete from table4 where SID=:SID ;
delete from table5 where SID=:SID ;
END;
");
try
{
cnn.Open();
using (OracleCommand cmm = new OracleCommand(sb.ToString(), cnnTSTM))
{
cmm.Parameters.Clear();
cmm.Parameters.Add(new OracleParameter("SID", SID));
cmm.ExecuteNonQuery();
}
cnn.Close();
}
2015年5月11日 星期一
用ExchangeService API (EWS) 確認EMAIL信箱位址是否存在
string sResult = "";
List<string> emailCollect = new List<string>();
ExchangeService es = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
es.Credentials = new System.Net.NetworkCredential("ACCOUNT", "PASSWORD", "NETAREA");
es.Url = new Uri("https://MYWEBSITE/ews/Exchange.asmx");
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
var resolvedNames = es.ResolveName("想找的姓名或帳號");
foreach (var resolvedName in resolvedNames)
{
emailCollect.Add(resolvedName.Mailbox.Address);
}
if (emailCollect.Count > 0)
{
sResult = emailCollect[0].ToString().Trim();
Console.WriteLine(sResult);
}
else
Console.WriteLine("找不到信箱!");
List<string> emailCollect = new List<string>();
ExchangeService es = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
es.Credentials = new System.Net.NetworkCredential("ACCOUNT", "PASSWORD", "NETAREA");
es.Url = new Uri("https://MYWEBSITE/ews/Exchange.asmx");
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
var resolvedNames = es.ResolveName("想找的姓名或帳號");
foreach (var resolvedName in resolvedNames)
{
emailCollect.Add(resolvedName.Mailbox.Address);
}
if (emailCollect.Count > 0)
{
sResult = emailCollect[0].ToString().Trim();
Console.WriteLine(sResult);
}
else
Console.WriteLine("找不到信箱!");
標籤:
找信箱是否存在,
C#,
EWS,
ExchangeService
2015年5月5日 星期二
RDLC 文字方塊 增大 超出
發現一張表的文字方塊有的超出寬度與高度後會撐大,
有的只會換行然後超出邊界的部分就截掉
解決方式
文字方塊右鍵→屬性→一般頁面裡的[調整大小選項]把允許高度增加給取消打勾就好了
有的只會換行然後超出邊界的部分就截掉
解決方式
文字方塊右鍵→屬性→一般頁面裡的[調整大小選項]把允許高度增加給取消打勾就好了
2015年4月28日 星期二
SQL SERVER 寫入 更新 TIMEOUT
今天排程發生INSERT時SQLSERVER TIMEOUT的錯誤訊息
但是DB主機正常運作,SMSS也可連線
資料表也可以選取檢視
直接對資料表操作新增資料或更新資料都會出現TIMEOUT逾時訊息
後來發現是LOG檔案滿了,上限29G,已經達到27.XG,成長率又是10%,再加上去就滿了
把LOG檔案清掉後,資料就正常寫入了
詢問之下,避免後患的做法
1.LOG檔案用簡單就好
2.定期要備份LOG檔案並清除
但是DB主機正常運作,SMSS也可連線
資料表也可以選取檢視
直接對資料表操作新增資料或更新資料都會出現TIMEOUT逾時訊息
後來發現是LOG檔案滿了,上限29G,已經達到27.XG,成長率又是10%,再加上去就滿了
把LOG檔案清掉後,資料就正常寫入了
詢問之下,避免後患的做法
1.LOG檔案用簡單就好
2.定期要備份LOG檔案並清除
標籤:
資料庫LOG,
逾時,
INSERT,
SQL SERVER,
TIMEOUT
2015年4月22日 星期三
textarea focus 在最後面
textarea有一串定型字串與提示字串
focus之後要移掉提示字串但是游標要在最後面
原本
$("#textarea").focus(function () {
if( $(this).val()=='定型字串:(提示字串)')
$(this).val('定型字串');
});
結果效果變成focus後游標會跑到最前面去
改用jquery的focusin事件就解決了
$("#textarea").focusin(function () {
if( $(this).val()=='定型字串:(提示字串)')
$(this).val('定型字串');
});
focus之後要移掉提示字串但是游標要在最後面
原本
$("#textarea").focus(function () {
if( $(this).val()=='定型字串:(提示字串)')
$(this).val('定型字串');
});
結果效果變成focus後游標會跑到最前面去
改用jquery的focusin事件就解決了
$("#textarea").focusin(function () {
if( $(this).val()=='定型字串:(提示字串)')
$(this).val('定型字串');
});
標籤:
html,
javascript,
JQuery
2015年4月10日 星期五
RDLC 報表匯出PDF 全形數字亂碼
RDLC匯出PDF時遇到地址欄位裡的全形數字變成框框符號的亂碼
解決方式:把該變數文字方塊字形設定為中文,如新細明體,預設是Arial
就可以解決了
解決方式:把該變數文字方塊字形設定為中文,如新細明體,預設是Arial
就可以解決了
標籤:
匯出PDF,
asp.NET,
RDLC,
Report View
2015年3月31日 星期二
SPA專案架構
MVC書一次都教一堆東西...
RAZOR語法、實體資料庫模型、LINQ語法、IENUMERABLE型態...
實在有點懶的學
20150403補充:原來這個叫做SPA架構
前輩教的類MVC架構
1.Modal-就只是個Modal,放屬性欄位而已
2.DAL-資料庫存取相關功能(Data Access Level)
3.主要專案-前端功能
應用在網站專案、Console專案、winform等等都可
1.Visuao Studio建立空白解決方案
2.建立類別庫專案-Modal,想到再加入類別即可
3.建立類別庫專案-DAL
4.建立主要專案,以一般ASP.NET網站專案為例
網站專案加入參考Modal與DAL
DAL加入Modal參考
Modal不參考任何專案,獨立
5.假設要做一個客戶主檔維護功能,有新增刪除修改顯示(CRUD)基本功能
客戶主檔資料表:
SID、客戶名稱、客戶電話三個欄位就好
Modal底下建立客戶主檔類別
public class Customer
{
///<summary>流水號</summary>
public int SID{get;set;}
///<summary>客戶名稱</summary>
public string Name {get;set;}
///<summary>客戶電話</summary>
public string PhoneNumber {get;set;}
}
新增、更新、刪除時的訊息類別
public class msgCRUD
{
public static const string STATUS_SUCCESS="success";
public static const string STATUS_ERROR="error";
public string status {get;set;}
public string msg {get;set;}
}
DAL底下建立類別
using Modal;
public class CustomerController
{
public List<Customer> searchData(out msgCRUD msg)
{
msg=new msgCRUD();
List<Customer> list=new List<Customer>();
DataTable dt=new DataTable();
try
{
//資料庫處理,結果塞到DataTable
if(dt.Rows.Count>0)
{
foreach(DataRow dr in dt.Rows)
{
list.Add(new Customer(){
SID = dr["SID"].ToString(),
Name = dr["Name"].ToString(),
PhoneNumber = dr["PhoneNumber"].ToString()
});
}
}
}
catch(Exception ex)
{
msg.status=msgCRUD.STATUS_ERROR;
msg.msg="搜尋時發生錯誤:"+ex.ToString();
}
return list;
}
}
網站專案底下建立ASP網頁
後端Customer.aspx.cs
[WebMethod]
protected string searchData()
{
CustomerController cc=new CustomerController();
List<Customer> list=cc.searchData();
string myJson=JsonConvert.SerializeObject(list);
return myJson;
}
前端Customer.aspx
使用JQuery AJAX語法取得資料
...
</form>
<script type="javascript">
function searchData()
{
if (!window.ajaxValidPass) {
var sdata = { };
$.ajax({
type: "POST",
async: true,
url: "Customer.aspx/searchData",
data: JSON.stringify(sdata),
contentType: "application/json; charset=UTF-8",
dataType: 'json',
success: function (data) {
var ary = $.parseJSON(data.d);
if (ary) {
//處理撈回來的東西
}
else {
alert('找不到資料');
}
}
},
error: function (response) {
console.log('error:' + response.responseText);
alert('error:' + response.responseText);
}
});
}
}
</script>
到此即為基本的前端到後端,後端到資料存取層的資料傳輸方式
可以擺脫Server Control夾帶的垃圾CODE
又可以保持架構上的彈性
RAZOR語法、實體資料庫模型、LINQ語法、IENUMERABLE型態...
實在有點懶的學
20150403補充:原來這個叫做SPA架構
前輩教的
1.Modal-就只是個Modal,放屬性欄位而已
2.DAL-資料庫存取相關功能(Data Access Level)
3.主要專案-前端功能
應用在網站專案、Console專案、winform等等都可
1.Visuao Studio建立空白解決方案
2.建立類別庫專案-Modal,想到再加入類別即可
3.建立類別庫專案-DAL
4.建立主要專案,以一般ASP.NET網站專案為例
網站專案加入參考Modal與DAL
DAL加入Modal參考
Modal不參考任何專案,獨立
5.假設要做一個客戶主檔維護功能,有新增刪除修改顯示(CRUD)基本功能
客戶主檔資料表:
SID、客戶名稱、客戶電話三個欄位就好
Modal底下建立客戶主檔類別
public class Customer
{
///<summary>流水號</summary>
public int SID{get;set;}
///<summary>客戶名稱</summary>
public string Name {get;set;}
///<summary>客戶電話</summary>
public string PhoneNumber {get;set;}
}
新增、更新、刪除時的訊息類別
public class msgCRUD
{
public static const string STATUS_SUCCESS="success";
public static const string STATUS_ERROR="error";
public string status {get;set;}
public string msg {get;set;}
}
DAL底下建立類別
using Modal;
public class CustomerController
{
public List<Customer> searchData(out msgCRUD msg)
{
msg=new msgCRUD();
List<Customer> list=new List<Customer>();
DataTable dt=new DataTable();
try
{
//資料庫處理,結果塞到DataTable
if(dt.Rows.Count>0)
{
foreach(DataRow dr in dt.Rows)
{
list.Add(new Customer(){
SID = dr["SID"].ToString(),
Name = dr["Name"].ToString(),
PhoneNumber = dr["PhoneNumber"].ToString()
});
}
}
}
catch(Exception ex)
{
msg.status=msgCRUD.STATUS_ERROR;
msg.msg="搜尋時發生錯誤:"+ex.ToString();
}
return list;
}
}
網站專案底下建立ASP網頁
後端Customer.aspx.cs
[WebMethod]
protected string searchData()
{
CustomerController cc=new CustomerController();
List<Customer> list=cc.searchData();
string myJson=JsonConvert.SerializeObject(list);
return myJson;
}
前端Customer.aspx
使用JQuery AJAX語法取得資料
...
</form>
<script type="javascript">
function searchData()
{
if (!window.ajaxValidPass) {
var sdata = { };
$.ajax({
type: "POST",
async: true,
url: "Customer.aspx/searchData",
data: JSON.stringify(sdata),
contentType: "application/json; charset=UTF-8",
dataType: 'json',
success: function (data) {
var ary = $.parseJSON(data.d);
if (ary) {
//處理撈回來的東西
}
else {
alert('找不到資料');
}
}
},
error: function (response) {
console.log('error:' + response.responseText);
alert('error:' + response.responseText);
}
});
}
}
</script>
到此即為基本的前端到後端,後端到資料存取層的資料傳輸方式
可以擺脫Server Control夾帶的垃圾CODE
又可以保持架構上的彈性
2015年3月27日 星期五
LOG功能
public void myLog(string format, params object[] arg)
{
myLog(string.Format(format, arg));
}
/// <summary> log寫入text檔案 </summary>
/// <param name="message"></param>
public void myLog(string message)
{
//取得執行檔案(BIN/DEBUG)的路徑,加上LOG資料夾形成完整路徑
string loaclpath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string path = Path.Combine(Path.GetFullPath(loaclpath), "log");
if (string.IsNullOrEmpty(path))
{
path = Directory.GetCurrentDirectory();
}
string filename = Path.Combine(path, string.Format("{0:yyyy}\\{0:MM}\\{0:yyyy-MM-dd}.txt", DateTime.Now));
FileInfo finfo = new FileInfo(filename);
if (finfo.Directory.Exists == false)
{
finfo.Directory.Create();
}
string writeString = string.Format("[{0:yyyy/MM/dd HH:mm:ss}] {1}",
DateTime.Now, message) + Environment.NewLine;
File.AppendAllText(filename, writeString, Encoding.Unicode);
}
{
myLog(string.Format(format, arg));
}
/// <summary> log寫入text檔案 </summary>
/// <param name="message"></param>
public void myLog(string message)
{
//取得執行檔案(BIN/DEBUG)的路徑,加上LOG資料夾形成完整路徑
string loaclpath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string path = Path.Combine(Path.GetFullPath(loaclpath), "log");
if (string.IsNullOrEmpty(path))
{
path = Directory.GetCurrentDirectory();
}
string filename = Path.Combine(path, string.Format("{0:yyyy}\\{0:MM}\\{0:yyyy-MM-dd}.txt", DateTime.Now));
FileInfo finfo = new FileInfo(filename);
if (finfo.Directory.Exists == false)
{
finfo.Directory.Create();
}
string writeString = string.Format("[{0:yyyy/MM/dd HH:mm:ss}] {1}",
DateTime.Now, message) + Environment.NewLine;
File.AppendAllText(filename, writeString, Encoding.Unicode);
}
2015年3月24日 星期二
Oracle SQL decode中文字變成問號
用程式下SQL
Table1
----------
1
2
3
4
5
select col1,
decode(col1,'1','型態1',''2','型態2','3','型態3','4','型態4','XX')
結果data row裡面看,中文都變成"??"
解決方式:
在連線字串裡面加上Unicode=True
就解決了
Table1
----------
1
2
3
4
5
select col1,
decode(col1,'1','型態1',''2','型態2','3','型態3','4','型態4','XX')
結果data row裡面看,中文都變成"??"
解決方式:
在連線字串裡面加上Unicode=True
就解決了
訂閱:
文章 (Atom)