ListView Cancel Insert RRS feed

  • Question

  • User1510859543 posted

    Our users wanted an insert blocked if PTO entry exceeds a limit on number of days off.  Now they want to give some users the ability to override this and allow the insert to happen.  Below is the OnInserting code we are currently using. They want a popup to confirm this insert before the actual insert(s) are committed.  How can we do this?

            Dim strMsg As String = ""
            Dim strDatesOver As String = ""
            Using conData As SqlConnection = New SqlConnection(DBClass.GetMgmtConnectionString)
                Dim strSQL As String = "EXEC dbo.ms_selEmployeeTimeOffMax " &
                        "@StartDate = '" & dtDateFrom.ToShortDateString & "'" &
                        ", @EndDate = '" & dtDateTo.ToShortDateString & "'" &
                        ", @EmployeeCode='" & ddl.SelectedValue & "'"
                Dim cmdSelect As SqlCommand = New SqlCommand(strSQL, conData)
                Dim dtr As SqlDataReader = cmdSelect.ExecuteReader()
                If dtr.HasRows Then
                    While dtr.Read()
                        strDatesOver &= Format(dtr("TimeOffDate"), "M/d/yyyy") & "~"
                    End While
                End If
                If strDatesOver <> "" Then
                    'PTO max exceeded on one or more dates
                    strMsg = "The PTO dates below would exceed daily group maximums for PTO. PTO entry was cancelled.~" & strDatesOver
                    txtMsg.Text = strMsg
                    e.Cancel = True
                End If
            End Using

    Monday, November 2, 2020 3:06 PM

All replies

  • User475983607 posted

    How can we do this?

    First, come up with a design that meets the requirements.  These are steps.   Next, write the code to meet the requirement. 

    If you want the community to complete your work, then are you also willing to share your fee?

    As a hint, the current business rules are within the stored procedure.  Modify the procedure to accept another parameter which overrides the current logic. 

    Monday, November 2, 2020 4:45 PM