开发者

How to cancel insert in listview following method asp.net vb

I am stumped by being unable to cancel a list view insert operation following a method to validate a string. While the method validates the string and shows a modal popup when the string is not valid, then I want to stop the insert using e.cancel in listviewinserteventargs, however the cancel operation did not occur. Any help is appreciated!!!

Imports System.Data
'Imports System.Data.SqlClient

Public Class SecureOrderHCTPScan
    Inherits System.Web.UI.Page

    Public iPreLoadIndex As Integer
    'Public pageContent As String = "<!-- #include file=""content/home/home.txt"" -->"

    Dim currentOrderID As Int32 'for current order number
    Dim entryNum As Int32 ' holds sample entry number


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        gotoDefaultHome.HRef = "TestOrderDefault.aspx"
        gotoDefaultHome.Title = ""

        iPreLoadIndex = CInt(Request.QueryString("titrateIdx"))

        'creates new order object
        Dim orderTicket = New orderNumbers

        'checks to see if an order # has been issued and if so, does not create a new order
        If (Me.IsPostBack) Then

        Else
            ViewState("currentOrderID") = orderTicket.createNewOrder("BSIRG6789")
        End If
        currentOrderID = ViewState("currentOrderID")
        orderNumLbl.Text = currentOrderID
        Session("orderNum") = currentOrderID

        'Verify Date in tbxColDate as being no more than than 7 days old and not in the future
        Dim currentDate As Date = DateTime.Now()
        Dim tubeDumpDate As Date = DateTime.Now.AddDays(-7)

        'set maximum and minimum dates for date validation, date is time specimens are kept
        'in lab
        tbxCollDate_Validator.MaximumValue = currentDate.ToString("MM/dd/yy")
        tbxCollDate_Validator.MinimumValue = tubeDumpDate.ToString("MM/dd/yy")

        'The number of tubes scanned in this session
        'create new entry number generator object
        Dim entryNum = New entryNumber
        Session("EntryNum") = entryNum.createNextEntryNum(currentOrderID)

        'Exit Sub
        'homeContent.Text = "<!-- #include file=""content/home/home.txt"" -->"
        'Response.Write("about page...<br />")
        'Response.Write(Request.Form("contentIdx") & "....<br />")
        'Response.Write(contentIdxSS.Value)

    End Sub


    Sub insert(ByVal sender As Object, ByVal e As ListViewInsertEventArgs)

        Dim tb = New TextBox
        Dim donorNumString As String
        Dim barcodeValidFlg As Boolean = True

        'gets donor number from listview control
        tb = ListView1.InsertItem.FindControl("donorNumTextBox")

        donorNumString = tb.Text

        'tb.Text = donorNumString.ToLower

        Dim validBarcode = New BETAbarcodeValidator(donorNumString)

        validBarcode.validate(donorNumString)
        barcodeValidFlg = validBarcode.BarcodeValid

        If (barcodeValidFlg = False) Then
            e.Cancel = True
            Button3_ModalPopupExtender.Show()

        End If
    End Sub


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub



        <asp:ListView ID="ListView1" runat="server" 
            DataKeyNames="donorNum" 
            DataSourceID="SqlDataSource1" 
            InsertItemPosition="FirstItem" 
            EnableModelValidation="True">

            <AlternatingItemTemplate>
                <tr style="background-color: #FFFFFF;color: #284775;">
                    <td>
                        <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" CausesValidation="False" 
                            Text="Delete" />
                    </td>
                    <td class="testSelection">
                        <asp:Label ID="entryNumLabel" runat="server" Text='<%# Eval("entryNum") %>' />
                    </td>
                    <td class="donorNumberTbxEntryCell">
                        <asp:Label ID="donorNumLabel" runat="server"
                            Text='<%# Eval("donorNum") %>' />
                    </td>

                    <td class="testSelection">
                        <asp:CheckBox ID="CHGCheckBox" runat="server" Checked='<%# Eval("CHG") %>' 
                            Enabled="false" />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="CMVCheckBox" runat="server" Checked='<%# Eval("CMV") %>' 
                            Enabled="false" />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="devHCTPCheckBox" runat="server" 
                            Checked="true" Enabled="false" />
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <EditItemTemplate>
                <tr style="background-color: #999999;">
                    <td>
                        <asp:Button ID="UpdateButton" runat="server" CommandName="Update" 
                            Text="Update" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                            Text="Cancel" />
                    </td>
                    <td>
                        <asp:TextBox ID="entryNumTextBox" runat="server" 
                            Text='<%# Bind("entryNum") %>' />
                    </td>


                    <td class="donorNumberTbxEntryCell">
                        <asp:Label ID="donorNumLabel1" runat="server" Text='<%# Eval("donorNum") %>' />
                    </td>

                    <td class="testSelection">
                        <asp:CheckBox ID="CHGCheckBox" runat="server" Checked='<%# Bind("CHG") %>' />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="CMVCheckBox" runat="server" Checked='<%# Bind("CMV") %>' />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="devHCTPCheckBox" runat="server" 
                            Checked="true" />
                    </td>
                </tr>
            </EditItemTemplate>
            <EmptyDataTemplate>
                <table runat="server" 
                    style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
                    <tr>
                        <td>
                            No data was returned.</td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <InsertItemTemplate>
                <tr style="">
                    <td>
                        <asp:Button ID="InsertButton" runat="server" CommandN开发者_如何学运维ame="Insert" 
                            Text="Save" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                            Text="Clear" />
                    </td>
                    <td class="testSelection">
                        <asp:label ID="entryNumTextBox" runat="server" 
                            Text='<%# Bind("entryNum") %>' />
                    </td>
                    <td class="donorNumberTbxEntryCell">
                        <asp:TextBox ID="donorNumTextBox" class="donorNumTbxEntry" runat="server" 
                            Text='<%# Bind("donorNum") %>' />
                    </td>

                    <td class="testSelection">
                        <asp:CheckBox ID="CHGCheckBox" runat="server" Checked='<%# Bind("CHG") %>' />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="CMVCheckBox" runat="server" Checked='<%# Bind("CMV") %>' />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="devHCTPCheckBox" runat="server" 
                            Checked="true" />
                    </td>
                </tr>
            </InsertItemTemplate>
            <ItemTemplate>
                <tr style="background-color: #E0FFFF;color: #333333;">
                    <td>
                        <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" CausesValidation="False"  
                            Text="Delete" />
                    </td>
                    <td class="testSelection">
                        <asp:Label ID="entryNumLabel" runat="server" Text='<%# Eval("entryNum") %>' />
                    </td>
                    <td>
                        <asp:Label ID="donorNumLabel" runat="server" 
                            Text='<%# Eval("donorNum") %>' />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="CHGCheckBox" runat="server" Checked='<%# Eval("CHG") %>' 
                            Enabled="false" />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="CMVCheckBox" runat="server" Checked='<%# Eval("CMV") %>' 
                            Enabled="false" />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="devHCTPCheckBox" runat="server" 
                            Checked="true" Enabled="false" />
                    </td>
                </tr>
            </ItemTemplate>
            <LayoutTemplate>
                <table runat="server">
                    <tr runat="server">
                        <td runat="server">
                            <table ID="itemPlaceholderContainer" runat="server" border="1" 
                                style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
                                <tr runat="server" style="background-color: #E0FFFF;color: #333333;">
                                    <th runat="server">
                                    </th>
                                    <th runat="server">
                                        #</th>
                                    <th runat="server">
                                        Donor Number</th>
                                    <th runat="server">
                                        CHG</th>
                                    <th runat="server">
                                        CMV</th>
                                    <th runat="server">
                                        HCTP</th>
                                </tr>
                                <tr ID="itemPlaceholder" runat="server">
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr runat="server">
                        <td runat="server" 
                            style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
            <SelectedItemTemplate>
                <tr style="background-color: #E2DED6;font-weight: bold;color: #333333;">
                    <td>
                        <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" CausesValidation="False" 
                            Text="Delete" />
                    </td>
                    <td>
                        <asp:Label ID="entryNumLabel" runat="server" Text='<%# Eval("entryNum") %>' />
                    </td>
                    <td>
                        <asp:Label ID="donorNumLabel" runat="server" 
                            Text='<%# Eval("donorNum") %>' />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="CHGCheckBox" runat="server" Checked='<%# Eval("CHG") %>' 
                            Enabled="false" />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="CMVCheckBox" runat="server" Checked='<%# Eval("CMV") %>' 
                            Enabled="false" />
                    </td>
                    <td class="testSelection">
                        <asp:CheckBox ID="devHCTPCheckBox" runat="server" 
                            Checked="true" Enabled="false" />
                    </td>
                </tr>
            </SelectedItemTemplate>
        </asp:ListView>


    <p class="style1" />
        <asp:Button ID="Button1" runat="server" Text="Submit Order" />
    </td>

</tr>
</table>

<% If (iPreLoadIndex = 2) Then%>
   <script type="text/javascript">changeContent(1,2); </script>
<% ElseIf (iPreLoadIndex = 3) Then%>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            DeleteCommand="DELETE FROM [ctsTPAOrder] WHERE [donorNum] = @original_donorNum" 
            InsertCommand="INSERT INTO [ctsTPAOrder] ([entryNum], [donorNum], [orderID], [CHG], [CMV], [devHCTP]) VALUES (@entryNum, @donorNum, @orderID, @CHG, @CMV, 1)" 
            SelectCommand="SELECT [entryNum], [donorNum], [CHG], [CMV], [devHCTP] FROM [ctsTPAOrder] WHERE ([orderID] = @orderID) ORDER BY [entryNum] DESC" 
            UpdateCommand="UPDATE [ctsTPAOrder] SET [entryNum] = @entryNum, [CHG] = @CHG, [CMV] = @CMV, [devHCTP] = @devHCTP WHERE [donorNum] = @original_donorNum" 
            OldValuesParameterFormatString="original_{0}">
            <DeleteParameters>
                <asp:Parameter Name="original_donorNum" Type="String" />
            </DeleteParameters>
            <InsertParameters>
                <asp:ControlParameter Name="orderID" ControlID="orderNumLbl" Type="Int32" />
                <asp:SessionParameter Name="entryNum" SessionField="entryNum" Type="Int32" />
                <asp:Parameter Name="donorNum" Type="String" />
                <asp:ControlParameter Name="collectionDate" ControlID="tbxCollDate" Type="DateTime" />
                <asp:Parameter Name="CHG" Type="Boolean" />
                <asp:Parameter Name="CMV" Type="Boolean" />
                <asp:Parameter Name="devHCTP" Type="Boolean" />
            </InsertParameters>
            <SelectParameters>
                <asp:SessionParameter Name="orderID" SessionField="orderNum" Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="entryNum" Type="Int32" />
                <asp:Parameter Name="CHG" Type="Boolean" />
                <asp:Parameter Name="CMV" Type="Boolean" />
                <asp:Parameter Name="devHCTP" Type="Boolean" />
                <asp:Parameter Name="original_donorNum" Type="String" />
                            <asp:ControlParameter Name="orderID" ControlID="orderNumLbl" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>


Try adding a handler for OnItemInserting and Cancel the operation there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜