Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

Conexion con sql server

Imports System.Data.SqlClient
dim Conexion01 As New SqlConnection
If Conexion01.State = ConnectionState.Closed Then Conexion01.Open()
Dim SQLInv = "Select GrossWeight as Peso, UserDecimal1 as Largo from
pilot.erp.Part with(nolock) where Partnum = '" & PartNum.text & "'"
Dim dtInv as DataTable = new DataTable
Dim daInv as SQLDataAdapter = New SqlDataAdapter()
Dim cmdInv as New SQLCommand(SQLInv, Conexion01)
daInv.SelectCommand = cmdInv
daInv.Fill(dtInv)
if dtInv.rows.count = 0
'fRevInventario = "Datos incorrectos en la revision de inventario,
favor de varificar. "
if Conexion01.State <> ConnectionState.Closed then Conexion01.Close()
exit function
end if

++++++++++++++++++++++++++++++++++++++++++++++++++

Realizar instancia de un componente Nativo de Epicor


dim Variable as new TipoDeComponente
Variable = CType(csm.GetNativeControlReference("EpiGuid"), TipoDeComponente)

++++++++++++++++++++++++++++++++++++++++++++++++++

Arreglo para permisos por usuario


Dim Permitidos() As String = { "JUANPEREZ", "ALVIRDE", "PEPEPECAS", "DGUZMAN",
"HGOMEZ" }
Dim index As Integer = Array.IndexOf(Permitidos,
ucase(PartTranHistForm.Session.UserID))
if Index = -1 then
No tiene Permiso
else
Tiene Permiso
end if

++++++++++++++++++++++++++++++++++++++++++++++++++
Obtener informaci�n mediante ingreso de usuario

dim PartNum as EpiTextBox


dim Cantidad as EpiNumericEditor
dim Conexion01 As New SqlConnection

Private Sub JobEntryForm_Load(ByVal sender As Object, ByVal args As EventArgs)


' Add Event Handler Code
Conexion01.ConnectionString = "Data Source= 192.168.1.251\epicorDB;Initial Catalog
= pilot ;User id = sa;Password = saArtabanE10"
PartNum = Ctype(csm.GetNativeControlReference("543b58f3-576d-4131-badf-
b9f7e3d446c5"), EpiTextBox)
Cantidad = Ctype(csm.GetNativeControlReference("c6c8b7d5-e166-4ef7-
9dc1-8efcb608ddfa"), EpiNumericEditor)
' ** Get Property
if JobEntryForm.Session.CompanyID = "ARTABAN5" THEN bCalcular.visible =
true else bCalcular.visible = False

if Cantidad.Readonly = True Then Exit sub


dim Metros as double
Metros = InputBox("Favor de Indicar los Metros: ", "Grupo Artaban",
"0")
Cantidad.value = fCalculaKG(Metros)
Cantidad.Focus()
bCalcular.Focus()

Private Function fCalculaKG(byval Metros as double) as Double


try
If Conexion01.State = ConnectionState.Closed Then
Conexion01.Open()
Dim SQLInv = "Select GrossWeight as Peso, UserDecimal1 as Largo
from pilot.erp.Part with(nolock) where Partnum = '" & PartNum.text & "'"
Dim dtInv as DataTable = new DataTable
Dim daInv as SQLDataAdapter = New SqlDataAdapter()
Dim cmdInv as New SQLCommand(SQLInv, Conexion01)
daInv.SelectCommand = cmdInv
daInv.Fill(dtInv)
if dtInv.rows.count = 0
'fRevInventario = "Datos incorrectos en la revision de
inventario, favor de varificar. "
if Conexion01.State <> ConnectionState.Closed then
Conexion01.Close()
exit function
end if
return dtinv.rows(0)("Peso")*Metros/dtinv.rows(0)("Largo")
catch
return 0
end try
end function

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Proceso para utilizar un Procedimiento almacenado con retorno de Variable

Try
If Conexion01.State = ConnectionState.Closed Then Conexion01.Open()
Dim Msj = fRevInventario(JobNum, Conexion01)
if Msj <> "OK" then
msgbox(Msj, MsgBoxStyle.Critical, "ARTABAN INTERNACIONAL")
btnAsignar.Enabled = True
exit sub
end if

Dim cmd As New SqlCommand("spGenEtiqueta", Conexion01)


cmd.CommandType = CommandType.StoredProcedure
'cmd.Transaction = Transac
cmd.Parameters.Add("@Company",SqlDbType.VarChar, 10).value =
RQForm.Session.CompanyID
cmd.Parameters.Add("@Jobnum",SqlDbType.VarChar, 50).value = JobNum
cmd.Parameters.Add("@idOperador",SqlDbType.VarChar, 50).value =
RQForm.Session.EmployeeID
cmd.Parameters.Add("@Usuario",SqlDbType.VarChar, 50).value =
RQForm.Session.UserID
cmd.Parameters.Add("@Cantidad", SqlDbType.Int).value = 1
cmd.Parameters.Add("@Etiqueta", SqlDbType.VarChar, 10)
cmd.Parameters("@Etiqueta").Direction = ParameterDirection.Output
' Transac.Commit()
If Conexion01.State = ConnectionState.Closed Then Conexion01.Open()
cmd.ExecuteNonQuery()
Dim tran As Boolean = oTrans.Update()

'Process.start("\\epicor01\ERP10.0.700Deployment\ArtaReport.exe", "1 "+


cmd.Parameters("@Etiqueta").Value.ToString)
shell("\\epicor01\Reportes\ArtaReport.exe 1 " + RQForm.Session.CompanyID + "
" + cmd.Parameters("@Etiqueta").Value.ToString, AppWinStyle.Hide)
FormSurtido.Close()
Catch ex As Exception
'Transac.Rollback()
MsgBox("Ocurrio un Error al Generar la etiqueta, favor de verificar con el
administrador del sistema." + " " + ex.Message, MsgBoxStyle.Critical, "ARTABAN
INTERNACIONAL")
'msgbox(Conexion01.State)
btnAsignar.Enabled = True
Exit Sub
End Try

You might also like