加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Vb.Net程序设计:代码片段集

发布时间:2020-12-16 22:44:41 所属栏目:大数据 来源:网络整理
导读:'回车键,跳格,并选中内容。 Private Sub FrmFiber_KeyPress(ByVal sender As System.Object,ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress If e.KeyChar = ChrW(Keys.Enter) Then Me.SelectNextControl(Me.ActiveControl,T

'回车键,跳格,并选中内容。

Private Sub FrmFiber_KeyPress(ByVal sender As System.Object,ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress

If e.KeyChar = ChrW(Keys.Enter) Then
Me.SelectNextControl(Me.ActiveControl,True,False,True)
If TypeOf Me.ActiveControl Is TextBox Then
Dim ctlTextBox As TextBox = CType(Me.ActiveControl,TextBox)
If String.IsNullOrEmpty(ctlTextBox.Text) = False Then
ctlTextBox.SelectAll()
End If
End If
End If

End Sub


'对两个Datatable的结构相同进行合并:

Dim db As Datatable = Nothing
Dim dt As DataTable = ds.Tables(0)
'''/两个datatable进行合并
db = dt.Copy()
Dim foundRows As DataRow() = dt.Select()
For i As Integer = 0 To foundRows.Length - 1
db.ImportRow(foundRows(i))
Next


'两个结构一样的DT合并
Dim DataTable1 As New DataTable()
Dim DataTable2 As New DataTable()
Dim newDataTable As DataTable = DataTable1.Clone()

Dim obj As Object() = New Object(newDataTable.Columns.Count - 1) {}
For i As Integer = 0 To DataTable1.Rows.Count - 1
DataTable1.Rows(i).ItemArray.CopyTo(obj,0)
newDataTable.Rows.Add(obj)
Next

For i As Integer = 0 To DataTable2.Rows.Count - 1
DataTable2.Rows(i).ItemArray.CopyTo(obj,0)
newDataTable.Rows.Add(obj)
Next


Private Sub BtnExeQuery_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles BtnExeQuery.Click

Dim cd As String
Dim cmd As New SqlClient.SqlCommand
Dim strWhere As String = String.Empty
cd = " and "
If String.IsNullOrEmpty(Me.TxtLotNo.Text.Trim) = False Then
strWhere &= (IIf(String.IsNullOrEmpty(strWhere),"",cd) & "strLotNo like (@strLotNo)")
cmd.Parameters.Add(New SqlClient.SqlParameter("@strLotNo",Me.TxtLotNo.Text.Trim & "%"))
End If
If String.IsNullOrEmpty(Me.TxtColorNo.Text.Trim) = False Then
strWhere &= (IIf(String.IsNullOrEmpty(strWhere),cd) & "strItemName like (@strItemName)")
cmd.Parameters.Add(New SqlClient.SqlParameter("@strItemName",Me.TxtColorNo.Text.Trim & "%"))
End If

If String.IsNullOrEmpty(Me.TxtPly.Text.Trim) = False Then
strWhere &= (IIf(String.IsNullOrEmpty(strWhere),cd) & "lngPly = (@lngPly)")
cmd.Parameters.Add(New SqlClient.SqlParameter("@lngPly",CInt(Me.TxtPly.Text.Trim)))
End If


If String.IsNullOrEmpty(Me.TxtYarnCount.Text.Trim) = False Then
strWhere &= (IIf(String.IsNullOrEmpty(strWhere),cd) & "dblYarnCount = (@dblYarnCount)")
cmd.Parameters.Add(New SqlClient.SqlParameter("@dblYarnCount",CDbl(Me.TxtYarnCount.Text.Trim)))
End If

If String.IsNullOrEmpty(Me.TxtMoistureRegain.Text.Trim) = False Then
strWhere &= (IIf(String.IsNullOrEmpty(strWhere),cd) & "dblMoistureRegain = (@dblMoistureRegain)")
cmd.Parameters.Add(New SqlClient.SqlParameter("@dblMoistureRegain",CDbl(Me.TxtMoistureRegain.Text.Trim)))
End If

If Me.CboWarehouseID.SelectedIndex > -1 Then
strWhere &= (IIf(String.IsNullOrEmpty(strWhere),cd) & "intWarehouseID = (@intWarehouseID)")
cmd.Parameters.Add(New SqlClient.SqlParameter("@intWarehouseID",CInt(Me.CboWarehouseID.SelectedValue)))
End If

If Me.ChkDeliveryDate.Checked Then
strWhere &= (IIf(String.IsNullOrEmpty(strWhere),cd) & "dtmDelivery = (@dtmDelivery)")
cmd.Parameters.Add(New SqlClient.SqlParameter("@dtmDelivery",Me.dtmDeliveryDate.Value.Date))
End If


cmd.CommandText = "select " & strLotFields & " from tblLot where strStatus<>'Void' and " & IIf(String.IsNullOrEmpty(strWhere),"1=1",strWhere)
'cmd.CommandText ="sp_QueryItem"
'cmd.CommandType = CommandType.StoredProcedure
tblQuery = SQLHelper.GetDataTable(cmd)
BindDv(tblQuery)
End Sub

自定义控件鼠标滑动动态效果-边框颜色

Imports System.Drawing

Public Class UserControl1

    Private Sub UserControl1_MouseHover(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.MouseHover
        Using g As Graphics = Graphics.FromHwnd(Me.Handle)
            g.DrawRectangle(Pens.Blue,Me.Width - 1,Me.Height - 1)
        End Using
    End Sub

    Private Sub UserControl1_MouseLeave(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.MouseLeave
        Using g As Graphics = Graphics.FromHwnd(Me.Handle)
            g.DrawRectangle(New Pen(Me.BackColor),Me.Height - 1)
        End Using
    End Sub

End Class

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读