|
Have you tried Uri.TryCreate Method (System) | Microsoft Docs[^] - I haven't either, but ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
No it doesn't. The docs for Uri.TryCreate go all the way back to .NET Framework 1.1.
|
|
|
|
|
If it's actually crashing on the new ToastCollection line, then the URI is valid - otherwise, the new Uri line would crash.
The ToastCollection probably doesn't support pack: URIs. But that's just a guess, since you haven't provided any details of the error.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I think the error was at the URI statement, I checked the documentation (well, duh) and they use "ms-appx:" instead.
Still having errors on related code.
Will ask another question.
Thanks
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
According to the documentation[^], Toast images only support the following URI schemas:
http:// or https:// file:/// ms-appx:/// ms-appdata:///local/
WPF-style pack: URIs are not supported.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks, I missed that one.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
Hi at all
Im new in C# WPF and SQL
since days im sitting on a problem I could not solve, and hope of help but fdid not find the Problem, because I'm not so good in sql:
I try to delete(Löschen) a Dataset from Listbox and the Database behind(MySQL), and i do not find my failure.
Please can you help me?
I tried to send a Screenshot, but dont find a way.... Thanks for your help
XAML-Code
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="Artikel" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="60" />
</Grid.RowDefinitions>
<StackPanel Grid.Column="0" Grid.Row="0" Margin="10,50,0,0">
<StackPanel Orientation="Vertical" DataContext="{Binding SelectedItem, ElementName=cbArtikel}">
<Label x:Name="lblArtikel" FontWeight="Bold" Content="Artikel" Margin="45,5" />
<DockPanel Width="300" Margin="0,5,0,5">
<Label x:Name="lblName" DockPanel.Dock="Left" Width="100" Height="30" Content="Name:" />
<TextBox x:Name="tbName" DockPanel.Dock="Right" Width="200" Height="30" Text="{Binding name}"/>
</DockPanel>
<DockPanel Width="300" Margin="0,5,0,5">
<Label x:Name="lblBeschreibung" DockPanel.Dock="Left" Width="100" Height="30" Content="Beschreibung:" />
<TextBox x:Name="tbBeschreibung" DockPanel.Dock="Right" Width="200" Height="30" Text="{Binding beschreibung}" />
</DockPanel>
<DockPanel Width="300" Margin="0,5,0,5">
<Label x:Name="lblGroesse" DockPanel.Dock="Left" Width="100" Height="30" Content="Größe:" />
<TextBox x:Name="tbGroesse" DockPanel.Dock="Right" Width="200" Height="30" Text="{Binding groesse}" />
</DockPanel>
<DockPanel Width="300" Margin="0,5,0,5">
<Label x:Name="lblFarbe" DockPanel.Dock="Left" Width="100" Height="30" Content="Farbe:" />
<TextBox x:Name="tbFarbe" DockPanel.Dock="Right" Width="200" Height="30" Text="{Binding farbe}" />
</DockPanel>
<DockPanel Width="300" Margin="0,5,0,5">
<Label x:Name="lblMenge" DockPanel.Dock="Left" Width="100" Height="30" Content="Menge:" />
<TextBox x:Name="tbMenge" DockPanel.Dock="Right" Width="200" Height="30" Text="{Binding menge}" />
</DockPanel>
<DockPanel Width="300" Margin="0,5,0,5">
<Label x:Name="lblPreis" DockPanel.Dock="Left" Width="100" Height="30" Content="Preis:" />
<TextBox x:Name="tbPreis" DockPanel.Dock="Right" Width="200" Height="30" Text="{Binding preis}" />
</DockPanel>
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0">
<Label Name="lblListArtikel" FontWeight="Bold" FontSize="16" Margin="50,50,0,5">Liste der Artikel</Label>
<ListBox x:Name="lbArtikel" Width="300" Height="220">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock Text="{Binding name}" FontWeight="Bold" DockPanel.Dock="Left" Width="85" />
<TextBlock Text="{Binding beschreibung}" FontWeight="Thin" Width="90" />
<TextBlock Text="{Binding groesse}" FontWeight="Thin" Width="30" />
<TextBlock Text="{Binding farbe}" FontWeight="Thin" Width="30" />
<TextBlock Text="{Binding menge}" FontWeight="Thin" Width="30" />
<TextBlock Text="{Binding preis}" FontWeight="Thin" Width="30" />
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button x:Name="btnDelete" Content="Löschen" Width="100" Height="30" Background="Salmon" HorizontalAlignment="Center" Margin="0,15" Click="btnDelete_Click" />
</StackPanel>
<DockPanel Grid.Column="0" Grid.Row="1" LastChildFill="False" HorizontalAlignment="Left" Margin="50,0,0,0">
<Button x:Name="btnAdd" Width="100" Height="30" Click="btnAdd_Click" Content="Hinzufügen" />
</DockPanel>
<DockPanel Grid.Column="1" Grid.Row="1" LastChildFill="False" HorizontalAlignment="Right" Margin="0,0,50,0">
<Button x:Name="btnZurueck" Width="100" Height="30" Content="Zurück" Click="btnZurueck_Click" />
</DockPanel>
</Grid>
</Window>
Code-Behind for that WPF:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.Odbc;
using System.Data;
namespace WpfApp1
{
public partial class MainWindow : Window
{
private OdbcConnection odbcConnection;
public MainWindow()
{
InitializeComponent();
odbcConnection = new OdbcConnection("DSN=dbdemo2;");
ArtikelShow();
}
private void ArtikelShow()
{
try
{
string sqlArtikel = "SELECT * FROM artikel";
OdbcCommand odbcCommand = new OdbcCommand(sqlArtikel, odbcConnection);
OdbcDataAdapter odbcDataAdapter = new OdbcDataAdapter(odbcCommand);
DataSet dataSet = new DataSet();
odbcDataAdapter.Fill(dataSet, "tableArtikel");
lbArtikel.ItemsSource = dataSet.Tables["tableArtikel"].DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.GetType() + Environment.NewLine + ex.Message, "Datenbankfehler");
}
}
private void btnDelete_Click(object sender, RoutedEventArgs e)
{
if (lbArtikel.SelectedValue == null)
{
MessageBox.Show("Keinen Eintrag zum Löschen ausgewählt");
}
else
{
try
{
MessageBoxResult messageBoxResult = MessageBox.Show("Wollen Sie wirklich den Artikel aus der Datenbank löschen?", "Bitte bestätigen Sie den Löschvorgang", MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.Yes)
{
string sqlDelete = "DELETE FROM artikel WHERE id=?";
OdbcCommand odbcCommand = new OdbcCommand(sqlDelete, odbcConnection);
odbcConnection.Open();
odbcCommand.Parameters.AddWithValue("@id", Int32.Parse(lbArtikel.SelectedValue.ToString()));
odbcCommand.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.GetType() + Environment.NewLine + ex.Message, "Datenbankfehler");
}
finally
{
odbcConnection.Close();
ArtikelShow();
}
}
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
if (tbName.Text.Equals(""))
{
MessageBox.Show("Bitte einen Artikelnamen eingeben");
}
else
{
try
{
string sqlInsert = "INSERT INTO artikel VALUES(NULL, ?, ?, ?, ?, ?, ?)";
OdbcCommand odbcCommand = new OdbcCommand(sqlInsert, odbcConnection);
odbcConnection.Open();
odbcCommand.Parameters.AddWithValue("@name", tbName.Text);
odbcCommand.Parameters.AddWithValue("@beschreibung", tbBeschreibung.Text);
odbcCommand.Parameters.AddWithValue("@groesse", tbGroesse.Text);
odbcCommand.Parameters.AddWithValue("@farbe", tbFarbe.Text);
odbcCommand.Parameters.AddWithValue("@menge", Convert.ToInt32(tbMenge.Text));
odbcCommand.Parameters.AddWithValue("@preis", Convert.ToDouble(tbPreis.Text));
odbcCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.GetType() + Environment.NewLine + ex.Message, "Datenbankfehler");
}
finally
{
odbcConnection.Close();
ArtikelShow();
}
}
}
private void btnZurueck_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
|
|
|
|
|
You should put your "start up code" in the MainWindow Loaded event; there are too many side effects when you do too much in the "constructor" of the main window (or any window for that matter).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
That's a good tip, thanks...
As for my background, I'm 56 and what other crosswords are, C# is to me.
I'm currently learning C# with books, but unfortunately they are very buggy and I just can't find the bug:
Database error!
System.FormatException
The input string is in the wrong format
|
|
|
|
|
Test the value of:
Int32.Parse(lbArtikel.SelectedValue.ToString())); I would guess it is probably null.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Hello thanks, im looking around to learn anything about the parsing?, an howto with examples, better than the microsoft site?
|
|
|
|
|
Yes, that's it, but now I must find a way to solve my problem
thank you for the tip
oh, thats a very good side to learn for all beginners like me
https://www.dotnetperls.com/parse
|
|
|
|
|
I have been looking at various ORM libraries. Many of these seem to rely on attributes placed on classes and fields in the model. I understand that attributes can be completely ignored by the build process but I'm not sure how such library-specific attributes fit with the whole idea of dependency injection and being able to swap in/out different data providers without requiring any other changes - and certainly not as 'deep down' as the model layer.
I am also puzzled by the workflow using ORM tools. Some require the POCO class to be defined and some ask the data tables to be designed first, but once the first iteration of all this is in a production environment, how on earth do you then instigate any changes without obliterating the live database?
I'd be extremely grateful if anyone could point me at some good reading around this whole subject.
Kind wishes - Patrick
Thank you to anyone taking the time to read my posts.
|
|
|
|
|
In Entity Framework, you can use "fluent configuration" to configure the store, so that you don't need to add library-specific attributes to the classes.
Creating and configuring a model - EF Core | Microsoft Docs[^]
You can even mix-and-match; I tend to add the non-library-specific attributes like StringLength to the classes, and put the EF-specific stuff in an IEntityTypeConfiguration<T> class.
Patrick Skelton wrote: once the first iteration of all this is in a production environment, how on earth do you then instigate any changes without obliterating the live database?
For Entity Framework, you can use migrations to update the database schema to match the model:
Migrations Overview - EF Core | Microsoft Docs[^]
Other ORMs will probably have something similar.
There are also third-party tools to manage your schema migrations (eg: Flyway) but they tend to cost money.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Interesting stuff, Richard. Thank you. Looks like I have some reading and experimenting to do.
Thank you to anyone taking the time to read my posts.
|
|
|
|
|
I use Entity Framework; I like to keep it simple; and have never gone much beyond [KEY]. I maintain my data relationships in code; I use primarily "code-first" versus "data-base" first since I'm primarily developing / prototyping. I think you should examine your own style before subscribing to a particular approach.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Thanks, Gerry. Code-first does sound best for me, for the same reasons as you.
Thank you to anyone taking the time to read my posts.
|
|
|
|
|
Patrick Skelton wrote: and being able to swap in/out different data providers without requiring any other changes
Having spent decades working with data providers that is pipe dream.
If the system evolves into any complexity then differences between systems will crop up that at best will exhibit problems that make at least one service provide behave in a less than optimal way compared to others.
This can be minimized, but not eliminated, by the following
1. Very carefully review all requirements BEFORE committing to evaluate impact on data flows especially those that have any chance of involving performance (volume and size.) The impact must always be rigorously sized.
2. Have a custom data layer that STRICTLY enforces the data rules.
3. Do not allow any exceptions. If you allow even one exception then over time there will be more exceptions.
|
|
|
|
|
I have a C# app in .NET framework 4.6.1 where it uses WebClient.DownloadString(url) to download content from a url that uses TLS 1.3 and it throws exception because app is intended for a use on Windows Vista that doesn't have TLS 1.3
.NET framework 4.8 can't be installed on Vista.
How can I solve this problem so that app can work on Vista?
|
|
|
|
|
I just browsed to namespace System.Net, using VS2010, and can see that WebClient.DownloadString(ur(i)) is a member of System [4.0.0.0] so I'd suggest going into the Project Properties and see if you can't switch the Target framework from the green one, 4.6.1, to ... say 2.0 or a little higher. Maybe 4.0.
Nothing I've ever compiled with VS2010 gave me troubles on Vista but TLS did superceed SSL as I recall back around Windows 2000. Then again, I've actually has RDP running on Vista (though not attaching to Windows 2000) ... so I don't know what gives with RDP.
Perhaps I'm confusing help here with some other help somewhere else
|
|
|
|
|
Hi,
It's not possible. The .NET framework utilizes Schannel for TLS 1.3[^] and Vista uses outdated libraries.
moxol wrote: How can I solve this problem so that app can work on Vista? The only thing that comes to mind is maybe using a C# wrapper around libcurl[^].
Best Wishes,
-David Delaune
|
|
|
|
|
You can get your app to use the OS-default protocols by setting a registry key:
Transport Layer Security (TLS) best practices with the .NET Framework - .NET Framework | Microsoft Docs[^]
Of course, that won't help if the OS doesn't support TLS 1.3 in the first place. As far as I can see, it's only supported in Windows 10 (build 1903 or later) and Windows 11, and in Windows Server 2019 and 2022. Vista doesn't even support TLS 1.1 without a patch!
I guess the real question is, why are you still using an OS which has been out of mainstream support for over a decade, and out of extended support for over five years?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yep,
There are a few third-party options. I'm not a C# dev, but I heard that Bouncy Castle[^] does TLS 1.3 or maybe a libcurl wrapper would be an option.
|
|
|
|
|
|