Saturday, August 23, 2014

vb.net (Add)

1. Browse to show image on form 

Private Sub Buttonaddimage_Click(sender As Object, e As EventArgs) Handles Buttonaddimage.Click
        Dim ofd As New OpenFileDialog
        If ofd.ShowDialog = DialogResult.OK Then
            If ofd.FileName <> String.Empty Then
                imgpath = ofd.FileName
                Dim bm_source As New Bitmap(Bitmap.FromFile(ofd.FileName), 200, 200)
                PictureBox1.Image = bm_source
            End If
        End If
    End Sub

2. Add Item include image

Private Sub additem_Click(sender As Object, e As EventArgs) Handles additem.Click
        Dim comm2 As New OdbcCommand
        Dim comm3 As New OdbcCommand
        Dim status As Byte
        Dim userid2 As Byte
        Form1.connect()
        Form1.conn.Open()
        comm2 = Form1.comm
        Dim itemgroupid As Integer
        comm2 = New OdbcCommand("INSERT INTO `tbl_item`(`igroup_id`, `item_code`, `item_name`, `qty`, `price_out`, `expire_date`, `image`, `status_id`, `created_date`, `created_by`) VALUES (?,?,?,?,?,?,?,?,?,?)", Form1.conn)
        Dim comm As New OdbcCommand
        Dim odt As New DataTable
        Dim ods As New DataSet
        comm3 = New OdbcCommand("select igroup_id from tbl_item_group where igroup_name='" & ComboBoxitemgroup.Text & "'", Form1.conn)
        Dim myDA As OdbcDataAdapter = New OdbcDataAdapter(comm3)
        myDA.Fill(ods, "tbl_item_group")
        odt = ods.Tables("tbl_item_group")
        itemgroupid = odt.Rows(0).Item(0)
        comm2.Parameters.AddWithValue("igroup_id", itemgroupid)
        comm2.Parameters.AddWithValue("item_code", Me.TextBoxitemcode.Text)
        comm2.Parameters.AddWithValue("item_name", Me.TextBox1.Text)
        comm2.Parameters.AddWithValue("qty", Me.TextBoxquantity.Text)
        comm2.Parameters.AddWithValue("price_out", Me.TextBoxsellout.Text)
        comm2.Parameters.AddWithValue("expire_date", CDate(Me.DateTimePicker1.Text))

        Dim bm_source As New Bitmap(Bitmap.FromFile(imgpath), 400, 400)

        Dim clone As Bitmap = CopyBitmap(bm_source)
        Dim timeStamp As String = DateTime.Now.ToString("yyyyMMddhhmmss")

        clone.Save("C:\Users\Laptop\Desktop\rathana\" & timeStamp & ".bmp", ImageFormat.Bmp)
        comm2.Parameters.AddWithValue("image", "C:\Users\Laptop\Desktop\rathana\" & timeStamp & ".bmp")

        If Comitemstatus.Text = "Active" And Comitemstatus.Text <> "" Then
            status = 1
        Else
            status = 0
        End If
        comm2.Parameters.AddWithValue("status_id", status)
        comm2.Parameters.AddWithValue("created_date", Now)
        userid2 = Form1.userid
        comm2.Parameters.AddWithValue("created_by", userid2)
        comm2.ExecuteNonQuery()
        Form1.conn.Close()
    End Sub

No comments:

Post a Comment