【发布时间】:2016-01-10 10:47:19
【问题描述】:
我根据软件架构创建了三个项目层-应用层,业务层和数据访问层。现在我想从应用层访问Richtextbox到业务逻辑层。在业务逻辑层中,我实现了一个WikipediaPerseCode来显示来自的短文本维基百科页面。我编写代码。但我不确定如何在应用层引用和显示文本。我正在尝试,但由于我是软件架构处理的新手,我不知道该怎么做。
我的应用层是这样的-
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 { 类短文本 {
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 调用,而你会反过来拒绝所有调用。这有助于保持复杂性并保持代码有点干净。另外,您可以在这里使用msdn.microsoft.com/en-us/library/ef2xyb33%28v=vs.110%29.aspx。
标签: c# winforms architecture richtextbox layer