private void btnImport_Click(object sender, EventArgs e) { if (memoryFilenames == null || memoryFilenames.Length == 0) { MessageBox.Show("请选择需要转换文件"); return; } if (cbbSystem.SelectedItem == null) { MessageBox.Show("请选择需要转换文件的格式"); return; } if (!string.IsNullOrEmpty(txtDatabase.Text.Trim()) && !string.IsNullOrEmpty(txtTitle.Text.Trim()) && !string.IsNullOrEmpty(txtSearchDate.Text.Trim()) && !string.IsNullOrEmpty(txtTimespan.Text.Trim()) && !string.IsNullOrEmpty(txtSearchCondition.Text.Trim())) { } else { MessageBox.Show("请输入标题或备注内容"); return; } iconvert.Clear(); foreach (var file in memoryFilenames) { iconvert.Read(file); } using (StreamReader reader = new StreamReader("template.html", Encoding.UTF8)) { html = reader.ReadToEnd(); html_code = GetTemplateCode(); string title = txtTitle.Text.Trim(); //string content = iconvert.ToHtml(); string searchdate = txtSearchDate.Text.Trim(); string timespan = txtTimespan.Text.Trim(); string searchcondition = txtSearchCondition.Text.Trim(); string database = txtDatabase.Text.Trim(); html = html.Replace("${title}$", title); html_code = html_code.Replace("${title}$", title); List <string> years = new List <string>(); if (string.IsNullOrEmpty(txtYear.Text.Trim())) { } else if (txtYear.Text.Trim().Contains(';')) { foreach (var year in txtYear.Text.Trim().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { years.Add(year.Trim()); } } else { years.Add(txtYear.Text.Trim()); } #region 全部格式 html = html.Replace("${content}$", iconvert.ToHtml(years)); html = html.Replace("${searchdate}$", searchdate); html = html.Replace("${searchTimeSpan}$", timespan); html = html.Replace("${searchCount}$", iconvert.Count().ToString()); html = html.Replace("${searchCondition}$", searchcondition); html = html.Replace("${database}$", database); #endregion #region code格式 html_code = html_code.Replace("${content}$", iconvert.ToHtml(years)); html_code = html_code.Replace("${searchdate}$", searchdate); html_code = html_code.Replace("${searchTimeSpan}$", timespan); html_code = html_code.Replace("${searchCount}$", iconvert.Count().ToString()); html_code = html_code.Replace("${searchCondition}$", searchcondition); html_code = html_code.Replace("${database}$", database); #endregion //content=string.Format(html, txtTitle.Text.Trim(), iconvert.ToHtml()); webBrowser1.DocumentText = html; this.Text = title; txtRecordCount.Text = iconvert.Count().ToString(); } }