Skip to content

Commit 2660945

Browse files
Merge pull request #1 from SyncfusionExamples/DataForm_AI_SmartPaste
DataForm OpenAI-powered smart paste sample added.
2 parents d4351e0 + c542ac8 commit 2660945

40 files changed

+1295
-0
lines changed

MAUIDataForm/MAUIDataForm.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 25.0.1706.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MAUIDataForm", "MAUIDataForm\MAUIDataForm.csproj", "{2DA805FB-AE03-4EDA-A989-165797A3C923}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{2DA805FB-AE03-4EDA-A989-165797A3C923}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2DA805FB-AE03-4EDA-A989-165797A3C923}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{2DA805FB-AE03-4EDA-A989-165797A3C923}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{2DA805FB-AE03-4EDA-A989-165797A3C923}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {16105FEF-B69D-4365-B8B8-1388BE7B7ADA}
24+
EndGlobalSection
25+
EndGlobal

MAUIDataForm/MAUIDataForm/App.xaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version = "1.0" encoding = "UTF-8" ?>
2+
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:local="clr-namespace:MAUIDataForm"
5+
x:Class="MAUIDataForm.App">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
10+
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
11+
</ResourceDictionary.MergedDictionaries>
12+
</ResourceDictionary>
13+
</Application.Resources>
14+
</Application>

MAUIDataForm/MAUIDataForm/App.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace MAUIDataForm;
2+
3+
public partial class App : Application
4+
{
5+
public App()
6+
{
7+
InitializeComponent();
8+
9+
MainPage = new AppShell();
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<Shell
3+
x:Class="MAUIDataForm.AppShell"
4+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:local="clr-namespace:MAUIDataForm"
7+
Shell.FlyoutBehavior="Disabled"
8+
Title="MAUIDataForm">
9+
10+
<ShellContent
11+
ContentTemplate="{DataTemplate local:MainPage}"
12+
Route="MainPage" />
13+
14+
</Shell>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace MAUIDataForm;
2+
3+
public partial class AppShell : Shell
4+
{
5+
public AppShell()
6+
{
7+
InitializeComponent();
8+
}
9+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
5+
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
6+
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
7+
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
8+
9+
<!-- Note for MacCatalyst:
10+
The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.
11+
When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.
12+
The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;
13+
either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->
14+
<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->
15+
16+
<OutputType>Exe</OutputType>
17+
<RootNamespace>MAUIDataForm</RootNamespace>
18+
<UseMaui>true</UseMaui>
19+
<SingleProject>true</SingleProject>
20+
<ImplicitUsings>enable</ImplicitUsings>
21+
<Nullable>enable</Nullable>
22+
23+
<!-- Display name -->
24+
<ApplicationTitle>MAUIDataForm</ApplicationTitle>
25+
26+
<!-- App Identifier -->
27+
<ApplicationId>com.companyname.mauidataform</ApplicationId>
28+
29+
<!-- Versions -->
30+
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
31+
<ApplicationVersion>1</ApplicationVersion>
32+
33+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>
34+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
35+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
36+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
37+
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
38+
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
39+
</PropertyGroup>
40+
41+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
42+
<CreatePackage>false</CreatePackage>
43+
</PropertyGroup>
44+
<ItemGroup>
45+
<!-- App Icon -->
46+
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
47+
48+
<!-- Splash Screen -->
49+
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
50+
51+
<!-- Images -->
52+
<MauiImage Include="Resources\Images\*" />
53+
<MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
54+
55+
<!-- Custom Fonts -->
56+
<MauiFont Include="Resources\Fonts\*" />
57+
58+
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
59+
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
60+
</ItemGroup>
61+
62+
<ItemGroup>
63+
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
64+
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
65+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0-rc.2.23479.6" />
66+
<PackageReference Include="Azure.AI.OpenAI" Version="1.0.0-beta.15" />
67+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
68+
<PackageReference Include="Syncfusion.Maui.DataForm" Version="*" />
69+
</ItemGroup>
70+
71+
<ItemGroup>
72+
<None Remove="feedbackform.png" />
73+
<None Remove="Model\" />
74+
<None Remove="ViewModel\" />
75+
<None Remove="Service\" />
76+
</ItemGroup>
77+
<ItemGroup>
78+
<BundleResource Include="feedbackform.png" />
79+
</ItemGroup>
80+
<ItemGroup>
81+
<Folder Include="Model\" />
82+
<Folder Include="ViewModel\" />
83+
<Folder Include="Service\" />
84+
</ItemGroup>
85+
</Project>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:dataForm="clr-namespace:Syncfusion.Maui.DataForm;assembly=Syncfusion.Maui.DataForm"
5+
xmlns:local="clr-namespace:MAUIDataForm"
6+
x:Class="MAUIDataForm.MainPage">
7+
8+
<Grid>
9+
<Image Source="feedbackform.png" Aspect="Fill" />
10+
<Grid HorizontalOptions="Center"
11+
VerticalOptions="Center"
12+
ColumnSpacing="20">
13+
14+
<Frame HasShadow="False"
15+
BackgroundColor="{DynamicResource SfDataFormNormalBackground}"
16+
CornerRadius="10"
17+
MaximumHeightRequest="550"
18+
VerticalOptions="Start"
19+
HorizontalOptions="Center"
20+
WidthRequest="550"
21+
Padding="10">
22+
23+
<Grid BackgroundColor="{DynamicResource SfDataFormNormalBackground}">
24+
<Grid.RowDefinitions>
25+
<RowDefinition Height="40"/>
26+
<RowDefinition Height="0.8*"/>
27+
<RowDefinition Height="1"/>
28+
<RowDefinition Height="75"/>
29+
</Grid.RowDefinitions>
30+
31+
<Grid.BindingContext>
32+
<local:FeedbackViewModel/>
33+
</Grid.BindingContext>
34+
35+
<Label Text="Product Feedback"
36+
TextColor="Black"
37+
FontSize="Subtitle"
38+
FontAttributes="Bold"
39+
VerticalTextAlignment="Center"
40+
HorizontalTextAlignment="Center"/>
41+
42+
<dataForm:SfDataForm x:Name="feedbackForm"
43+
Grid.RowSpan="1"
44+
Grid.Row="1"
45+
DataObject="{Binding ViewModel}"
46+
ValidationMode="PropertyChanged"
47+
LayoutType="TextInputLayout"
48+
HorizontalOptions="Center">
49+
<dataForm:SfDataForm.TextInputLayoutSettings>
50+
<dataForm:TextInputLayoutSettings ShowHelperText="True"
51+
FocusedStroke="{DynamicResource SfDataFormFocusedEditorStroke}"/>
52+
</dataForm:SfDataForm.TextInputLayoutSettings>
53+
</dataForm:SfDataForm>
54+
55+
<Line Grid.Row="2" Background="#F5F5F5" />
56+
57+
<HorizontalStackLayout Grid.Row="3"
58+
HorizontalOptions="End">
59+
<Button x:Name="onlineSmartPaste"
60+
Text="Smart Paste"
61+
CornerRadius="20"
62+
FontSize="16"
63+
Margin="20,0,20,0"
64+
Clicked="OnSmartPasteButtonClicked"
65+
HeightRequest="40"/>
66+
67+
<Button x:Name="submitButton"
68+
Text="Submit"
69+
CornerRadius="20"
70+
FontSize="16"
71+
Margin="20,0,20,0"
72+
Clicked="OnSubmitButtonClicked"
73+
HeightRequest="40"/>
74+
</HorizontalStackLayout>
75+
</Grid>
76+
</Frame>
77+
</Grid>
78+
</Grid>
79+
80+
81+
</ContentPage>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
namespace MAUIDataForm
2+
{
3+
using Newtonsoft.Json;
4+
5+
public partial class MainPage : ContentPage
6+
{
7+
public MainPage()
8+
{
9+
InitializeComponent();
10+
}
11+
12+
string clipboardText;
13+
private AzureOpenAIService azureAIService = new AzureOpenAIService();
14+
15+
private async void OnSmartPasteButtonClicked(object sender, EventArgs e)
16+
{
17+
if (Clipboard.Default.HasText)
18+
{
19+
this.clipboardText = await Clipboard.Default.GetTextAsync();
20+
}
21+
22+
if (string.IsNullOrEmpty(this.clipboardText))
23+
{
24+
await App.Current.MainPage.DisplayAlert("", "No text copied to clipboard. Please copy the text and try again", "OK");
25+
26+
return;
27+
}
28+
29+
string dataFormJsonData = JsonConvert.SerializeObject(this.feedbackForm!.DataObject);
30+
string prompt = $"Merge the copied data into the DataForm field content, ensuring that the copied text matches suitable field names. Here are the details:" +
31+
$"\n\nCopied data: {this.clipboardText}," +
32+
$"\nDataForm Field Name: {dataFormJsonData}," +
33+
$"\nProvide the resultant DataForm directly." +
34+
$"\n\nConditions to follow:" +
35+
$"\n1. Do not use the copied text directly as the field name; merge appropriately." +
36+
$"\n2. Ignore case sensitivity when comparing copied text and field names." +
37+
$"\n3. Final output must be Json format" +
38+
$"\n4. No need any explanation or comments in the output" +
39+
$"\n Please provide the valid JSON object without any additional formatting characters like backticks or newlines";
40+
string finalResponse = await this.azureAIService.GetResponseFromGPT(prompt);
41+
this.ProcessSmartPasteData(finalResponse);
42+
}
43+
44+
private async void OnSubmitButtonClicked(object sender, EventArgs e)
45+
{
46+
if (this.feedbackForm != null && App.Current?.MainPage != null)
47+
{
48+
if (this.feedbackForm.Validate())
49+
{
50+
await App.Current.MainPage.DisplayAlert("", "Feedback form submitted successfully", "OK");
51+
}
52+
else
53+
{
54+
await App.Current.MainPage.DisplayAlert("", "Please enter the required details", "OK");
55+
}
56+
}
57+
}
58+
59+
private void ProcessSmartPasteData(string response)
60+
{
61+
//// Deserialize the JSON string to a Dictionary
62+
var openAIJsonData = JsonConvert.DeserializeObject<Dictionary<string, object>>(response);
63+
64+
//// Create lists to hold field names and values
65+
var filedNames = new List<string>();
66+
var fieldValues = new List<string>();
67+
68+
foreach (var data in openAIJsonData!)
69+
{
70+
filedNames.Add(data.Key);
71+
fieldValues.Add(data.Value?.ToString() ?? string.Empty);
72+
}
73+
74+
if (this.feedbackForm.DataObject is FeedBackForm feedbackForm)
75+
{
76+
feedbackForm.Name = fieldValues[0];
77+
feedbackForm.Email = fieldValues[1];
78+
feedbackForm.ProductName = fieldValues[2];
79+
feedbackForm.ProductVersion = fieldValues[3];
80+
feedbackForm.Rating = (int)Math.Round(double.Parse(fieldValues[4]));
81+
feedbackForm.Comments = fieldValues[5];
82+
};
83+
84+
for (int i = 0; i < filedNames.Count; i++)
85+
{
86+
this.feedbackForm!.UpdateEditor(filedNames[i]);
87+
}
88+
}
89+
}
90+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Microsoft.Extensions.Logging;
2+
using Syncfusion.Maui.Core.Hosting;
3+
4+
namespace MAUIDataForm;
5+
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var builder = MauiApp.CreateBuilder();
11+
builder
12+
.UseMauiApp<App>()
13+
.ConfigureSyncfusionCore()
14+
.ConfigureFonts(fonts =>
15+
{
16+
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
17+
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
18+
});
19+
20+
#if DEBUG
21+
builder.Logging.AddDebug();
22+
#endif
23+
24+
return builder.Build();
25+
}
26+
}
27+

0 commit comments

Comments
 (0)