private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e) { InitStyle(); style = new StyleDesc(); StyleTitle s_title = new StyleTitle(); if (s_title.ShowDialog() == System.Windows.Forms.DialogResult.OK) { style.style_title = s_title.style_title; frmEditFont font_form = new frmEditFont(); font_form._font = font; if (font_form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { font = font_form._font; // переменная получает значение из формы font.CheckFont(); if (font.font_id == 0) { font.InsertFont(); font.CheckFont(); } style.font = font.font_id; frmEditPar e_par = new frmEditPar(par); e_par._par = par; if (e_par.ShowDialog() == System.Windows.Forms.DialogResult.OK) { par = e_par._par; // переменная получает значение из формы par.CheckPar(); if (par.paragraph_id == 0) { par.InsertPar(); par.CheckPar(); } style.paragraph = par.paragraph_id; style.InsertStyle(); LoadStyle(); bs.DataSource = styleDT; } } } }
public frmStyle() { InitializeComponent(); style = new StyleDesc(); LoadStyle(); bs.DataSource = styleDT; stBindingNavigator.BindingSource = bs; tbStTitle.DataBindings.Add(new Binding("Text", bs, "style_title")); tbSize.DataBindings.Add(new Binding("Text", bs, "size")); tbFTitle.DataBindings.Add(new Binding("Text", bs, "font_title")); tbColor.DataBindings.Add(new Binding("Text", bs, "color")); chbCurs.DataBindings.Add(new Binding("Checked", bs, "italic")); chbZh.DataBindings.Add(new Binding("Checked", bs, "bold")); chPodch.DataBindings.Add(new Binding("Checked", bs, "underlined")); tbAlign.DataBindings.Add(new Binding("Text", bs, "alignment")); tbRight.DataBindings.Add(new Binding("Text", bs, "right_indent")); tbLeft.DataBindings.Add(new Binding("Text", bs, "left_indent")); tbOtst.DataBindings.Add(new Binding("Text", bs, "indent_1st_string")); tbBefore.DataBindings.Add(new Binding("Text", bs, "interval_before")); tbAfter.DataBindings.Add(new Binding("Text", bs, "interval_after")); tbStrInt.DataBindings.Add(new Binding("Text", bs, "interval_between")); }
public static string _Font(System.Data.DataTable dt, int index, bool styleobj, StyleDesc style, GeneralInfo info) { string font = ""; string bold = "", italic = "", underlined = ""; if (styleobj == true) { style.font_title = dt.Rows[index]["font_title"].ToString().Trim(); style.color = dt.Rows[index]["color"].ToString().Trim(); style.size = double.Parse(dt.Rows[index]["size"].ToString().Trim()); style.bold = (bool)dt.Rows[index]["bold"]; style.italic = (bool)dt.Rows[index]["italic"]; style.underlined = (bool)dt.Rows[index]["underlined"]; if (style.bold != false) bold = "полужирный"; if (style.italic != false) italic = "курсив"; if (style.underlined != false) underlined = "подчеркнутый"; font = style.font_title + "; " + style.color + "; " + style.size + "пт"; if (bold != "") font += "; " + bold; if (italic != "") font += "; " + italic; if (underlined != "") font += "; " + underlined; } else { info.num_font_title = dt.Rows[index]["font_title"].ToString().Trim(); info.num_color = dt.Rows[index]["color"].ToString().Trim(); info.num_size = double.Parse(dt.Rows[index]["size"].ToString().Trim()); info.num_bold = (bool)dt.Rows[index]["bold"]; info.num_italic = (bool)dt.Rows[index]["italic"]; info.num_underlined = (bool)dt.Rows[index]["underlined"]; if (info.num_bold != false) bold = "полужирный"; if (info.num_italic != false) italic = "курсив"; if (info.num_underlined != false) underlined = "подчеркнутый"; font = info.num_font_title + "; " + info.num_color + "; " + info.num_size + "пт"; if (bold != "") font += "; " + bold; if (italic != "") font += "; " + italic; if (underlined != "") font += "; " + underlined; } return font; }
public static string Style(StyleDesc style, DataTable styles, List<StyleDesc> styles_list, GeneralInfo info) { string str_style = ""; for (int i = 0; i < styles.Rows.Count; i++) { if (styles.Rows[i]["style_id"] != null) { style = new StyleDesc(); style.style_id = int.Parse(styles.Rows[i]["style_id"].ToString()); style.style_title = styles.Rows[i]["style_title"].ToString().Trim(); str_style += "***" + style.style_title + "***" + Environment.NewLine + "Абзац: " + Paragraph(i, style, styles) + Environment.NewLine + "Шрифт: " + _Font(styles, i, true, style, info) + Environment.NewLine; styles_list.Add(style); } } return str_style; }
public static string Paragraph(int index, StyleDesc style, DataTable styles) { string par = ""; string li = "", ri = "", i1st = "", ib = "", ia = "", ibetween = ""; if (double.Parse(styles.Rows[index]["left_indent"].ToString()) != 0.0) { style.left_indent = double.Parse(styles.Rows[index]["left_indent"].ToString()); li = "отступ слева: " + style.left_indent.ToString() + " см"; } if (double.Parse(styles.Rows[index]["right_indent"].ToString()) != 0.0) { style.right_indent = double.Parse(styles.Rows[index]["right_indent"].ToString()); ri = "отступ справа: " + style.right_indent.ToString() + " см"; } if (double.Parse(styles.Rows[index]["indent_1st_string"].ToString()) != 0.0) { style.indent_1st_string = double.Parse(styles.Rows[index]["indent_1st_string"].ToString()); i1st = "отступ 1-ой строки: " + style.indent_1st_string.ToString() + " см"; } style.interval_before = double.Parse(styles.Rows[index]["interval_before"].ToString()); style.interval_after = double.Parse(styles.Rows[index]["interval_after"].ToString()); style.interval_between = double.Parse(styles.Rows[index]["interval_between"].ToString()); style.align = styles.Rows[index]["alignment"].ToString().Trim(); if (style.interval_before != 0.0) ib = "интервал до абзаца: " + style.interval_before.ToString() + " пт"; if (style.interval_after != 0.0) ia = "интервал после абзаца: " + style.interval_after.ToString() + " пт"; if (style.interval_between != 0.0) ibetween = "междустрочный интервал: " + style.interval_between.ToString() + " пт"; par = "выравнивание - " + style.align; if (li != "") par += "; " + li; if (ri != "") par += "; " + ri; if (i1st != "") par += "; " + i1st; if (ib != "") par += "; " + ib; if (ia != "") par += "; " + ia; if (ibetween != "") par += "; " + ibetween; return par; }
// проверка стиля private void SpireStyleCheck(List<Spire.Doc.Documents.Paragraph> prsSt, StyleDesc st, string comment) { int indexPar; DocumentFormat.OpenXml.Wordprocessing.Paragraph parXML; foreach (Spire.Doc.Documents.Paragraph p in prsSt) { if (p.Text != "") { indexPar = IndexOfPar(p); comment = CheckStyleProps(indexPar, st, p); parXML = document.MainDocumentPart.Document.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().ToList().ElementAt(indexPar); AddCommentOnParagraph(parXML, comment); } } }
public frmMain() { InitializeComponent(); info = new GeneralInfo(); style = new StyleDesc(); }
// проверка шрифта private string FontCheck(StyleDesc styleForCheck, Spire.Doc.Documents.Paragraph docXpar) { string style_com = ""; // шрифт if (styleForCheck.font_title != docXpar.BreakCharacterFormat.FontName) style_com += "; "+ "название шрифта - " + styleForCheck.font_title; if (styleForCheck.size != docXpar.BreakCharacterFormat.FontSize) style_com += "; " + "размер шрифта - " + styleForCheck.size.ToString(); if (styleForCheck.color == "черный") { if (docXpar.BreakCharacterFormat.TextColor.Name != "0") style_com += "; " + "цвет - " + styleForCheck.color; } else if (styleForCheck.color == "красный") { if (docXpar.BreakCharacterFormat.TextColor.Name != "ffff0000") style_com += "; " + "цвет - " + styleForCheck.color; } else if (styleForCheck.color == "серый") { if (docXpar.BreakCharacterFormat.TextColor.Name != "ffa5a5a5") style_com += "; " + "цвет - " + styleForCheck.color; } else if (styleForCheck.color == "синий") { if (docXpar.BreakCharacterFormat.TextColor.Name != "ff2e74b5") style_com += "; " + "цвет - " + styleForCheck.color; } if (styleForCheck.bold != docXpar.BreakCharacterFormat.Bold) style_com += "; " + "полужирный - " + styleForCheck.bold.ToString(); if (styleForCheck.italic != docXpar.BreakCharacterFormat.Italic) style_com += "; " + "курсив - " + styleForCheck.italic.ToString(); bool line; if (docXpar.BreakCharacterFormat.UnderlineStyle != Spire.Doc.Documents.UnderlineStyle.None) line = true; else line = false; if (styleForCheck.underlined != line) style_com += "; " + "подчеркнутый - " + styleForCheck.underlined; return style_com; }
// проверка свойств стиля public string CheckStyleProps(int index, StyleDesc styleForCheck, Spire.Doc.Documents.Paragraph docXpar) { string style_com = "Измените настройки стиля '" + styleForCheck.style_title + "' следующим образом: "; // выравни if (styleForCheck.align == "по левому краю") { if (docXpar.Format.HorizontalAlignment != Spire.Doc.Documents.HorizontalAlignment.Left) style_com += "Выравнивание по левому краю; "; } else if (styleForCheck.align == "по правому краю") { if (docXpar.Format.HorizontalAlignment != Spire.Doc.Documents.HorizontalAlignment.Right) style_com += "выравнивание по правому краю; "; } else if (styleForCheck.align == "по центру") { if (docXpar.Format.HorizontalAlignment != Spire.Doc.Documents.HorizontalAlignment.Center) style_com += "выравнивание по центру; "; } else if (styleForCheck.align == "по ширине") { if (docXpar.Format.HorizontalAlignment != Spire.Doc.Documents.HorizontalAlignment.Justify) style_com += "выравнивание по ширине; "; } // отступы if (styleForCheck.indent_1st_string != Math.Round((iTextSharp.text.Utilities.PointsToMillimeters(docXpar.Format.FirstLineIndent) / 10), 2, MidpointRounding.AwayFromZero)) style_com += "отступ первой строки - " + styleForCheck.indent_1st_string.ToString(); if (styleForCheck.right_indent != Math.Round((iTextSharp.text.Utilities.PointsToMillimeters(docXpar.Format.RightIndent) / 10), 2, MidpointRounding.AwayFromZero)) style_com += "; " + "отступ справа - " + styleForCheck.right_indent.ToString(); if (styleForCheck.left_indent != Math.Round((iTextSharp.text.Utilities.PointsToMillimeters(docXpar.Format.LeftIndent) / 10), 2, MidpointRounding.AwayFromZero)) style_com += "; " + "отступ слева - " + styleForCheck.left_indent.ToString(); // интервалы if (styleForCheck.interval_before != docXpar.Format.BeforeSpacing) style_com += "; " + "интервал перед абзацем - " + styleForCheck.interval_before.ToString(); if (styleForCheck.interval_after != docXpar.Format.AfterSpacing) style_com += "; " + "интервал после абзаца - " + styleForCheck.interval_after.ToString(); if (styleForCheck.interval_between != docXpar.Format.LineSpacing) style_com += "; " + "междустрочный интервал - " + styleForCheck.interval_between.ToString(); style_com += FontCheck(styleForCheck, docXpar); return style_com; }
private void lbStyles_MouseDoubleClick(object sender, MouseEventArgs e) { if (lbStyles.SelectedItem != null) { if (styles.Rows.Count > 0) if (styles.Columns["style_id"] != null) styles.PrimaryKey = new DataColumn[] { styles.Columns["style_id"] }; DataTable newSts = styles.Clone(); DataRow st = styles.Rows.Find((int)lbStyles.SelectedValue); newSts.Rows.Add(st.ItemArray); frmStyleDetails frm = new frmStyleDetails(); StyleDesc sty = new StyleDesc(); List<StyleDesc> lis = new List<StyleDesc>(); GeneralInfo ginfo = new GeneralInfo(); frm.labStyle.Text = StyleDesc.Style(sty, newSts, lis, ginfo); if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { frm.Close(); } } }
// добавление стиля private void btnAddStyle_Click(object sender, EventArgs e) { string d = lbStyles.Items.ToString(); try { frmStyle style_form = new frmStyle(); if (style_form.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _style = style_form.style; if (lbStyles.FindString(_style.style_title) != -1) { throw new Exception(); } if (_style.IsThereStyle(info_id) == false) { _style.InsertStyleInStyles(info_id); _style.LoadStyles(ref styles, info_id); // загрузка стилей Style(); } else System.Windows.Forms.MessageBox.Show("Ошибка добавления!\nПопытка добавить уже существующий стиль.", "Добавление стиля"); style_form.Close(); } } catch (Exception) { System.Windows.Forms.MessageBox.Show("Ошибка добавления!\nПопытка добавить стиль с тем же названием.", "Добавление стиля"); } }