gpt4 book ai didi

wcf - 在我的 Web 应用程序项目中重用来自网站项目的代码

转载 作者:行者123 更新时间:2023-12-04 06:03:26 24 4
gpt4 key购买 nike

这是代码。我现在也在代码隐藏中遇到错误,即变量已经存在并且方法具有相同的签名,但我无法在后面的代码中的任何地方找到这些重复项。

.ASPX

<%@ Page Title="Mijn oefeningen" Language="VB" MasterPageFile="~/main.master" AutoEventWireup="false" Inherits="Fitness2.exercises" Codebehind="exercises.aspx.vb" %>
<%@ MasterType VirtualPath="~/main.master" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPHBigBanner" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="CPHQuickSearch" Runat="Server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="CPHCenter" Runat="Server">


<asp:Label ID="lblStatus" runat="server" />

<div class="section">
<div class="action">
<asp:Button ID="btnAddNew" runat="server" Text="Nieuwe oefening aanmaken" />
</div>
</div>


<div class="section">

<asp:GridView DataKeyNames="id" Width="100%" ID="gvExercises" runat="server" GridLines="Horizontal" CellPadding="10" AllowSorting="true" AllowPaging="True" PageSize="50" AutoGenerateColumns="False" >
<PagerSettings Mode="NumericFirstLast" Position="Bottom" />
<PagerStyle CssClass="gridpager" HorizontalAlign="Center" />
<RowStyle CssClass="gv_even" Height="20" />
<AlternatingRowStyle CssClass="gv_odd" />
<HeaderStyle CssClass="gv_header" />
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Bekijk"/>
<asp:TemplateField>
<ItemTemplate>
<asp:linkButton runat="server" CausesValidation="false" ID="Edit" Text="Bewerk" CommandName="EditItem" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="title" HeaderText="Oefening naam">
<ItemTemplate>
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("title") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="category" HeaderText="Categorie">
<ItemTemplate>
<asp:Label ID="category" runat="server" Text='<%# Eval("category") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
&nbsp;&nbsp;&nbsp;<asp:ImageButton runat="server" ImageUrl="/images/delete.png" CausesValidation="false" ID="Delete" OnClientClick="javascript:return confirm('Weet je zeker dat je dit item wilt verwijderen?');" ToolTip="Verwijder" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<asp:ObjectDataSource ID="odsExercises" runat="server" SortParameterName="sortExpression" SelectMethod="GetExercisesPagedSorted" InsertMethod="InsertExercise" DeleteMethod="DeleteExerciseById" SelectCountMethod="GetExercisesCount" TypeName="ExerciseBLL" EnablePaging="true">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>

<asp:DetailsView GridLines="None" AutoGenerateRows="False" DataKeyNames="id" DataSourceID="odsdvExercises" ID="dvExercises" Width="100%" runat="server">
<Fields>
<asp:CommandField ButtonType="Link" ValidationGroup="Exercises" ControlStyle-CssClass="link" EditText="Item bewerken" NewText="Nieuw item aanmaken" UpdateText="Opslaan" InsertText="Opslaan" ShowEditButton="True" CancelText="Annuleren" ShowInsertButton="true" />

<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<%#Eval("id")%>
</ItemTemplate>
<EditItemTemplate>
<%#Eval("id")%>
</EditItemTemplate>
<InsertItemTemplate>
</InsertItemTemplate>
</asp:TemplateField>



<asp:TemplateField HeaderText="Oefening naam *" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("title") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="title" Width="400" MaxLength="150" CssClass="textbox" runat="server" Text='<%# Bind("title") %>'/>
<asp:RequiredFieldValidator ID="ReqdfguiredF43ieldValidator1" ValidationGroup="Exercises" ControlToValidate="title" runat="server" ErrorMessage="*" Display="Dynamic"/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="title" Width="400" MaxLength="150" CssClass="textbox" runat="server" Text=""/>
<asp:RequiredFieldValidator ID="Requdf1giredF43ieldVagfglidator1" ValidationGroup="Exercises" ControlToValidate="title" runat="server" ErrorMessage="*" Display="Dynamic"/>
</InsertItemTemplate>
</asp:TemplateField>



<asp:TemplateField HeaderText="Doelstelling">
<ItemTemplate>
<asp:Literal ID="Lafgdfdbel1c" runat="server" Text='<%# Eval("goal").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="goal" MaxLength="150" Width="400" CssClass="textbox" runat="server" Text='<%# Bind("goal") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="goal" MaxLength="150" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText="Tempo">
<ItemTemplate>
<asp:Literal ID="Lafdgdfdbel1c" runat="server" Text='<%# Eval("tempo").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tempo" MaxLength="50" Width="400" CssClass="textbox" runat="server" Text='<%# Bind("tempo") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="tempo" MaxLength="50" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText="Omschrijving">
<ItemTemplate>
<asp:Literal ID="Lafdgdfdbel1c" runat="server" Text='<%# Eval("description").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="description" TextMode="MultiLine" Rows="3" Columns="50" CssClass="textbox" runat="server" Text='<%# Bind("description") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="description" TextMode="MultiLine" Rows="3" Columns="50" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>


<asp:TemplateField HeaderText="Aantal sets">
<ItemTemplate>
<asp:Literal ID="La1fgdfdbel1c" runat="server" Text='<%# Eval("sets").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="sets" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("sets") %>'/>
<asp:RegularExpressionValidator ControlToValidate="sets" ValidationGroup="Exercises" ID="RegularExpressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="sets" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="sets" ValidationGroup="Exercises" ID="RegularExpressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Minimum herhalingen">
<ItemTemplate>
<asp:Literal ID="La1f3gdfdbel1c" runat="server" Text='<%# Eval("reprange_min").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="reprange_min" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("reprange_min") %>'/>
<asp:RegularExpressionValidator ControlToValidate="reprange_min" ValidationGroup="Exercises" ID="RegularExpresfsionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="reprange_min" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="reprange_min" ValidationGroup="Exercises" ID="RegularExpresfsionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Maxmimum herhalingen">
<ItemTemplate>
<asp:Literal ID="La1f3gdfdb6el1c" runat="server" Text='<%# Eval("reprange_max").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="reprange_max" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("reprange_max") %>'/>
<asp:RegularExpressionValidator ControlToValidate="reprange_max" ValidationGroup="Exercises" ID="RegularExspressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="reprange_max" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="reprange_max" ValidationGroup="Exercises" ID="RegularsExpressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Minuten">
<ItemTemplate>
<asp:Literal ID="La11f3gdfdb6el1c" runat="server" Text='<%# Eval("minutes").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="minutes" MaxLength="3" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("minutes") %>'/>
<asp:RegularExpressionValidator ControlToValidate="minutes" ValidationGroup="Exercises" ID="RegularExpressionValidator8" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="minutes" MaxLength="3" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="minutes" ValidationGroup="Exercises" ID="RegularExpressionValidator8" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="YouTube link">
<ItemTemplate>
<asp:Literal ID="La11f3gdfd2b6el1c" runat="server" Text='<%# Fitness2.GlobalFunctions.GetVideoEmbed(Eval("youtube").tostring) %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="youtube" MaxLength="50" Width="400" CssClass="textbox" runat="server" Text='<%# Bind("youtube") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="youtube" MaxLength="2" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Categorie" HeaderStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Label ID="Label1b" runat="server" Text='<%# Bind("category") %>'/>
</ItemTemplate>
<EditItemTemplate>
<table>
<tr>
<td>Selecteer bestaande categorie:</td>
<td>
<asp:DropDownList ID="ddlcategory" SelectedValue='<%# Bind("category") %>' DataSourceID="sqldsCategories" DataTextField="title" DataValueField="title" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>of maak een nieuwe categorie aan:</td>
<td>
<asp:TextBox ID="category" Width="200" MaxLength="50" CssClass="textbox" runat="server" />
<asp:RequiredFieldValidator ID="RequirebbdF43ieldValidator1" ValidationGroup="tasks" ControlToValidate="category" runat="server" ErrorMessage="*" Display="Dynamic"/>
</td>
</tr>
</table>
</EditItemTemplate>
<InsertItemTemplate>
<table>
<tr>
<td>Selecteer bestaande categorie:</td>
<td>
<asp:DropDownList ID="ddlcategory" DataSourceID="sqldsCategories" DataTextField="title" DataValueField="title" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>of maak een nieuwe categorie aan:</td>
<td>
<asp:TextBox ID="category" Width="200" MaxLength="50" CssClass="textbox" runat="server" />
<asp:RequiredFieldValidator ID="RequirebbdF43ieldValidator1" ValidationGroup="tasks" ControlToValidate="category" runat="server" ErrorMessage="*" Display="Dynamic"/>
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:TemplateField>



</Fields>


</asp:DetailsView>


<asp:ObjectDataSource ID="odsdvExercises" TypeName="ExerciseBLL" SelectMethod="GetExerciseById" InsertMethod="InsertExercise" UpdateMethod="UpdateExercise" runat="server">
<SelectParameters>
<asp:ControlParameter ControlID="gvExercises" Name="id" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

<asp:SqlDataSource ID="sqldsCategories" ConnectionString="<%$ConnectionStrings:conn1 %>" runat="server"></asp:SqlDataSource>



</div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="CPHRight" Runat="Server">
</asp:Content>

.ASPX.VB
Imports Fitness2.GlobalFunctions
Imports System.Drawing
Imports System.IO

Partial Class exercises
Inherits System.Web.UI.Page

Private _userid As String

在这里我得到错误:'_userid' 在这个类中已经被声明为 'Private _userid As String'。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load   

在这里我得到错误:'Protected Sub Page_Load(sender As Object, e As System.EventArgs)'有多个具有相同签名的定义。
_userid = GetFieldFromSession(Session, "//root/user/userid")

If Not Page.IsPostBack Then
BindExercises()
End If


End Sub



'**************** TASKS ****************
Protected Sub BindExercises()
odsExercises.SelectParameters.Clear()
gvExercises.DataSourceID = "odsExercises"
odsExercises.SelectParameters.Add("maximumRows", gvExercises.PageSize)
odsExercises.SelectParameters.Add("startRowIndex", gvExercises.PageIndex)
odsExercises.SelectParameters.Add("sortExpression", odsExercises.SortParameterName)
odsExercises.SelectParameters.Add("userid", _userid)
'gvExercises.DataBind()

End Sub

Protected Sub lbtnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Title As String = Trim(CType(dvExercises.FindControl("title"), TextBox).Text)
Dim userid As String = _userid
Dim goal As String = Trim(CType(dvExercises.FindControl("goal"), TextBox).Text)
Dim tempo As String = Trim(CType(dvExercises.FindControl("tempo"), TextBox).Text)
Dim description As String = Trim(CType(dvExercises.FindControl("description"), TextBox).Text)
If description.Length > 4000 Then description = description.Substring(0, 4000)

Dim sets As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("sets"), TextBox).Text), sets)
Dim reprange_min As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_min"), TextBox).Text), reprange_min)
Dim reprange_max As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_max"), TextBox).Text), reprange_max)
Dim minutes As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("minutes"), TextBox).Text), minutes)

Dim youtube As String = Trim(CType(dvExercises.FindControl("youtube"), TextBox).Text)
'Dim ispublic As Boolean = CType(dvExercises.FindControl("ispublic"), CheckBox).Checked

Dim category As String = Trim(CType(dvExercises.FindControl("category"), TextBox).Text)
Dim categorydropdown As DropDownList = CType(dvExercises.FindControl("ddlcategory"), DropDownList)
If category = "" Then 'user wants to create new category
If categorydropdown.Items.Count = 0 Then
lblStatus.Text = GetStatus("Maak aub eerst een categorie aan", True)
Else
If categorydropdown.SelectedIndex <> -1 Then category = CType(dvExercises.FindControl("ddlcategory"), DropDownList).Text
End If
End If


Dim TA As New fitnessTableAdapters.exercisesTableAdapter
Dim returnval As Integer
TA.InsertExercise(New Guid(userid), Title, category, goal, tempo, description, sets, reprange_min, reprange_max, minutes, youtube, "", False, 0, returnval)
If returnval > 0 Then
Session("exerciseId") = returnval
gvExercises.DataBind()
lblStatus.Text = GetStatus("Oefening toegevoegd", False)
Else
lblStatus.Text = GetStatus("Whoops", True)
End If
End Sub


Protected Sub dvExercises_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvExercises.ItemInserting
Dim Title As String = Trim(CType(dvExercises.FindControl("title"), TextBox).Text)
Dim userid As String = _userid
Dim goal As String = Trim(CType(dvExercises.FindControl("goal"), TextBox).Text)
Dim tempo As String = Trim(CType(dvExercises.FindControl("tempo"), TextBox).Text)
Dim description As String = Trim(CType(dvExercises.FindControl("description"), TextBox).Text)
If description.Length > 4000 Then description = description.Substring(0, 4000)

Dim sets As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("sets"), TextBox).Text), sets)
Dim reprange_min As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_min"), TextBox).Text), reprange_min)
Dim reprange_max As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_max"), TextBox).Text), reprange_max)
Dim minutes As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("minutes"), TextBox).Text), minutes)

Dim youtube As String = Trim(CType(dvExercises.FindControl("youtube"), TextBox).Text)
'Dim ispublic As Boolean = CType(dvExercises.FindControl("ispublic"), CheckBox).Checked

Dim category As String = Trim(CType(dvExercises.FindControl("category"), TextBox).Text)
Dim categorydropdown As DropDownList = CType(dvExercises.FindControl("ddlcategory"), DropDownList)
If category = "" Then 'user wants to create new category
If categorydropdown.Items.Count = 0 Then
lblStatus.Text = GetStatus("Maak aub eerst een categorie aan", True)
Else
If categorydropdown.SelectedIndex <> -1 Then category = CType(dvExercises.FindControl("ddlcategory"), DropDownList).Text
End If
End If

Dim TA As New fitnessTableAdapters.exercisesTableAdapter
Dim returnval As Integer
TA.InsertExercise(New Guid(userid), Title, category, goal, tempo, description, sets, reprange_min, reprange_max, minutes, youtube, "", False, 0, returnval)
If returnval > 0 Then
Session("exerciseId") = returnval
gvExercises.DataBind()
lblStatus.Text = GetStatus("Oefening toegevoegd", False)
Else
lblStatus.Text = GetStatus("Whoops", True)
End If

e.Cancel = True
End Sub

Protected Sub odsdvExercises_Inserted(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs) Handles odsdvExercises.Inserted
gvExercises.DataBind()
End Sub

Protected Sub odsdvExercises_Updated(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs) Handles odsdvExercises.Updated
gvExercises.DataBind()
End Sub

Protected Sub dvExercises_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles dvExercises.ItemUpdating

Dim ID As Integer = CInt(dvExercises.DataKey.Value)
'retrieve controls
Dim Title As String = Trim(CType(dvExercises.FindControl("title"), TextBox).Text)
Dim userid As String = _userid
Dim goal As String = Trim(CType(dvExercises.FindControl("goal"), TextBox).Text)
Dim tempo As String = Trim(CType(dvExercises.FindControl("tempo"), TextBox).Text)
Dim description As String = Trim(CType(dvExercises.FindControl("description"), TextBox).Text)
If description.Length > 4000 Then description = description.Substring(0, 4000)

Dim sets As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("sets"), TextBox).Text), sets)
Dim reprange_min As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_min"), TextBox).Text), reprange_min)
Dim reprange_max As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_max"), TextBox).Text), reprange_max)
Dim minutes As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("minutes"), TextBox).Text), minutes)

Dim youtube As String = Trim(CType(dvExercises.FindControl("youtube"), TextBox).Text)
'Dim ispublic As Boolean = CType(dvExercises.FindControl("ispublic"), CheckBox).Checked

Dim category As String = Trim(CType(dvExercises.FindControl("category"), TextBox).Text)
Dim categorydropdown As Integer = CType(dvExercises.FindControl("ddlcategory"), DropDownList).SelectedIndex
If categorydropdown <> -1 Then category = CType(dvExercises.FindControl("ddlcategory"), DropDownList).Text

Dim TA As New fitnessTableAdapters.exercisesTableAdapter
Dim dt As fitness.exercisesDataTable = TA.GetExerciseById(ID)
Dim returnval As Integer = TA.Update(New Guid(userid), Title, category, goal, tempo, description, sets, reprange_min, reprange_max, minutes, youtube, dt(0).locpath.ToString, False, DateTime.Now, ID)

Select Case returnval
Case 0
lblStatus.Text = GetStatus("Whoops", True)
Case 1
gvExercises.DataBind()
lblStatus.Text = GetStatus("Item opgeslagen", False)
End Select
e.Cancel = True
End Sub

Protected Sub gvExercises_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvExercises.RowDataBound
Dim gvr As GridViewRow = e.Row
If gvr.RowType = DataControlRowType.DataRow Then
Dim imgBtn As ImageButton
imgBtn = CType(e.Row.FindControl("Delete"), ImageButton)
imgBtn.CommandArgument = gvr.RowIndex.ToString

Dim lnkBtn As LinkButton
lnkBtn = CType(e.Row.FindControl("Edit"), LinkButton)
lnkBtn.CommandArgument = gvr.RowIndex.ToString
End If
End Sub

Protected Sub gvExercises_OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvExercises.RowCommand
If e.CommandName = "DeleteEvent" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim data As DataKey = gvExercises.DataKeys(index)
Dim objectId As Integer = data.Values("id")
odsExercises.DeleteParameters.Clear()
odsExercises.DeleteParameters.Add("id", objectId)
odsExercises.Delete()
End If

If e.CommandName = "EditItem" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim data As DataKey = gvExercises.DataKeys(index)
Dim objectId As Integer = data.Values("id")
'floran
ViewState("id") = objectId.ToString
BindDetailsView()
'gvExercises.SelectedValue
'dvExercises.ChangeMode(DetailsViewMode.Edit)
End If
End Sub

Protected Sub dvExercises_ItemCommand(ByVal sender As Object, ByVal e As DetailsViewCommandEventArgs) Handles dvExercises.ItemCommand

End Sub

Protected Sub BindDetailsView()
Dim TA As New fitnessTableAdapters.exercisesTableAdapter
dvExercises.DataSourceID = ""
dvExercises.DataSource = TA.GetExerciseById(ViewState("id")) ' customer.FetchByCustomerType(ViewState("CustomerType").ToString())
dvExercises.DataBind()
dvExercises.ChangeMode(DetailsViewMode.Edit)

End Sub

Protected Sub btnAddNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
dvExercises.ChangeMode(DetailsViewMode.Insert)
End Sub

Protected Sub gvExercises_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvExercises.SelectedIndexChanged
If gvExercises.SelectedDataKey IsNot Nothing Then
Session("exerciseId") = CInt(gvExercises.SelectedDataKey.Value)
'ReportError("Session(exerciseId)", Session("exerciseId").ToString)
End If
End Sub




End Class

最佳答案

我没有保留这两种解决方案,而是将网站项目转换为 WAP。

您需要将网站项目中 app_code 文件夹中的所有内容移动到单独的类库中,或者直接将它们包含在 WAP 中(可能没有 app_code 文件夹,因为它具有特殊意义),在这种情况下它们将是编译成主要的 WAP 程序集。

您可能必须使用命名空间等才能使其正常工作,但影响应该很小。主要区别(和好处)是代码是在编译时构建的,您的源代码 (*.cs) 没有部署到服务器。

另请注意,在 VS 中,有一个上下文菜单选项可将网站项目实体转换为 Web 应用程序实体。这将创建 WAP 所需的 .designer.cs 文件,并在解决方案资源管理器中组织这些文件 - .aspx、.cs 和 .designer.cs 文件将显示为可扩展节点。

Here's an excellent article on MSDN covering the conversion process .

一旦您运行了 WAP,添加服务就像 right click - add new item... 一样简单。

关于wcf - 在我的 Web 应用程序项目中重用来自网站项目的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8670294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com