// Generate XML for compare two views public static XmlDocument CreateViewCompareDocForAnalysis(SpreadSheetView view1, SpreadSheetView view2) { if (view1.Columns.Length != view2.Columns.Length || view1.Rows.Length != view2.Rows.Length) throw new ArgumentException("Incorect views", "view1, view2"); XmlDocument xmlDoc = new XmlDocument(); XmlNode rows_node = xmlDoc.AppendChild(xmlDoc.CreateElement("rows")); for (int index = 0; index < view1.Rows.Length; index++) { Row row = view1.Rows[index]; Row row2 = view2.Rows[index]; XmlNode row_node = rows_node.AppendChild(xmlDoc.CreateElement("row")); row_node.Attributes.Append(xmlDoc.CreateAttribute("id")).Value = row.Id; XmlNode _cellparent = xmlDoc.CreateElement("cell"); //_cellparent.Attributes.Append(xmlDoc.CreateAttribute("colspan")).Value = "2"; //XmlNode _cellParentAddImage = null; //Generate tree #region Block rows generating if (row is Block) { _cellparent.InnerText = row.Name; index++; int endIndex = index + row.ChildRows.Count; //_cellparent.AppendChild(xmlDoc.CreateCDataSection(String.Format("{0} <img border=0 onclick=\"{2}\" src='{1}'>", row.Name, GetAbsolutePath("Layouts/Images/listsnew.gif"), GenScript_NewRow(row)))); for (; index < endIndex; index++) //Row childrow in ((Block)row).ChildRows) { Row childrow = view1.Rows[index]; Row childrow2 = view2.Rows[index]; //Generate XML for child rows XmlNode rowchild_node = row_node.AppendChild(xmlDoc.CreateElement("row")); //rowchild_node.AppendChild(xmlDoc.CreateCDataSection(String.Format("<a href='alert(1)'>{0}</a>", childrow.Name))); rowchild_node.Attributes.Append(xmlDoc.CreateAttribute("id")).Value = ((Row)childrow).Id; XmlNode cellcaption_node = xmlDoc.CreateElement("cell"); //cellcaption_node.InnerText = childrow.Name; //-cellcaption_node.AppendChild(xmlDoc.CreateCDataSection(String.Format("{0} <img border=0 id='{2}_{3}' onclick=\"{2}\" src='{1}'>", childrow.Name, GetAbsolutePath("Layouts/Images/delete.gif"), GenScript_DeleteRow(childrow), childrow.Id, row.ChildRows.Count + 1 ))); //.InnerText = childrow.Name; cellcaption_node.InnerText = childrow.Name; rowchild_node.AppendChild(cellcaption_node); //XmlNode cellbtn = xmlDoc.CreateElement("cell"); //cellbtn.AppendChild(xmlDoc.CreateCDataSection(String.Format("<img border=0 id='{2}_{3}' onclick=\"{2}\" src='{1}'>", childrow.Name, GetAbsolutePath("Layouts/Images/delete.gif"), GenScript_DeleteRow(childrow), childrow.Id, row.ChildRows.Count + 1 ))); //rowchild_node.AppendChild(cellbtn); foreach (Column childcolum in view1.Columns) { #region Get cell value string val1, val2; val1 = view1.GetValue(childcolum.Id, childrow.Id); val2 = view2.GetValue(childcolum.Id, childrow2.Id); if (val1.Length > 0 && val2.Length == 0) val2 = "0"; if (val1.Length == 0 && val2.Length > 0) val1 = "0"; string Value = String.Format("{0}/{1}", val1, val2); if (val1.Length == 0 && val2.Length == 0) Value = string.Empty; #endregion XmlNode cell_node = rowchild_node.AppendChild(xmlDoc.CreateElement("cell")); Cell _cell = view1.GetCell(childcolum.Id, childrow.Id); if (_cell != null) { if (_cell.Type == CellType.AutoCalc) cell_node.Attributes.Append(xmlDoc.CreateAttribute("class")).Value = "dhtmlxGrid_bold"; else if (_cell.Type == CellType.UserValue) cell_node.Attributes.Append(xmlDoc.CreateAttribute("class")).Value = "dhtmlxGrid_italic"; if (_cell.ReadOnly) Value = "<div></div>" + Value; } cell_node.Attributes.Append(xmlDoc.CreateAttribute("id")).Value = childcolum.Id; cell_node.InnerText = Value; // TODO: } } index--; //row_node.AppendChild(_cellParentAddImage); }//if #endregion if (row.ReadOnly && row.Expression != string.Empty && !(row is Block)) { _cellparent.InnerText = "<b>" + row.Name + "</b>"; } else { _cellparent.InnerText = row.Name; } row_node.AppendChild(_cellparent); #region Bind columns values foreach (Column column in view1.Columns) { string CellUID = string.Format("{0}:{1}", column.Id, row.Id); #region Get cell value string val1, val2; val1 = view1.GetValue(column.Id, row.Id); val2 = view2.GetValue(column.Id, row2.Id); if (val1.Length > 0 && val2.Length == 0) val2 = "0"; if (val1.Length == 0 && val2.Length > 0) val1 = "0"; string Value = String.Format("{0}/{1}", val1, val2); if (val1.Length == 0 && val2.Length == 0) Value = string.Empty; #endregion Cell _cell = view1.GetCell(column.Id, row.Id); XmlNode cell_node = row_node.AppendChild(xmlDoc.CreateElement("cell")); if (_cell != null) { if (_cell.Type == CellType.AutoCalc) cell_node.Attributes.Append(xmlDoc.CreateAttribute("class")).Value = "dhtmlxGrid_bold"; else if (_cell.Type == CellType.UserValue) cell_node.Attributes.Append(xmlDoc.CreateAttribute("class")).Value = "dhtmlxGrid_italic"; if (_cell.ReadOnly) Value = "<div></div>" + Value; if (row.ReadOnly && row.Id.ToLower().Contains("Space")) Value = "<div></div>"; } cell_node.Attributes.Append(xmlDoc.CreateAttribute("id")).Value = column.Id;//CellUID;//column.Id; cell_node.InnerText = Value; } #endregion } return xmlDoc; }
private static void BindCell(SpreadSheetView view, XmlDocument doc, XmlNode parent_node, string ColumnId, string RowId) { XmlNode cell_node = parent_node.AppendChild(doc.CreateElement("cell")); Cell _cell = view.GetCell(ColumnId, RowId); string Value = view.GetValue(ColumnId, RowId); if (_cell != null) { if (_cell.Type == CellType.AutoCalc) { cell_node.Attributes.Append(doc.CreateAttribute("class")).Value = "dhtmlxGrid_bold"; //Value = "<span></span>"+Value; } else if (_cell.Type == CellType.UserValue) { cell_node.Attributes.Append(doc.CreateAttribute("class")).Value = "dhtmlxGrid_italic"; } if (_cell.ReadOnly) Value = "<div></div>" + Value; //ѕустые р¤ды. Name == string.Empty + ReadOnly if (view.Rows[view.GetRowIndex(_cell.Position.RowId)].Name == string.Empty && view.Rows[view.GetRowIndex(_cell.Position.RowId)].ReadOnly) { Value = "<div></div> "; } } cell_node.Attributes.Append(doc.CreateAttribute("id")).Value = ColumnId; cell_node.InnerText = Value; }