SQLCMD = " SELECT DM_DEPARTMENT, DM_DESCRIPTION ,(DM_DEPARTMENT+' '+DM_DESCRIPTION) As DM_NAME "
SQLCMD &= " FROM VGL_DEPARTMENT_MASTER "
SQLCMD &= " WHERE DM_DEL_FLAG <> 'Y' "
SQLCMD &= " AND DM_COMPANY='" & LogonCompCode & "' "
SQLCMD &= " AND DM_BRANCH='" & LogonBranchCode & "'"
DT = Nothing
DT = GetDataTable(SQLCMD)
If Not FlagConnect Then
Exit Sub
End If
With cboAcc1
.BeginUpdate()
.DisplayMember = "DM_NAME"
.ValueMember = "DM_DEPARTMENT"
.DataSource = DT
.EndUpdate()
End With
cboAcc1.SelectedIndex = -1
_conn.Close()
If _conn.State = ConnectionState.Open Then
_conn.Close()
End If
Dim Sb As New System.Text.StringBuilder()
Sb.AppendLine("SELECT [DM_DEPARTMENT], [DM_DESCRIPTION] ,([DM_DEPARTMENT]+' '+[DM_DESCRIPTION]) As [DM_NAME]")
Sb.AppendLine("FROM [VGL_DEPARTMENT_MASTER]")
Sb.AppendLine("WHERE [DM_DEL_FLAG]<>@dm_del_flag AND")
Sb.AppendLine("[DM_COMPANY]=@dm_company AND")
Sb.AppendLine("[DM_BRANCH]=@dm_branch AND")
Sb.AppendLine("([DM_DEPARTMENT] IS NOT NULL OR [DM_DESCRIPTION] IS NOT NULL)")
SQLCMD = Sb.ToString()
Dim _Comm As New SqlCommand(SQLCMD, _conn)
_Comm.Parameters.AddWithValue("@dm_del_flag", "Y")
_Comm.Parameters.AddWithValue("@dm_company", LogonCompCode)
_Comm.Parameters.AddWithValue("@dm_branch", LogonBranchCode)
DT.Rows.Clear()
Dim DataAdapter As New SqlDataAdapter(_Comm)
DataAdapter.Fill(DT)
If Not FlagConnect Then
Exit Sub
End If
cboAcc1.DataSource = DT
cboAcc1.DisplayMember = "DM_NAME"
cboAcc1.ValueMember = "DM_DEPARTMENT"
cboAcc1.SelectedIndex = -1
Dim cmdBuilder As System.Text.StringBuilder = New System.Text.StringBuilder()
cmdBuilder.AppendLine("SELECT '' AS [Value_Field] ,'' AS [Text_Field]") 'แถวว่างอยู่ตรงนี้
cmdBuilder.AppendLine("UNION")
cmdBuilder.AppendLine("SELECT [DM_DEPARTMENT] AS [Value_Field]")
cmdBuilder.AppendLine(" ,([DM_DEPARTMENT]+' '+[DM_DESCRIPTION]) AS [Text_Field] ")
cmdBuilder.AppendLine("FROM [VGL_DEPARTMENT_MASTER]")
cmdBuilder.AppendLine("WHERE ([DM_DEL_FLAG] <> 'Y')")
cmdBuilder.AppendLine(" AND [DM_COMPANY]='" & LogonCompCode & "'")
cmdBuilder.AppendLine(" AND [DM_BRANCH]='" & LogonBranchCode & "'")
cmdBuilder.AppendLine("ORDER BY [DM_DEPARTMENT] ,[DM_DESCRIPTION]")
DT = Nothing
DT = GetDataTable(cmdBuilder.ToString())
If Not FlagConnect Then
Exit Sub
End If
With cboAcc1
.BeginUpdate()
.DisplayMember = "Text_Field"
.ValueMember = "Value_Field"
.DataSource = DT
.EndUpdate()
End With
cboAcc1.SelectedIndex = -1
_conn.Close()
SELECT ''AS Value_Field ,'' AS Text_Field
UNION
SELECT DM_DEPARTMENT AS Value_Field,(DM_DEPARTMENT+' '+DM_DESCRIPTION) AS Text_Field
FROM VGL_DEPARTMENT_MASTER
WHERE DM_DEL_FLAG <> 'Y'
AND DM_COMPANY='001'
AND DM_BRANCH='001'
ORDER BY Value_Field ,Text_Field