hi 1st create the record successful but 2nd time lo also show same msg box....
iam using bll and dal.
bll code:
how to check duplicate record:
Public Shared Function CreateNewAMSRegMaintance(ByVal objAMSRegMaintance As clsAMSRegMaintance, ByVal tmprmno As Int32) As String
If Not objAMSRegMaintance Is Nothing Then
Dim TempId As String = dalAMSRegMaintance.CreateNewAMSRegMaintance(objAMSRegMaintance, tmprmno)
If TempId = 0 Then
objAMSRegMaintance.m_RMNO = tmprmno
Return True
Else
Return False
End If
Else
Return False
End If
End Function
dal code:
Public Shared Function CreateNewAMSRegMaintance(ByVal objAMSRegMaintance As clsAMSRegMaintance, ByVal tmprmno As Int32) As Integer
If objAMSRegMaintance Is Nothing Then
Throw New ArgumentNullException("objAMSRegMaintance")
End If
Dim db As DBAccess = New DBAccess
Dim sqlCmd As SqlCommand = New SqlCommand()
db.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, Nothing)
db.AddParamToSQLCmd(sqlCmd, "@RMNO", SqlDbType.BigInt, 8, ParameterDirection.Input, tmprmno)
db.AddParamToSQLCmd(sqlCmd, "@DEVICE_NO", SqlDbType.NVarChar, 6, ParameterDirection.Input, objAMSRegMaintance.DEVICE_NO)
db.AddParamToSQLCmd(sqlCmd, "@SERIAL_NO", SqlDbType.NVarChar, 30, ParameterDirection.Input, objAMSRegMaintance.SERIAL_NO)
db.AddParamToSQLCmd(sqlCmd, "@RHDATE", SqlDbType.NVarChar, 10, ParameterDirection.Input, objAMSRegMaintance.RHDATE)
db.AddParamToSQLCmd(sqlCmd, "@RTIME", SqlDbType.NVarChar, 10, ParameterDirection.Input, objAMSRegMaintance.RTIME)
db.AddParamToSQLCmd(sqlCmd, "@REMP", SqlDbType.NVarChar, 100, ParameterDirection.Input, objAMSRegMaintance.
db.AddParamToSQLCmd(sqlCmd, "@REMPTELNO", SqlDbType.NVarChar, 15, ParameterDirection.Input, objAMSRegMaintance.
db.AddParamToSQLCmd(sqlCmd, "@PROBLEMDESC", SqlDbType.NVarChar, 100, ParameterDirection.Input, objAMSRegMaintance.PROBLEMDESC)
db.AddParamToSQLCmd(sqlCmd, "@RMFLG", SqlDbType.Int, 8, ParameterDirection.Input, objAMSRegMaintance.RMFLG)
db.AddParamToSQLCmd(sqlCmd, "@ERROR", SqlDbType.VarChar, 100, ParameterDirection.Output, Nothing)
db.SetCommandType(sqlCmd, CommandType.StoredProcedure, "SP_CREATEREGMAINTANCE")
db.ExecuteScalarCmd(sqlCmd)
Return CInt(sqlCmd.Parameters("@ReturnValue").Value)
End Function
aspx.cs code:
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
Dim ret As Boolean
Dim objAMSRegMaintance As clsAMSRegMaintance = New clsAMSRegMaintance
Dim objAMSDALRegMaintance As dalAMSRegMaintance = New dalAMSRegMaintance
If txtDevNum.Text <> "" Then
objAMSRegMaintance.DEVICE_NO = Trim(txtDevNum.Text)
objAMSRegMaintance.SERIAL_NO = Trim(txtSerialNum.Text)
objAMSRegMaintance.RHDATE = Trim(txtRecHDate.Text)
objAMSRegMaintance.RTIME = Trim(txtRecHTime.Text)
objAMSRegMaintance.
objAMSRegMaintance.
objAMSRegMaintance.PROBLEMDESC = Trim(txtPrbDesc.Text)
objAMSRegMaintance.RMFLG = 0
Dim tmprmno As Int32 = objAMSDALRegMaintance.GetAutoIncrementValue("TBL_MAINTENANCE", "RMNO")
ret = clsAMSRegMaintance.CreateNewAMSRegMaintance(objAMSRegMaintance, tmprmno)
If ret = True Then
Page.ClientScript.RegisterStartupScript(Me.GetType(), "ShowMessageScript", "alert('!تم الحفظ بنجاح');", True)
ClearTextBox(Me)
Else
Page.ClientScript.RegisterStartupScript(Me.GetType(), "ShowMessageScript", "alert('في قسم الصيانة لعمل الصيانة اللازمة');", True)
ClearTextBox(Me)
End If
Else
Page.ClientScript.RegisterStartupScript(Me.GetType(), "ShowMessageScript", "alert('!بجب تعبئة الحقول قبل الحفظ');", True)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub