如何将值数据传递给txtfile? [英] How to pass the value data to txtfile ?

查看:62
本文介绍了如何将值数据传递给txtfile?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Imports System.Data
Imports System.Data.Odbc
Imports System.IO


Public Class Form1


    Dim OdbcConnection As Odbc.OdbcConnection
    Dim OdbcCommand As Odbc.OdbcCommand
    Dim sqlString As String
    Public des As String

    Dim connection As String = "DRIVER={MySQL ODBC 3.51 Driver};" & "SERVER=192.168.1.6;" & "DATABASE=ztest;" & "UID=MYBS;" & "PASSWORD=MYBSMYBS;" & "OPTION=3;"
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ZtestDataSet.stk_group' table. You can move, or remove it, as needed.
        Me.Stk_groupTableAdapter1.Fill(Me.ZtestDataSet.stk_group)

        TestConnection()
        atxt.Select()
        atxt.Focus()
    End Sub

    Public Sub TestConnection()
        'Try

        Dim odbcconnection As String = "DRIVER={MySQL ODBC 3.51 Driver};" & "SERVER=192.168.1.6;" & "DATABASE=ztest;" & "UID=MYBS;" & "PASSWORD=MYBSMYBS;" & "OPTION=3;"
        Dim connStr As New OdbcConnection(odbcconnection)
        Dim selectSql As String = "SELECT description FROM stk_group WHERE itemgroup = '" & cb1.SelectedValue.ToString & "'"
        Dim comm As New OdbcCommand(selectSql, connStr)
        Dim dr As OdbcDataAdapter
        connStr.Open()
        dr = comm.ExecuteReader
        'While dr.Read()
        'des = dr.Item(0).ToString
        ' End While

        connStr.Close()
        'dr.Close()
        'MsgBox("Connection is ok.")

        'Catch ex As Exception
        'MsgBox("Failed to connect to data source")
        ' End Try
    End Sub



    

    Private Sub WriteToFile(ByVal input As String, ByVal path As String, ByVal append As Boolean)


        Using writer As New StreamWriter(path, append)
            writer.WriteLine(input)

        End Using
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        'file location  
        Dim group, amount, final, price As String
        Dim a() As Byte
        Dim testPath As String = "D:\Barcode\textfile\tmp.txt"
        Dim receiptPath As String = "D:\Barcode\textfile\receipt.txt"
        Dim printPagePath As String = "D:\Barcode\textfile\barcode4.txt"
        Dim ibarcodePath As String = "D:\Barcode\textfile\barcode2.txt"
        Dim itextPath As String = "D:\Barcode\textfile\barcode3.txt"
        Dim ipricePath As String = "D:\Barcode\textfile\barcode.txt"
        Dim textPath As String = "D:\Barcode\textfile\text.txt"
        Dim desPath As String = "D:\Barcode\textfile\Description.txt"
        Dim page As Integer
        page = ctxt1.Text

        'combine this code into string code (13digit number )
        group = cb1.SelectedValue.ToString
        amount = String.Format("{0:0000000}", CInt(CDbl(atxt.Text * 100)))
        final = group + "" + amount + "0"
        WriteToFile(final, testPath, True)
        price = Format(CDbl(atxt.Text), "f")

        'read this xy file to fill the barcode size 
        Dim xy, xy2, xy3, xy4, xy5 As String
        Dim reader As New System.IO.StreamReader("D:\Barcode\textfile\xy.txt")
        xy = reader.ReadLine()
        xy2 = reader.ReadLine()
        xy3 = reader.ReadLine()
        xy4 = reader.ReadLine()
        xy5 = reader.ReadLine()
        reader.Close()

        'copy all content txt file to receipt.txt
        Dim ibarcodeString As String = "BARCODE " + xy + ",""128"",50,0,0,2,1,""" + final + """"
        WriteToFile(ibarcodeString, ibarcodePath, False)


        Dim desString As String = "TEXT " + xy5 + ",""1"",0,1,1,""" + des + """"
        WriteToFile(desString, desPath, False)

        Dim textString As String = "TEXT " + xy4 + ",""1"",0,1,1,""" + texttxt.Text + """"
        WriteToFile(textString, textPath, False)

        Dim itextString As String = "TEXT " + xy2 + ",""2"",0,1,1,""" + final + """"
        WriteToFile(itextString, itextPath, False)

        Dim ipriceString As String = "TEXT " + xy3 + ",""3"",0,1,1,""RM " + price + """"
        WriteToFile(ipriceString, ipricePath, False)

        Dim iprintString As String = "PRINT " + ctxt1.Text + ",1"
        WriteToFile(iprintString, printPagePath, False)

        a = System.IO.File.ReadAllBytes("D:\Barcode\textfile\barcode1.txt")
        System.IO.File.WriteAllBytes(receiptPath, a)
        WriteToFile(ibarcodeString, receiptPath, True)
        WriteToFile(desString, receiptPath, True)
        WriteToFile(textString, receiptPath, True)
        WriteToFile(itextString, receiptPath, True)
        WriteToFile(ipriceString, receiptPath, True)
        WriteToFile(iprintString, receiptPath, True)
        'until this session end is the txt file to reicept.txt  
        'MessageBox.Show("Record stored successful")

        'shell profile is to use cmd to run bat file 
        Shell("D:\Barcode\PrintBarcode.bat", vbNormalFocus)

    End Sub


End Class

推荐答案

这篇关于如何将值数据传递给txtfile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆