Skip to content

Commit

Permalink
Preparing/trying to save/open file with a view #1011
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Sep 2, 2024
1 parent e6f9814 commit 0a17573
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion FetchXmlBuilder/Controls/attributeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private void UpdateCellFromUI()
cell.Name = Node.GetAttributeLayoutName();
cell.Width = chkLayoutVisible.Checked ? trkLayoutWidth.Value : 0;
cell.IsHidden = !chkLayoutVisible.Checked;
fxb.dockControlLayoutXml?.UpdateXML(cell.Parent?.ToXML());
fxb.dockControlLayoutXml?.UpdateXML(cell.Parent?.ToXMLString());
}
grpLayout.Visible = cell != null;
trkLayoutWidth.Enabled = chkLayoutVisible.Checked;
Expand Down
4 changes: 2 additions & 2 deletions FetchXmlBuilder/DockControls/ResultGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ internal void SetLayoutToGrid()
}
var tmpreloaded = reloaded;
reloaded = true;
crmGridView1.LayoutXML = form.dockControlBuilder?.LayoutXML?.ToXML();
crmGridView1.LayoutXML = form.dockControlBuilder?.LayoutXML?.ToXMLString();
crmGridView1.Refresh();
reloaded = tmpreloaded;
}
Expand Down Expand Up @@ -455,7 +455,7 @@ private void crmGridView1_LayoutChanged(object sender, DataGridViewColumnEventAr
private void mnuResetLayout_Click(object sender, EventArgs e)
{
form.dockControlBuilder.ResetLayout();
crmGridView1.LayoutXML = form.dockControlBuilder.LayoutXML?.ToXML();
crmGridView1.LayoutXML = form.dockControlBuilder.LayoutXML?.ToXMLString();
RefreshData();
}

Expand Down
23 changes: 18 additions & 5 deletions FetchXmlBuilder/DockControls/TreeBuilderControl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Sdk.Query;
using Rappen.XRM.Helpers.Extensions;
using Rappen.XRM.Helpers.FetchXML;
using Rappen.XRM.Helpers.Interfaces;
using Rappen.XTB.FetchXmlBuilder.Builder;
Expand Down Expand Up @@ -417,7 +418,7 @@ internal void UpdateLayoutXML()
{
return;
}
fxb.dockControlLayoutXml?.UpdateXML(LayoutXML?.ToXML());
fxb.dockControlLayoutXml?.UpdateXML(LayoutXML?.ToXMLString());
if (GetCurrentControl() is attributeControl attrcontrol)
{
attrcontrol.UpdateUIFromCell();
Expand Down Expand Up @@ -516,16 +517,28 @@ private void DisplayDefinition(XmlDocument fetchDoc)
ManageMenuDisplay();
}

private XmlDocument GetFetchDocument()
private XmlDocument GetFetchDocument(bool includelayout = false)
{
var doc = new XmlDocument();
if (tvFetch.Nodes.Count > 0)
{
XmlNode rootNode = doc.CreateElement("root");
doc.AppendChild(rootNode);
TreeNodeHelper.AddXmlNode(tvFetch.Nodes[0], rootNode);
var xmlbody = doc.SelectSingleNode("root/fetch").OuterXml;
doc.LoadXml(xmlbody);
if (includelayout && LayoutXML != null)
{
//rootNode.AppendChild(new XmlNode("view"));
//view.AppendChild(LayoutXML.ToXMLString().ToXmlNode());
//view.AppendChild(GetFetchDocument(false));
TreeNodeHelper.AddXmlNode(tvFetch.Nodes[0], rootNode);
var xmlbody = doc.SelectSingleNode("root/view").OuterXml;
doc.LoadXml(xmlbody);
}
else
{
TreeNodeHelper.AddXmlNode(tvFetch.Nodes[0], rootNode);
var xmlbody = doc.SelectSingleNode("root/fetch").OuterXml;
doc.LoadXml(xmlbody);
}
}
return doc;
}
Expand Down
22 changes: 19 additions & 3 deletions FetchXmlBuilder/FXBGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ internal void UpdateLiveXML(bool preventxmlupdate = false)
{
if (settings.Results.WorkWithLayout)
{
dockControlLayoutXml.UpdateXML(dockControlBuilder.LayoutXML?.ToXML());
dockControlLayoutXml.UpdateXML(dockControlBuilder.LayoutXML?.ToXMLString());
}
else
{
Expand Down Expand Up @@ -340,7 +340,23 @@ private void OpenFile()
FileName = ofd.FileName;
var fetchDoc = new XmlDocument();
fetchDoc.Load(ofd.FileName);
dockControlBuilder.Init(fetchDoc.OuterXml, null, false, "open file", true);
switch (fetchDoc.FirstChild?.Name)
{
case "fetch":
dockControlBuilder.Init(fetchDoc.OuterXml, null, false, "open file", true);
break;

case "view":
var fetch = fetchDoc.SelectSingleNode("//fetch")?.InnerText;
var layout = fetchDoc.SelectSingleNode("//grid")?.InnerText;
dockControlBuilder.Init(fetch, layout, true, "open file", true);
break;

default:
MessageBox.Show("The selected file does not contain FetchXML.\nPlease select another one.", "Open File",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
}
LogUse("OpenFile");
}
EnableControls(true);
Expand Down Expand Up @@ -682,7 +698,7 @@ private void SaveView(bool saveas)
}
}
var fetch = dockControlBuilder.GetFetchString(false, false);
var layout = includelayout ? dockControlBuilder.LayoutXML.ToXML() : View?["layoutxml"].ToString();
var layout = includelayout ? dockControlBuilder.LayoutXML.ToXMLString() : View?["layoutxml"].ToString();
var newView = new Entity(viewtype);
newView["fetchxml"] = fetch;
newView["returnedtypecode"] = entityname;
Expand Down
6 changes: 3 additions & 3 deletions FetchXmlBuilder/FetchXmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private void SaveSetting()
connectionsettings = new FXBConnectionSettings();
}
connectionsettings.FetchXML = dockControlBuilder.GetFetchString(false, false);
connectionsettings.LayoutXML = dockControlBuilder.LayoutXML?.ToXML();
connectionsettings.LayoutXML = dockControlBuilder.LayoutXML?.ToXMLString();
SettingsManager.Instance.Save(typeof(FetchXmlBuilder), connectionsettings, ConnectionDetail?.ConnectionName);
}

Expand Down Expand Up @@ -789,7 +789,7 @@ private void tsmiRepoSave_Click(object sender, EventArgs e)
return;
}
query.Fetch = dockControlBuilder.GetFetchString(true, false);
query.Layout = dockControlBuilder.LayoutXML?.ToXML();
query.Layout = dockControlBuilder.LayoutXML?.ToXMLString();
SaveRepository();
MessageBox.Show($"Query {query.Name} updated in repository", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Expand All @@ -814,7 +814,7 @@ private void tsmiRepoSaveAs_Click(object sender, EventArgs e)
repository.Queries.Remove(repository.Queries.FirstOrDefault(q => q.Name == queryname));
}
var fetch = dockControlBuilder.GetFetchString(true, false);
var layout = dockControlBuilder.LayoutXML?.ToXML();
var layout = dockControlBuilder.LayoutXML?.ToXMLString();
var query = new QueryDefinition { Name = queryname, Fetch = fetch, Layout = layout };
repository.Queries.Add(query);
repository.SortQueries();
Expand Down
2 changes: 1 addition & 1 deletion FetchXmlBuilder/Views/LayoutXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ internal void MakeSureAllCellsExistForColumns(Dictionary<string, int> namewidths
}
}

public string ToXML()
public string ToXMLString()
{
var result = $@"<grid name='resultset' object='{EntityMeta?.ObjectTypeCode}' jump='{EntityMeta?.PrimaryNameAttribute}' select='1' icon='1' preview='1'>
<row name='result' id='{EntityMeta?.PrimaryIdAttribute}'>
Expand Down

0 comments on commit 0a17573

Please sign in to comment.