根據軟件體系結構創建三個Project層--Application層,Business laer和DataAccess層。現在我想從應用程序層訪問Richtextbox到業務邏輯層。層我實現了一個WikipediaPerseCode來顯示來自維基百科page的短文本。我編寫代碼。但我不確定如何引用和顯示應用程序層中的文本。我在嘗試,但由於我是softawre架構處理中的新手,我不知道該怎麼做。從BusinessLayer訪問RichtextBox並使用c顯示文本#
我的應用層是喜歡 -
namespace TouristPlace
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ShortText.txt1 = richTextBox1;
}
public string SetText1
{
get { return richTextBox1.Text; }
set { richTextBox1.Text = value; }
}
}
}
我的短文本是 - 命名空間WikiPerser { 類ShortText {
public static RichTextBox txt1 = new RichTextBox();
public static void shortText(string name)
{
using (WebClient wc = new WebClient())
{
var startPath = Application.StartupPath;
//var spath = Path.Combine(startPath,@"\ShortText\");
string folderName = Path.Combine(startPath, "Short Text");
System.IO.Directory.CreateDirectory(folderName);
string fileName = name + ".txt";
var path = Path.Combine(folderName, fileName);
var client = new WebClient();
var response = client.DownloadString("https://en.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exlimit=max&explaintext&exintro&titles=" + name + "&redirects=");
var responseJson = JsonConvert.DeserializeObject<RootObject>(response);
var firstKey = responseJson.query.pages.First().Key;
var extract = responseJson.query.pages[firstKey].extract;
try
{
Regex regex = new Regex(@".(?<=\()[^()]*(?=\)).(.)");
string.Format("Before:{0}", extract);
extract = regex.Replace(extract, string.Empty);
string result1 = String.Format(extract);
result1 = Regex.Replace(result1, @"\\n", " ");
//richTextBox1.Text = result;
txt1.Text = extract;
File.WriteAllText(path, txt1.Text);
}
catch (Exception)
{
txt1.Text = "Error";
}
}
}
}
}
這就是所謂的「分層」:你組織代碼層。層只允許調用底層。所以你會有UI - > BL的電話,你會反過來拒絕所有的電話。這有助於保持複雜性並保持代碼的清潔。另外,您可以在這裏使用https://msdn.microsoft.com/en-us/library/ef2xyb33%28v=vs.110%29.aspx。 – mikalai