2018年10月24日 星期三

DataTable

寫入DataTable
Dim dt As New DataTable()
dt.Columns.Add("date")
dt.Columns.Add("num")

Dim row As DataRow = dt.NewRow()
row("date") = "2018/12/12"
row("num") = "1200"
dt.Rows.Add(row)

----或----
Dim dt As New DataTable()
dt.Columns.Add("date")
dt.Columns.Add("num")

dt.Rows.Add("2018/12/12","1200")


字串寫入陣列
Dim array_p As New ArrayList
For i As Integer = 0 To distTable.Rows.Count - 1
        array_p.Add(distTable(i)("WO_NUMBER"))
Next

取DataTable裡某欄位不重覆資料
Dim dv As DataView = Lv_dt_D.DefaultView
Dim distTable As DataTable = dv.ToTable(True, "WO_NUMBER")


Dim Lv_dtGroup As DataTable = DTABLE.DefaultView.ToTable(True, "MCT_CUR_WO")

取DataTable的篩選條件
Dim find_rows As DataRow() = Lv_dt_D_b.Select("WO_NUMBER='" & array_p(j) & "'")

取DataTable某欄位的最大值
Dim v_max_seq As Integer = v_dt1.Compute("Max(SEQ)", "")

取DataTable進行條件加總

DTABLE.Compute("Sum(MCT_CUR_QTY)", "MCT_CUR_WO='" & Lv_dtGroup(i)("MCT_CUR_WO") & "'")

將欄位值轉數字型態
 Dim v_dt1 As New DataTable
v_dt1.Columns.Add("SEQ")

v_dt1.Columns("SEQ").DataType = System.Type.GetType("System.Int32")

DataTable排序
dt.DefaultView.Sort = "AG DESC"

dt= dt.DefaultView.ToTable()


DataTable 欄位名稱變更
dt.Columns("DOCNO").ColumnName = "合約編號"

NameValueCollection 集合 [字典]
字串字典,只能使用字串,如果你操作的對象是字串,那這個類別絕對是你的首選,因為它可以省下轉型的動作。 
NameValueCollection 特性如下: 
1.一個索引鍵(Key)對應到多個內容(Value),不同於StringCollection。 
2.用GetValues方法取得的值是陣列型態,所以在處理上要小心。

Dim nvc As NameValueCollection = New NameValueCollection()
        nvc.Add("MES3002PJ_F1_A5_MAIN", "Form1")
        nvc.Add("MES3002PJ_F2_B5_MAIN", "Form2")
        nvc.Add("MES3002PJ_F3_A5_MAIN", "Form3")
        nvc.Add("MES3002PJ_F4_B5_MAIN", "Form4")

        Dim formName As String = Nothing
        For i As Integer = 0 To nvc.Count - 1
            If nvc.Keys(i) = name Then
                formName = nvc(i)
            End If

        Next

2018年10月15日 星期一

鼠标移上某行顯示浮动DIV提示信息

CSS
.show
        {
            z-index:9999;
            position:fixed;

        }

body
<p onmouseover="mover(this,'.....')">Text</p>

<div id='kk'>
    ......
</div>

javascript
function mover(event, val) {
            var div = document.getElementById("kk");
            var event = window.event || event;
            div.style.left = 10 + event.clientX + "px";//"px"必须
            div.style.top = 10 + event.clientY + "px";//"px"必须
            div.innerHTML = val;
            div.className = "show";
        }
        function out() {
            document.getElementById("kk").className = "none";
}

2018年7月3日 星期二

數字欄位小數點超過兩位,則取到小數第二位,若不足小數兩位,則顯示原數字。

數字欄位小數點超過兩位,則取到小數第二位,若不足小數兩位,則顯示原數字。
select name,
                                      case when substr(to_char(floor(attribute1*100)/100),1,1) = '.'  
                                                then '0'||to_char(floor(attribute1*100)/100) 
                                           when substr(to_char(floor(attribute1*100)/100),1,2) = '-.' 
                                                then replace(to_char(floor(attribute1*100)/100),'-.','-0.')
                                           else to_char(floor(attribute1*100)/100) end attribute1,
                                      case when substr(to_char(floor(attribute2*100)/100),1,1) = '.' 
                                                then '0'||to_char(floor(attribute2*100)/100)
                                           when substr(to_char(floor(attribute2*100)/100),1,2) = '-.'
                                                then replace(to_char(floor(attribute2*100)/100),'-.','-0.')
                                           else to_char(floor(attribute2*100)/100) end attribute2,
                                      case when substr(to_char(floor(attribute3*100)/100),1,1) = '.' 
                                                then '0'||to_char(floor(attribute3*100)/100)
                                           when substr(to_char(floor(attribute3*100)/100),1,2) = '-.'
                                                then replace(to_char(floor(attribute3*100)/100),'-.','-0.')
                                           else to_char(floor(attribute3*100)/100) end attribute3,
                                      case when substr(to_char(floor(attribute4*100)/100),1,1) = '.' 
                                                then '0'||to_char(floor(attribute4*100)/100)
                                           when substr(to_char(floor(attribute4*100)/100),1,2) = '-.'
                                                then replace(to_char(floor(attribute4*100)/100),'-.','-0.')
                                           else to_char(floor(attribute4*100)/100) end attribute4,
                                      attribute6,to_char(date1,'yyyy/MM/dd') date1,to_char(date2,'yyyy/MM/dd') date2
                                 from szs_web_item_content
                                where code='SZSWEB_DIVIDEND_INFORMATION'
                                  and org_id=:org_id and sys_id=:sys_id
                                order by to_number(name) desc

2018年1月25日 星期四

ASP.NET 中 C# VB 於同一專案 App_Code 目錄內並存

ASP.NET 中 C# VB 於同一專案 App_Code 目錄內並存
兩者在一般的並存上其實不會有問題

但如果在 App_Code 內要同時存在時就會噴錯給你看


解決方法是在Web.Config 內加入如下

<compilation debug="true" strict="false" explicit="true" targetFramework="4.0">
  <codeSubDirectories>
    <add directoryName="CSApp_Code"/>
  </codeSubDirectories>
</compilation>

把原本的 VB 依舊放在 App_Code 下 C# 則放在 App_Code/CSApp_Code 下面

或者是可以另外 <add directoryName="VBApp_Code"/>

然後把 VB 也收好放在 App_Code/VBApp_Code 下


from:http://jumping-fun.blogspot.tw/2013/06/aspnet-c-vb-appcode.html

2017年11月5日 星期日

[Excel]

找出兩欄的差異值
=IF(COUNTIF(A:A,B2)>0,"相同","不相同")    <=B表姓名值是否出現在A表中?
=IF(COUNTIF(B:B,A2)>0,"相同","不相同")    <=A表姓名值是否出現在B表中?


2017年10月20日 星期五

[ASP.NET] vb.net call javascript function

vb.net call javascript function

一、
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:openUserAppSetting();return false;" />

二、
<asp:Button ID="but_save" runat="server" Text="提交變更" class="btn btn-primary"  OnClientClick="return openUserAppSetting();"/>

<asp:Button id="Button2" runat="server" Text="XD" OnClientClick="closeUserAppSetting();" OnClick="Button2_Click"  UseSubmitBehavior="false" />
OnClientClick會在onclick之前執行

三、
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "", "showDisplay()", True)
ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "showDisplay();", True)

<script type="text/javascript">
        function openUserAppSetting() {
            $('#userAppSetting').skygqbox();
        }

        function closeUserAppSetting() {
            $('#userAppSetting').hide();
        }
</script>



HTML/javascript call vb function

[ HTML ]
<td onclick="callServersideFunction()">日期</td>

[ javascript ]
//call vb function
 function callServersideFunction() {
         var someValueToPass = name;
          __doPostBack('CustomPostBack', someValueToPass);

}

[ vb ]
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ' Insure that the __doPostBack() JavaScript method is created...
    Me.ClientScript.GetPostBackEventReference(Me, String.Empty)

    'If IsPostBack = False Then
    Dim eventTarget As String = ""
    Dim eventArgument As String = ""

    If Request("__EVENTTARGET") Is Nothing Then
        eventTarget = String.Empty
    Else
        eventTarget = Request("__EVENTTARGET")
    End If

    If Request("__EVENTARGUMENT") Is Nothing Then
        eventArgument = String.Empty
    Else
        eventArgument = Request("__EVENTARGUMENT")
    End If

    If eventTarget = "CustomPostBack" Then
        Dim valuePassed As String = eventArgument
        ' there call function....
    End If
    ' End If

End Sub







[ASP.NET]判斷要寫入的資料是否與資料表相同,若不相同才進行更新

Function IsRowModified_u(ByVal r As GridViewRow) As Boolean
        Dim Curr_OrgID As String
        Dim Curr_HomoID As String
        Dim Curr_LineNum As String
        Dim lv_RadioButtonList As String
        Dim lv_HAZARDOUS_VALUE As String
        Dim lv_REASON As String

        Curr_OrgID = CType(r.FindControl("lb_org_id"), Label).Text 'Convert.ToInt32(GridView1.DataKeys(0).Value)
        Curr_HomoID = CType(r.FindControl("lb_HOMOGENOUS_MAT_ID"), Label).Text
        Curr_LineNum = CType(r.FindControl("lb_LINE_NUM"), Label).Text

        lv_RadioButtonList = CType(r.FindControl("RadioButtonList1"), RadioButtonList).Text
        lv_HAZARDOUS_VALUE = CType(r.FindControl("tb_HAZARDOUS_VALUE"), TextBox).Text
        lv_REASON = CType(r.FindControl("tb_REASON"), TextBox).Text

        Dim row As DataRow = originalDataTable_u.[Select]([String].Format("org_id = {0} and HOMOGENOUS_MAT_ID={1} and line_num={2}", Curr_OrgID, Curr_HomoID, Curr_LineNum))(0)

        If lv_RadioButtonList.Equals(row("INCLUDE_YN").ToString()) = True And _
            lv_HAZARDOUS_VALUE.Equals(row("HAZARDOUS_VALUE").ToString()) = True And _
            lv_REASON.Equals(row("REASON").ToString()) = True Then
            Return True
        Else
            Return False
        End If

        'Return False
    End Function