2013-04-12 55 views
0

我有一個編輯配置文件的C#Windows窗體應用程序。它基本上從XML文件讀取一個字符串,並允許管理員在需要時編輯該字符串。將Windows窗體應用程序轉換爲網絡用戶控件(功能)

我被要求對此進行設置我們的服務器上,以便用戶可以登錄到網站並運行應用程序。我已經完成了沒有Web開發,我看到很多網上的答案,說你不能將Windows窗體應用程序轉換爲Web窗體應用程序。但是這些答案似乎特指轉換UI。

我真的只有在移植的功能感興趣。我的UI只是一個編輯字符串的文本框,一個顯示當前字符串值的列表視圖,以及一個提交更改的按鈕。我非常樂意爲我的內容設計一個新的用戶界面。但功能如何?我可以拿走當前的C#代碼並將其掛接到Web UI中嗎?或者我需要爲網絡編寫不同的代碼?

從button_Click和的KeyDown功能

除此之外,我真的有兩個:

列表的字符串是什麼:

/// <summary> 
    /// Checks to see if the phrase is already in the list. If not, then add it. 
    /// </summary> 
    /// <param name="addThis"></param> 
    internal void addPhrase(string addThis) 
    { 
     foreach (ListViewItem lvi in listView1.Items) 
     { 
      if (addThis == lvi.Text) 
      { 
       lvi.Selected = true; 
       MessageBox.Show("List of phrases already contains \"" + addThis + ".\" Please check the phrase again. \nIf the problem persists, contact your system administrator."); 
       return; 
      } 
     } 

     string myFile = Environment.CurrentDirectory + "\\CGEmailCnctr.exe.config"; 
     string pattern = "messageFilter"; 
     string pattern2 = ";\""; 
     string igPhrase = ";" + addThis + ";\""; 

     string strFile = File.ReadAllText(myFile); 
     var sb = new StringBuilder(strFile); 

     //Find messageFilter, the key we need to change, and get the index of it 
     int index = strFile.IndexOf(pattern); 
     string after = strFile.Substring(index); 

     strFile = strFile.Substring(0, index) + strFile.Substring(index).Replace(pattern2, igPhrase); 

     //MessageBox.Show(strFile); 

     try 
     { 
      File.WriteAllText(myFile, strFile); 

      MessageBox.Show("Operation complete. Messages with the phrase \"" + addThis + "\" in the subject line will no longer automatically generate ChangeGear tickets.", "Phrase Added"); 

      listView1.Items.Add(addThis); 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("Operation failed. \n" + ex.ToString()); 
     } 
    } 

我使用:

/// <summary> 
    /// Find current phrases being ignored and list them 
    /// </summary> 
    internal void listPhrases() 
    { 
     string myFile = Environment.CurrentDirectory + "\\CGEmailCnctr.exe.config"; 

     string strFile = File.ReadAllText(myFile); 
     var sb = new StringBuilder(strFile); 

     string getThis = "<add key=\"messageFilter\" value=\""; 
     string subStr = strFile.Substring(strFile.IndexOf(getThis) + getThis.Length); 
     string[] igPhrases = subStr.Substring(0, subStr.IndexOf(";\"")).Split(';'); 

     foreach (string s in igPhrases) 
     { 
      listView1.Items.Add(s); 
     } 
    } 

添加到字符串語句,萬一他們揭示什麼光:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.IO; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
+1

查看「Click Once」應用程序,它們是可從服務器運行的Windows Forms應用程序 –

回答

1

有幾個問題,如果你嘗試使用Web窗體驗證碼,第一個是你使用的:Environment.CurrentDirectory這可能需要使用Server.MapPath相反,另一種是你直接有電話的使用者介面代碼,例如MessageBox.ShowListViewItem,連接到用戶界面的代碼必須要重新考慮,所以你有前進的道路。

您可以更好地嘗試,從頭創建Web窗體,而不是移植代碼的應用程序,它可能是更容易這樣,將有助於你更好地理解Web窗體是如何工作的。

+1

當然,如果您急於和/或應用程序需要修改本地計算機上的文件客戶端點擊一次可以幫助你。 – Rafael

相關問題