我有一個編輯配置文件的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;
查看「Click Once」應用程序,它們是可從服務器運行的Windows Forms應用程序 –