2011-10-05 3 views
0

웹 응용 프로그램에서 사용자 정의 컨트롤을 사용하고 있습니다. 통신 주소를 입력하는 것입니다.확장 된 기본 주소 상자

2 개의 모드로 주소를 입력 할 수 있습니다 : extended and basic.

extended에서 address1, address2, address3, city, state, zip 및 country를 다른 컨트롤에 입력하고 basic mode에는 간단한 여러 줄 텍스트 상자에 위의 모든 세부 정보를 입력합니다.

토글 버튼은이 모드를 전환하는 데 사용됩니다.

비어있는 모든 텍스트 상자를 vbcrlf과 함께 추가하고 여러 줄 텍스트 상자에 표시하는 것이 간단하기 때문에 확장에서 기본으로 전환하면 작동합니다.

내 문제는 기본에서 확장으로 전환 할 때입니다. 나는 빈 줄이 있는지 없는지 알고 싶다. 동일한 기능을 가진 기존 사용자 정의 컨트롤을 제공 할 수 있다면 여전히 나을 것입니다.

감사합니다. 항

Extended Mode - I enter every thing individually in different textboxes. 

+-------------+ 
|Address 1 | 
+-------------+ 
|    | 
+-------------+ 
|Address 3 | 
+-------------+ 
|    | 
+-------------+ 
|State  | 
+-------------+ 
|    | 
+-------------+ 
|Country  | 
+-------------+ 

      Toggle  


Present scenario - The array 

array(0) = "Address1" 
array(1) = "" 
array(2) = "Address2" 
array(3) = "" 
array(4) = "State" 
array(5) = "" 
array(6) = "Country" 


I click on the Toggle and switch to Basic mode. Here I am displaying all the address lines which are not empty in a long text box with multiline = True. 

+-------------+ 
|Address1  | 
|Address3  | 
|State  | 
|Country  | 
|    | 
+-------------+ 

    Toggle 

Now, i will edit the address and delete the Address3 which is on the line 2. 

+-------------+ 
|Address1  | 
|State  | 
|Country  | 
|    | 
+-------------+ 

    Toggle 

Now when i click on the toggle, i need to see the textboxes in the extended mode are having the correct values. 

+-------------+ 
|Address 1 | 
+-------------+ 
|    | 
+-------------+ 
|    | 
+-------------+ 
|    | 
+-------------+ 
|State  | 
+-------------+ 
|    | 
+-------------+ 
|Country  | 
+-------------+ 

      Toggle  

I think, it is clear. i need to go by line by line only as i can enter the same text in two lines. 

for example 
City - New York. 
State - New York. 

in the above case, i need to identify which new york (City/State) is deleted/modified. 

Thanks. 
-===================== 

답변

0

확인

===================================, 귀하의 편집 된 질문, 나는 당신을 위해 일해야 UserControl을 만들었습니다.

ASCX :

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="MultiFieldTextbox.ascx.vb" Inherits="WebApplication2.MultiFieldTextbox" %> 
<asp:Panel ID="PnlBasic" Visible="false" runat="server"> 
    <asp:TextBox ID="TxtFields" runat="server" TextMode="MultiLine" Width="200" Height="200"></asp:TextBox> 
</asp:Panel> 
<asp:Panel ID="PnlExtended" Visible="true" runat="server"> 
    <asp:TextBox ID="TxtAddress1" runat="server"></asp:TextBox> 
    <asp:TextBox ID="TxtAddress2" runat="server"></asp:TextBox> 
    <asp:TextBox ID="TxtAddress3" runat="server"></asp:TextBox> 
    <asp:TextBox ID="TxtCity" runat="server"></asp:TextBox> 
    <asp:TextBox ID="TxtState" runat="server"></asp:TextBox> 
    <asp:TextBox ID="TxtZip" runat="server"></asp:TextBox> 
    <asp:TextBox ID="TxtCountry" runat="server"></asp:TextBox> 
</asp:Panel> 
<asp:Button ID="BtnSwitchMode" runat="server" Text="switch mode" /> 

ASCX-코드 숨김 : 물론 당신은 당신의 필요 조건에 레이아웃을 변경해야

작동
Public Class MultiFieldTextbox 
    Inherits System.Web.UI.UserControl 

    Public Enum ViewMode As Int32 
     Basic 
     Extended 
    End Enum 

    Public Property Mode As ViewMode 
     Get 
      If Me.PnlBasic.Visible Then 
       Return MultiFieldTextbox.ViewMode.Basic 
      Else 
       Return MultiFieldTextbox.ViewMode.Extended 
      End If 
     End Get 
     Set(ByVal value As ViewMode) 
      Me.PnlBasic.Visible = value = ViewMode.Basic 
      Me.PnlExtended.Visible = value = ViewMode.Extended 
      InitNewMode(value) 
     End Set 
    End Property 

    Public Property Addr1 As String 
     Get 
      Return Me.TxtAddress1.Text.Trim 
     End Get 
     Set(ByVal value As String) 
      Me.TxtAddress1.Text = value.Trim 
     End Set 
    End Property 
    Public Property Addr2 As String 
     Get 
      Return Me.TxtAddress2.Text.Trim 
     End Get 
     Set(ByVal value As String) 
      Me.TxtAddress2.Text = value.Trim 
     End Set 
    End Property 
    Public Property Addr3 As String 
     Get 
      Return Me.TxtAddress3.Text.Trim 
     End Get 
     Set(ByVal value As String) 
      Me.TxtAddress3.Text = value.Trim 
     End Set 
    End Property 
    Public Property City As String 
     Get 
      Return Me.TxtCity.Text.Trim 
     End Get 
     Set(ByVal value As String) 
      Me.TxtCity.Text = value.Trim 
     End Set 
    End Property 
    Public Property State As String 
     Get 
      Return Me.TxtState.Text.Trim 
     End Get 
     Set(ByVal value As String) 
      Me.TxtState.Text = value.Trim 
     End Set 
    End Property 
    Public Property Zip As String 
     Get 
      Return Me.TxtZip.Text.Trim 
     End Get 
     Set(ByVal value As String) 
      Me.TxtZip.Text = value.Trim 
     End Set 
    End Property 
    Public Property Country As String 
     Get 
      Return Me.TxtCountry.Text.Trim 
     End Get 
     Set(ByVal value As String) 
      Me.TxtCountry.Text = value.Trim 
     End Set 
    End Property 

    Private Property FieldInfos As Dictionary(Of String, FieldInfo) 
     Get 
      If ViewState("FieldInfos") Is Nothing Then 
       ViewState("FieldInfos") = New Dictionary(Of String, FieldInfo) 
      End If 
      Return DirectCast(ViewState("FieldInfos"), Dictionary(Of String, FieldInfo)) 
     End Get 
     Set(ByVal value As Dictionary(Of String, FieldInfo)) 
      ViewState("FieldInfos") = value 
     End Set 
    End Property 

    Private Sub InitNewMode(ByVal newMode As ViewMode) 
     Select Case newMode 
      Case ViewMode.Basic 
       Dim builder As New Text.StringBuilder 
       Dim lineNumber As Int32 = 0 
       Dim key = "Addr1" 
       Dim field = Me.Addr1 
       FieldInfos = New Dictionary(Of String, FieldInfo) 

       lineNumber += 1 
       If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine)) 
       FieldInfos.Add(key, New FieldInfo(lineNumber, key, field)) 
       key = "Addr2" 
       field = Me.Addr2 
       lineNumber += 1 
       If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine)) 
       FieldInfos.Add(key, New FieldInfo(lineNumber, key, field)) 
       key = "Addr3" 
       field = Me.Addr3 
       lineNumber += 1 
       If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine)) 
       FieldInfos.Add(key, New FieldInfo(lineNumber, key, field)) 
       key = "City" 
       field = Me.City 
       lineNumber += 1 
       If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine)) 
       FieldInfos.Add(key, New FieldInfo(lineNumber, key, field)) 
       key = "State" 
       field = Me.State 
       lineNumber += 1 
       If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine)) 
       FieldInfos.Add(key, New FieldInfo(lineNumber, key, field)) 
       key = "Zip" 
       field = Me.Zip 
       lineNumber += 1 
       If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine)) 
       FieldInfos.Add(key, New FieldInfo(lineNumber, key, field)) 
       key = "Country" 
       field = Me.Country 
       lineNumber += 1 
       If field.Length <> 0 Then builder.Append(String.Format("{0}{1}", field, ControlChars.NewLine)) 
       FieldInfos.Add(key, New FieldInfo(lineNumber, key, field)) 

       If builder.Length <> 0 Then builder.Length -= ControlChars.NewLine.Length 
       Me.TxtFields.Text = builder.ToString 
      Case ViewMode.Extended 
       Dim lineNumber As Int32 = 0 
       Dim allLines = Me.TxtFields.Text.Split(New String() {ControlChars.NewLine}, StringSplitOptions.None) 
       For Each line In allLines 
        lineNumber += 1 
        ' set value via old line number ' 
        Dim q = From field In Me.FieldInfos 
           Where field.Value.Line = lineNumber 
           Select field 
        If q.Any Then 
         Me.FieldInfos(q.First.Key).Value = line 
        End If 
       Next 
       Dim diff = FieldInfos.Count - allLines.Length 
       If diff <> 0 Then 
        Dim line As Int32 
        For line = (1 + allLines.Length) To (diff + allLines.Length) 
         ' set value=String.Empty for each missing line ' 
         Dim q = From field In Me.FieldInfos 
            Where field.Value.Line = line 
            Select field 
         If q.Any Then 
          Me.FieldInfos(q.First.Key).Value = String.Empty 
         End If 
        Next 
       End If 
       Me.Addr1 = Me.FieldInfos("Addr1").Value 
       Me.Addr2 = Me.FieldInfos("Addr2").Value 
       Me.Addr3 = Me.FieldInfos("Addr3").Value 
       Me.City = Me.FieldInfos("City").Value 
       Me.State = Me.FieldInfos("State").Value 
       Me.Zip = Me.FieldInfos("Zip").Value 
       Me.Country = Me.FieldInfos("Country").Value 
     End Select 
    End Sub 

    Protected Sub BtnSwitchMode_Click(ByVal sender As Object, ByVal e As EventArgs) Handles BtnSwitchMode.Click 
     Dim newMode As ViewMode = If(Me.Mode = ViewMode.Basic, ViewMode.Extended, ViewMode.Basic) 
     Me.Mode = newMode 
    End Sub 

End Class 

<Serializable()> 
Public Class FieldInfo 
    Public Property ID As String 
    Public Property Value As String 
    Public Property Line As Int32 
    Public Sub New(ByVal line As Int32, ByVal ID As String, ByVal Value As String) 
     Me.Line = line 
     Me.ID = ID 
     Me.Value = Value 
    End Sub 
End Class 
+0

경우 모든 주소 라인 (ADD1, ADD2 , add3, city, state, zip, country)가 입력됩니다. add1, add3, state, country를 지정한 다음 확장 모드의 해당 텍스트 상자에 정확하게 배치하는 방법을 알려줍니다. –

+0

감사합니다 Tim.it은 모든 add1, add2, add3, city, state, zip, country가 주어지면 작동합니다. 어떻게하면 add1, add3, state, country 만 부여 할 수 있습니까? 어떻게하면 add2가 비어 있고 add3가 올바른 텍스트 상자에 배치되었는지 알 수 있습니다. 그래서 도움이됩니다. –

+0

@Kompella : 문제를 이해하지 못합니다. 필드가 7 개 있습니다. 기본 모드로 전환하면 길이가 7 인 문자열 배열이 위 속성에 전달됩니다. Textbox.Text는 각 필드 다음에 NewLines으로 올바르게 채워집니다. 사용자가 한 줄을 제거하면 String Array (빈 줄)에 여전히있는 빈 줄이 생기고 Array-Length는 여전히 7입니다. 따라서 확장 모드로 전환하는 데 문제가 없어야합니다. –

관련 문제