Imports GAF.Tools
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Drawing.Imaging
Imports System.IO
Public Class frmland
Dim Conn As SqlConnection = New SqlConnection
Dim da As SqlDataAdapter
Dim add_state As Boolean = False
Dim dt As New DataTable
Dim db As New DataTable
Dim land As SqlCommand
Private bin As New BindingSource
Dim objCurrencyMgr As CurrencyManager
Dim currRecPos As Integer
Dim addNewMode As Boolean
Dim ds As DataSet = New DataSet()
Dim IsFind As Boolean = False
Dim ImageFileName As String = ""
Dim CurrentRecord As Integer = 0
Dim imgExtension As String = ""
Dim acProductList As New AutoCompleteStringCollection()
Dim ofDlg As Object
Private Sub Land_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strConn As String
strConn = "Data Source=.\SQLEXPRESS;Initial Catalog=SSPEGIS;Integrated Security=True"
Conn = New SqlConnection(strConn)
Dim sqlland As String = ""
sqlland = "SELECT * FROM land ORDER BY LANDID"
If IsFind = True Then
ds.Tables("land").Clear()
End If
da = New SqlDataAdapter(sqlland, Conn)
da.Fill(db)
Dim cmb As SqlCommandBuilder
cmb = New SqlCommandBuilder(da)
bin.DataSource = db
txtLANDID.DataBindings.Add("Text", bin, "LANDID")
txtPARCEL_CODE.DataBindings.Add("Text", bin, "PARCEL_CODE")
txtTAMBON_TH.DataBindings.Add("Text", bin, "TAMBON_TH")
txtDISTRICT_TH.DataBindings.Add("Text", bin, "DISTRICT_TH")
txtPROVINCE_TH.DataBindings.Add("Text", bin, "PROVINCE_TH")
If CurrentRecord = 0 Then
If Convert.ToString(db.Rows(CurrentRecord).Item("LAND_RENTID")) = "1" Then
RadioButton1.Checked = True
ElseIf Convert.ToString(db.Rows(CurrentRecord).Item("LAND_RENTID")) = "2" Then
RadioButton2.Checked = True
End If
End If
Try
If Convert.ToString(db.Rows(CurrentRecord).Item("PICTURE")) <> "" Then
PictureBox1.Image = Image.FromFile(Convert.ToString(db.Rows(CurrentRecord).Item("PICTURE")))
Else
PictureBox1.Image = Nothing
End If
Catch
PictureBox1.Image = Nothing
End Try
Dim sqlland_use As String = ""
sqlland_use = "SELECT * FROM land_use ORDER BY LAND_USEID"
da = New SqlDataAdapter(sqlland_use, Conn)
da.Fill(ds, "land_use")
Dim sqlldoc_type As String = ""
sqlldoc_type = "SELECT * FROM ldoc_type ORDER BY LDOC_TYPEID"
da = New SqlDataAdapter(sqlldoc_type, Conn)
da.Fill(ds, "ldoc_type")
With cboLAND_USE
.DisplayMember = "USED_DESC"
.ValueMember = "LAND_USEID"
.DataSource = ds.Tables("land_use")
.DataBindings.Add("SelectedValue", bin, "LAND_USEID")
End With
With cboLDOC_TYPE
.DisplayMember = "LDOC_TYPE"
.ValueMember = "LDOC_TYPEID"
.DataSource = ds.Tables("ldoc_type")
.DataBindings.Add("SelectedValue", bin, "LDOC_TYPEID")
End With
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim sqlupdate As String
Dim sqladd As String
Dim strConn As String
strConn = "Data Source=.\SQLEXPRESS;Initial Catalog=SSPEGIS;Integrated Security=True"
sqlupdate = "update land "
sqlupdate &= " set PARCEL_CODE = '" & txtPARCEL_CODE.Text & "',"
sqlupdate &= " TAMBON_TH= '" & txtTAMBON_TH.Text & "',"
sqlupdate &= " LAND_USEID='" & CStr(cboLAND_USE.SelectedValue) & "',"
sqlupdate &= " LDOC_TYPEID='" & CStr(cboLDOC_TYPE.SelectedValue) & "',"
If RadioButton1.Checked = True Then
sqlupdate &= "LAND_RENTID='1',"
ElseIf RadioButton2.Checked = True Then
sqlupdate &= "LAND_RENTID='2',"
End If
sqlupdate &= " PICTURE= '" & tmpFileName & "'," ' ตรงนี้อะครับเขียนยังไง
sqlupdate &= " DISTRICT_TH= '" & txtDISTRICT_TH.Text & "',"
sqlupdate &= " PROVINCE_TH= '" & txtPROVINCE_TH.Text & "'"
sqlupdate &= " where LANDID = '" & txtLANDID.Text & "'"
Try
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
land = New SqlCommand
With land
.CommandType = CommandType.Text
'If add_state = True Then
'.CommandText = sqladd
' Else
.CommandText = sqlupdate
' End If
.Connection = Conn
.ExecuteNonQuery()
End With
Catch ErrorToEdit As Exception
MessageBox.Show(ErrorToEdit.Message & sqladd, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
add_state = False
MessageBox.Show("บันทึกข้อมูลเสร็จแล้ว ", "แจ้งให้ทราบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Dim ofDlg As New OpenFileDialog()
ofDlg.Title = "เลือกไฟล์รูปภาพ"
ofDlg.Filter = "Bitmap Images(.bmp)|*.bmp|Gif Images(.gif)|*.gif|Jpeg Images(.jpg)|*.jpg| Png Image(*.png)|*.png|All Files (*.*)|*.*"
If ofDlg.ShowDialog = DialogResult.OK Then
tmpFileName = ofDlg.FileName
PictureBox1.Image = Image.FromFile(ofDlg.FileName)
End If
End Sub