Skip to content

Commit

Permalink
876065: sample added
Browse files Browse the repository at this point in the history
  • Loading branch information
SumathiSumi committed Jun 19, 2024
1 parent 600f0c0 commit 923b36a
Show file tree
Hide file tree
Showing 29 changed files with 1,257 additions and 0 deletions.
13 changes: 13 additions & 0 deletions KB-Samples/DiagramToExcel/DiagramToExcel/DiagramToExcel/App.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<p role="alert">Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Blazor.Diagram" Version="*" />
<PackageReference Include="Syncfusion.XlsIO.NET" Version="*" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33122.133
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiagramToExcel", "DiagramToExcel.csproj", "{BD607AD5-F5CD-4426-B6CF-BCF6EE5E38A5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BD607AD5-F5CD-4426-B6CF-BCF6EE5E38A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD607AD5-F5CD-4426-B6CF-BCF6EE5E38A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD607AD5-F5CD-4426-B6CF-BCF6EE5E38A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD607AD5-F5CD-4426-B6CF-BCF6EE5E38A5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E54284AF-9797-4860-9EED-6ECF085DCDBF}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.JSInterop;
using System;
using System.Threading.Tasks;

namespace DiagramToExcel
{
public static class FileUtils
{
public static ValueTask<object> SaveAs(this IJSRuntime js, string filename, byte[] data)
=> js.InvokeAsync<object>(
"saveAsFile",
filename,
Convert.ToBase64String(data));
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
@page "/"
@using System.IO;
@using DiagramToExcel;
@inject DiagramToExcel.Data.CreateExcel service
@inject Microsoft.JSInterop.IJSRuntime JS
@using Syncfusion.Blazor.Diagram


<button class="btn btn-primary" @onclick="@ExportExcel">ExportExcel</button>

<SfDiagramComponent Height="900px" @ref="diagram" NodeCreating="@OnNodeCreating" ConnectorCreating="@OnConnectorCreating">
<Syncfusion.Blazor.Diagram.DiagramTemplates>
<NodeTemplate>
@{
Node node1 = (context as Node);
string NameId = (node1.Data as HierarchicalDetails).Id;
string TeamName = (node1.Data as HierarchicalDetails).Role;
string EmpId = (node1.Data as HierarchicalDetails).Manager;
string color = (node1.Data as HierarchicalDetails).Color;
<div style="position: absolute;
width: 100%;
height: 100%;
border: 1px solid #E0E0E0;
background-color:@color;
box-sizing: border-box;
border-radius: 8px;
padding-top: 5px;">
<p>@NameId</p>
<p>@TeamName</p>
<p>@EmpId</p>
</div>
Syncfusion.Blazor.Diagram.NodeShapes type = (context as Node).Shape.Type;
}
</NodeTemplate>
</Syncfusion.Blazor.Diagram.DiagramTemplates>
<DataSourceSettings ID="Id" ParentID="Manager" DataSource="@DataSource"> </DataSourceSettings>
<Layout Type="LayoutType.HierarchicalTree" HorizontalSpacing="@HorizontalSpacing" VerticalSpacing="@VerticalSpacing">
</Layout>
</SfDiagramComponent>

@code {
int connectorCount = 0;
SfDiagramComponent diagram;
DiagramObjectCollection<Node> nodes = new DiagramObjectCollection<Node>();
DiagramObjectCollection<Connector> connectors = new DiagramObjectCollection<Connector>();
int left = 40;
int top = 50;
int HorizontalSpacing = 40;
int VerticalSpacing = 40;

private void OnNodeCreating(IDiagramObject obj)
{
Node node = obj as Node;
node.Height = 120;
node.Width = 250;
node.ID = (node.Data as HierarchicalDetails).Id;
node.Shape = new Shape()
{ Type = Syncfusion.Blazor.Diagram.NodeShapes.HTML };
if (node.Data != null)
{
node.Style = new ShapeStyle() { Fill = (node.Data as HierarchicalDetails).Color, StrokeWidth = 3, StrokeColor = "Black" };
}
//Initializing the default node's shape style.
}

private void OnConnectorCreating(IDiagramObject connector)
{
(connector as Connector).Type = ConnectorSegmentType.Orthogonal;
}

public class HierarchicalDetails
{
public string Id { get; set; }
public string Role { get; set; }
public string Manager { get; set; }
public string ChartType { get; set; }
public string Color { get; set; }
}
public List<HierarchicalDetails> DataSource = new List<HierarchicalDetails>()
{
new HierarchicalDetails() { Id= "FirstNode", Role= "Board ", Color= "Red" },
new HierarchicalDetails() { Id= "SecondNode", Role= "General Manager", Manager= "FirstNode", ChartType= "right", Color= "Blue" },
new HierarchicalDetails() { Id= "ThirdNode", Role= "Assistant Manager", Manager= "SecondNode", Color= "Yellow" },
new HierarchicalDetails() { Id= "FourthNode", Role= "Human Resource Manager", Manager= "SecondNode", ChartType= "right", Color= "Orange" },
new HierarchicalDetails() { Id= "FifthNode", Role= "Trainers", Manager= "SecondNode", Color= "Pink" },
new HierarchicalDetails() { Id= "SixthNode", Role= "Recruiting Team", Manager= "FourthNode", Color= "Green" },

};
MemoryStream excelStream;

/// <summary>
/// Create and download the Excel document
/// </summary>
protected async void ExportExcel()
{
excelStream = service.CreateDocument(diagram.Nodes);
await JS.SaveAs("ExportDiagramDetails.xlsx", excelStream.ToArray());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page "/"
@namespace DiagramToExcel.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "_Layout";
}

<component type="typeof(App)" render-mode="ServerPrerendered" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@using Microsoft.AspNetCore.Components.Web
@namespace BackgroundColor.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
<link href="BackgroundColor.styles.css" rel="stylesheet" />
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body>
@RenderBody()



<script src="_framework/blazor.server.js"></script>
<script type="text/javascript">
function saveAsFile(filename, bytesBase64) {
if (navigator.msSaveBlob) {
//Download document in Edge browser
var data = window.atob(bytesBase64);
var bytes = new Uint8Array(data.length);
for (var i = 0; i < data.length; i++) {
bytes[i] = data.charCodeAt(i);
}
var blob = new Blob([bytes.buffer], { type: "application/octet-stream" });
navigator.msSaveBlob(blob, filename);
}
else {
var link = document.createElement('a');
link.download = filename;
link.href = "data:application/octet-stream;base64," + bytesBase64;
document.body.appendChild(link); // Needed for Firefox
link.click();
document.body.removeChild(link);
}
}
</script>
</body>
</html>
33 changes: 33 additions & 0 deletions KB-Samples/DiagramToExcel/DiagramToExcel/DiagramToExcel/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

using DiagramToExcel.Data;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Syncfusion.Blazor;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<CreateExcel>();
builder.Services.AddSyncfusionBlazor();
var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseRouting();

app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:11920",
"sslPort": 44341
}
},
"profiles": {
"DiagramToExcel": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7204;http://localhost:5236",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@inherits LayoutComponentBase

<PageTitle>DiagramToExcel</PageTitle>

<div class="page">
<div class="sidebar">
<NavMenu />
</div>


<main>

<article class="content px-4">
@Body
</article>
</main>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}

main {
flex: 1;
}

.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}

.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}

.top-row ::deep a, .top-row .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
}

.top-row a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}

@media (max-width: 640.98px) {
.top-row:not(.auth) {
display: none;
}

.top-row.auth {
justify-content: space-between;
}

.top-row a, .top-row .btn-link {
margin-left: 0;
}
}

@media (min-width: 641px) {
.page {
flex-direction: row;
}

.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}

.top-row {
position: sticky;
top: 0;
z-index: 1;
}

.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using DiagramToExcel
@using DiagramToExcel.Shared
Loading

0 comments on commit 923b36a

Please sign in to comment.