private void button1_Click(object sender, EventArgs e) { Form3 obj = new Form3("学校名称", "", false); if (obj.ShowDialog() == DialogResult.OK) { string folder = obj.Value.Trim(); if (string.IsNullOrEmpty(folder)) { MessageBox.Show(this, "学校名称不能为空!"); return; } if (FileHelper.CheckFolder(FileHelper.htmlPath, folder) || FileHelper.CheckFolder(FileHelper.imagePath, folder) || folder.StartsWith(".") || folder.Contains("|") || folder.Contains("/") || folder.Contains("\\") || folder.Contains("<") || folder.Contains(">") || folder.Contains("*") || folder.Contains("?") || folder.Contains(":") || folder.Contains("\"")) { MessageBox.Show(this, "学校已经存在或名称不可用!"); return; } FileHelper.WriteFile(FileHelper.htmlPath, folder, "0.html"); schoolMenu1.Add(folder, true, true); } }
private void button7_Click(object sender, EventArgs e) { Form3 obj = new Form3("编写内容", schoolPage1.Content, true); if (obj.ShowDialog() == DialogResult.OK) { string[] newContent = obj.Value.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'); string[] contents = FileHelper.ReadFile(FileHelper.htmlPath, Tag.ToString(), (pageIndex + 1) + ".html"); StringBuilder sb = new StringBuilder(); foreach (string s in contents) { if (s.EndsWith("</br>")) { break; } sb.AppendLine(s); } foreach (string s in newContent) { decimal count = 0; int index1 = 0, index2 = 0; foreach (char c in s) { if (c > 127) { count += 1; } else { count += 0.5M; } if (count > 20) { if (c > 127) { count = 1; } else { count = 0.5M; } sb.AppendLine(s.Substring(index1, index2 - index1) + "</br>"); index1 = index2; } index2++; } if (index2 > index1) { sb.AppendLine(s.Substring(index1, index2 - index1) + "</br>"); } } sb.AppendLine(" </font>"); sb.AppendLine(" </div></div> </td>"); sb.AppendLine(" </tr>"); sb.AppendLine("</table>"); sb.AppendLine("</body>"); sb.AppendLine("</html>"); FileHelper.WriteFile(FileHelper.htmlPath, Tag.ToString(), (pageIndex + 1) + ".html", sb.ToString()); ShowPage(); } }