平时积累的东西

以下是本人在学习 工作中,总结出来的,觉得对自己在开发过程中比较有用的东西:

 

1:播放音乐

Private Declare Auto Function PlaySound Lib "winmm.dll" (ByVal lpszSoundName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer

    Const SND_filename As Integer = &H20000

    Const SND_alias As Integer = &H10000

    Const SND_sync As Integer = &H0

    Declare Auto Function waveOutGetNumDevs Lib "winmm.dll" Alias "waveOutGetNumDevs" () As Integer

    Declare Auto Function sndPlaySound Lib "winmm.dll" (ByVal filename As String, ByVal options As Integer) As Integer

    Private Const SND_memory As Integer = &H4

    Private Const SND_async As Integer = &H1

    Private Const proess_domain As String = ""

    Const SND_sync1 = &H0

    Const SND_async1 = &H1

    Const SND_nodefault = &H2

    Const SND_loop = &H8

Const SND_nostop = &H10

 

 

使用

    'Dim cou As Integer

                    'Dim le As String = Me.DsIPQC1.qc.Rows(i).Item(2)

                    'Dim ret As Long

                    'Dim strfilename As String

                    'strfilename = System.Windows.Forms.Application.StartupPath & "/sound/att.wav"

                    'ret = sndPlaySound(strfilename.ToCharArray, 0)

                    'For cou = 0 To le.Length - 1

                    '    'name = System.Windows.Forms.Application.StartupPath & "/sound/0.wav"     '" & le.Chars(cou) & "

                    '    'sndPlaySound(name.ToCharArray, 0)

 

                    '    strfilename = System.Windows.Forms.Application.StartupPath & "/sound/" & le.Chars(cou) & ".wav"

                    '    ret = sndPlaySound(strfilename.ToCharArray, 0)

                    'Next

 

 

2vs2003  PING 实现以及使用进程

 

Private Function ConnectionServer() As Boolean

        Try

            Dim p As New Process

            p.StartInfo.RedirectStandardOutput = True       '使用进程输出  

            p.StartInfo.CreateNoWindow = True       '新窗口来响应进程  

            p.StartInfo.FileName = "ping"

            p.StartInfo.Arguments = "192.168.0.113 -n 1 -w 4"       '"99.170.26.49"   '命令行参数(填写你自己要测试的ip地址)  

            p.StartInfo.UseShellExecute = False       '这里一定要设置为FALSE  

            p.Start()

            Dim s As String = p.StandardOutput.ReadToEnd             '应用程序获得进程输出流  

            p.WaitForExit(1000)   '等待1秒后退出进程  

            If s.IndexOf("Request timed out") > 0 Then

                Return False

            Else

                Return True

            End If

        Catch ex As Exception

            Return False

        End Try

 

 

3 获取语言

 

Private Declare Function GetSystemDefaultLCID Lib "kernel32 " () As Long

 

    Private Function GetOSLCID() As Integer

        Dim sysLCID As Long

 

        sysLCID = GetSystemDefaultLCID

        '&H409(us-英文)&H809(gb-英文)     &HC09(au-英文)   &H1009(ca-英文)

        '&H004(zh-中文)&H404(tw-Big5)&H804(cn-GBK/GB)&HC04(hk-Big5)   &H1004(sg-GBK)

        '&H804=2052   &H404=1028   &H409=1033   &H809=2057

        If sysLCID = &H804 Or sysLCID = &H4 Or sysLCID = &H1004 Then

            GetOSLCID = 1       '中文简体

        ElseIf sysLCID = &H404 Or sysLCID = &HC04 Then

            GetOSLCID = 2       '中文繁体

        ElseIf sysLCID Mod 16 = 9 Then

            GetOSLCID = 0       '(英文)

        Else

            GetOSLCID = 1

        End If

 

End Function

 

 

4  读写project

Imports Microsoft.Office.Interop.MSProject

Me.OpenFileDialog1.Filter = "Project 文件|*.mpp"

                If Me.OpenFileDialog1.ShowDialog() = DialogResult.OK Then

                    ReDim filename(Me.OpenFileDialog1.FileNames.Length)

                    filename = Me.OpenFileDialog1.FileNames

                    '打开文档

                    Dim row As DataRow

                    Me.Cursor = System.Windows.Forms.Cursors.WaitCursor

                                     Try

                        For i = 0 To filename.Length - 1

                            System.Windows.Forms.Application.DoEvents()

                            Me.ProgressBar1.Value += 90 / filename.Length

                            Dim aa As New Microsoft.Office.Interop.MSProject.Application

                            Dim bb As Microsoft.Office.Interop.MSProject.Project

                            str = Split(filename(i), "/").GetValue(5)

                            aa.FileOpen(filename(i))

                            aa.Visible = False

                            bb = aa.ActiveProject

                            For j = 1 To bb.Tasks.Count

                                Try

                                    If bb.Tasks(j).Name <> "" Then

                                        If Me.CheckBox1.Checked = True Then

                                            If bb.Tasks(j).Deadline >= Me.DateTimePicker1.Value And bb.Tasks(j).Deadline <= Me.DateTimePicker2.Value Then

                                                row = Me.ds.Tables("leo").NewRow

                                                row(0) = bb.Tasks(j).Name

                                                If bb.Tasks(j).Text1.Length = 4 Then

                                                    row(1) = "1000" & bb.Tasks(j).Text1 & "00"

                                                Else

                                                    row(1) = bb.Tasks(j).Text1

                                                End If

                                                row(2) = bb.Tasks(j).Text2

                                                If bb.Tasks(j).Text3.IndexOf("x") > 0 Then

                                                    row(3) = Split(bb.Tasks(j).Text3, "x").GetValue(0) * Split(bb.Tasks(j).Text3, "x").GetValue(1)

                                                Else

                                                    row(3) = bb.Tasks(j).Text3

                                                End If

                                                row(3) = bb.Tasks(j).Text3

                                                row(4) = bb.Tasks(j).Deadline &apos;"2008-5-20"

                                                row(5) = bb.Tasks(j).Start

                                                row(6) = bb.Tasks(j).Finish

                                                row(7) = bb.Tasks(j).Duration

                                                row(8) = bb.Tasks(j).Text4

                                                row(9) = Microsoft.VisualBasic.Left(str, 3) &apos;bb.Tasks(j).Text15

                                                row(10) = bb.Tasks(j).Text5

                                                Me.ds.Tables("leo").Rows.Add(row)

                                            End If

                                        Else

                                            If bb.Tasks(j).Start >= Me.DateTimePicker1.Value And bb.Tasks(j).Start <= Me.DateTimePicker2.Value Then

                                                row = Me.ds.Tables("leo").NewRow

                                                row(0) = bb.Tasks(j).Name

                                                If bb.Tasks(j).Text1.Length = 4 Then

                                                    row(1) = "1000" & bb.Tasks(j).Text1 & "00"

                                                Else

                                                    row(1) = bb.Tasks(j).Text1

                                                End If

                                                row(2) = bb.Tasks(j).Text2

                                                If bb.Tasks(j).Text3.IndexOf("x") > 0 Then

                                                    row(3) = Split(bb.Tasks(j).Text3, "x").GetValue(0) * Split(bb.Tasks(j).Text3, "x").GetValue(1)

                                                Else

                                                    row(3) = bb.Tasks(j).Text3

                                                End If

                                                row(4) = bb.Tasks(j).Deadline &apos;"2008-5-20"

                                                row(5) = bb.Tasks(j).Start

                                                row(6) = bb.Tasks(j).Finish

                                                row(7) = bb.Tasks(j).Duration

                                                row(8) = bb.Tasks(j).Text4

                                                row(9) = Microsoft.VisualBasic.Left(str, 3) &apos;bb.Tasks(j).Text15

                                                row(10) = bb.Tasks(j).Text5

                                                Me.ds.Tables("leo").Rows.Add(row)

                                            End If

                                        End If

                                    End If

                                Catch ex As Exception

                                    &apos; MessageBox.Show(ex.Message)

                                End Try

                            Next

                            aa.Quit(PjSaveType.pjDoNotSave)

                        Next

                    Catch ex As Exception

                        MessageBox.Show(ex.Message)

                    End Try

                End If

 

 

 

5两种方法导出EXCEL

 

 

Private Sub 导出EXCELToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 导出EXCELToolStripMenuItem.Click

        If Me.SEVECODataSet.重检记录.Count <= 0 Then

            MessageBox.Show("没有数据可以导出", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)

            Exit Sub

        End If

        If Me.SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then

            Exit Sub

        End If

        Dim filename As String = Me.SaveFileDialog1.FileName

        Dim excelapp As New Excel.Application

        Dim excelbook As Excel.Workbook = excelapp.Workbooks.Add

        Dim excelsheet As Excel.Worksheet = excelbook.Worksheets.Add

        excelapp.Visible = True

        &apos;With excelsheet

        &apos;    .Columns.ColumnWidth = 15

        &apos;    .Range("A1").Value = "来料日期"

        &apos;    .Range("B1").Value = "品号"

        &apos;    .Range("C1").Value = "品名"

        &apos;    .Range("D1").Value = "中文品名"

        &apos;    .Range("E1").Value = "库位"

        &apos;    .Range("F1").Value = "批号数量"

        &apos;    .Range("G1").Value = "重检日期"

        &apos;    .Range("H1").Value = "检验结果"

        &apos;    .Range("I1").Value = "检验员"

        &apos;    .Range("J1").Value = "备注"

        &apos;    .Range("K1").Value = "批号"

 

        &apos;Dim i As Integer = 2

        &apos;Dim dr As DataRow

        &apos;For Each dr In Me.SEVECODataSet.重检记录.Rows

        &apos;    .Range("A" + i.ToString).Value = dr("来料日期")

        &apos;    .Range("B" + i.ToString).Value = dr("品号")

        &apos;    .Range("C" + i.ToString).Value = dr("品名")

        &apos;    .Range("D" + i.ToString).Value = dr("中文品名")

        &apos;    .Range("E" + i.ToString).Value = dr("库位")

        &apos;    .Range("F" + i.ToString).Value = dr("批号数量")

        &apos;    .Range("G" + i.ToString).Value = dr("重检日期")

        &apos;    .Range("H" + i.ToString).Value = dr("检验结果")

        &apos;    .Range("I" + i.ToString).Value = dr("检验员")

        &apos;    .Range("J" + i.ToString).Value = dr("备注")

        &apos;    .Range("K" + i.ToString).Value = dr("批号")

        &apos;    i += 1

        &apos;Next

        &apos;  End With

        Me.DataGridView1.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText

        Me.DataGridView1.SelectAll()

        Dim dataobjct As New System.Windows.Forms.DataObject

        dataobjct = Me.DataGridView1.GetClipboardContent

        System.Windows.Forms.Clipboard.SetDataObject(dataobjct)

        excelsheet.PasteSpecial(Format:="文本", Link:=False, DisplayAsIcon:=False)

 

        Try

            If filename <> "" Then

                excelbook.Saved = True

                excelbook.SaveCopyAs(filename)

            End If

            MessageBox.Show("导出文件成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Catch ex As Exception

            MessageBox.Show("导出文件时出错,文件可能正被打开!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

        excelapp.Quit()

    End Sub

 

 

 

6读取XML

 

 

Dim Nxml As Xml.XmlNodeReader

        Dim Doc As New Xml.XmlDocument

        Doc.Load("login.xml")

        Nxml = New Xml.XmlNodeReader(Doc)

        Nxml.Read()

        Me.TextBox1.Text = Nxml.Name

        Nxml.Read()

        Me.TextBox2.Text = Nxml.Value

        Me.TextBox2.Focus()

 

 

 

 

7 将图片转化成BYTE 数组存入数据库中

 

On Error GoTo errhandler

        OpenFileDialog1.Filter = "图片文件(*.jpg)|*.jpg|全部文件(*.*)|*.*"

        OpenFileDialog1.FilterIndex = 1

        Me.OpenFileDialog1.ShowDialog()

        Me.PictureBox1.ImageLocation = Me.OpenFileDialog1.FileName

        Dim fs As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)

        Dim br As BinaryReader = New BinaryReader(fs)

        ReDim buffer(fs.Length)

        br.Read(buffer, 0, CInt(fs.Length))

 

        fs.Close()

errhandler:

        Exit Sub

读出来

 

Dim b() As Byte

        If Me.DataGridView1.CurrentRow.Cells(26).Value.ToString = String.Empty Then

            lrEmpS.PictureBox1.Image = Nothing

        Else

            b = Me.DataGridView1.CurrentRow.Cells(26).Value

            If b.Length > 0 Then

                Dim stream As New MemoryStream(b, True)

                stream.Write(b, 0, b.Length)

                lrEmpS.PictureBox1.Image = New Bitmap(New Bitmap(stream))            &apos;图片

                stream.Close()

            End If

        End If

 

8 数据加密

 

    Public Shared Function encrypt(ByVal str As String) As String
        Dim dataToHash As Byte() = (New System.Text.ASCIIEncoding).GetBytes(str)
        Dim hashvalue As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName("MD5"), System.Security.Cryptography.HashAlgorithm).ComputeHash(dataToHash)
        Dim strl As String = ""
        Dim i As Integer
        For i = 4 To 11
            strl += Hex(hashvalue(i)).ToLower
        Next
        Return strl

    End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值