Click here to Skip to main content
16,017,907 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
XML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="RadniNalozi.AddEmployeePage" 
             Title="Dodaj radni nalog">
    <ContentPage.Content>
        <StackLayout Padding="5">
            <Label Text="Broj radnog naloga" 
            FontAttributes="Bold" TextColor="Black"/>
            <Entry Placeholder="Ordine di lavoro" FontSize="Small" 
            HorizontalOptions="FillAndExpand" x:Name="name"/>
            <Label Text="Narudžbenica" FontAttributes="Bold" 
            TextColor="Black"/>
            <Entry Placeholder="Ordine" FontSize="Small" 
            HorizontalOptions="FillAndExpand" x:Name="address"/>
            <Label Text="Commessa" FontAttributes="Bold" 
            TextColor="Black"/>
            <Entry Placeholder="Commessa" FontSize="Small" 
            HorizontalOptions="FillAndExpand" x:Name="phoneNumber" 
                   Keyboard="Numeric"/>
            <Label Text="Oracle narudbženica" FontAttributes="Bold" 
            TextColor="Black"/>
            <Entry Placeholder="Oracle ordine" FontSize="Small" 
            HorizontalOptions="FillAndExpand" 
            Keyboard="Email" x:Name="email"/>
            <Label Text="Naručilac" 
            FontAttributes="Bold" TextColor="Black"/>
            <Entry Placeholder="Cliente" FontSize="Small" 
                   HorizontalOptions="FillAndExpand" 
                   IsPassword="True" x:Name="password"/>

            <Button Text="Sačuvaj" Clicked="SaveEmployee" 
            HorizontalOptions="FillAndExpand" 
                    BackgroundColor="LightGreen" 
                    TextColor="Black" x:Name="saveBtn"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>



What I have tried:

I have an error in this code, app work, when click save just close.
App just closes. Please give some recommendations.
Posted
Updated 7-Sep-23 4:10am
v2
Comments
Graeme_Grant 7-Sep-23 8:23am    
Where is the code for the SaveEmployee method?
Stylus STYLUS 7-Sep-23 8:26am    
private void SaveEmployee(object sender, EventArgs e)
{
if (saveBtn.Text == "Potvrdi")
{
Employee employee = new Employee();
employee.Name = name.Text;
employee.Address = address.Text;
employee.PhoneNumber = phoneNumber.Text;
employee.Email = email.Text;
employee.Password = password.Text;

bool res = DependencyService.Get<isqlite>().SaveEmployee(employee);
if (res)
{
Navigation.PopAsync();
}
else
{
DisplayAlert("Message", "Data Failed To Save", "Ok");
}
}
else
{
// update employee
employeeDetails.Name = name.Text;
employeeDetails.Address = address.Text;
employeeDetails.PhoneNumber = phoneNumber.Text;
employeeDetails.Email = email.Text;

bool res = DependencyService.Get<isqlite>().UpdateEmployee(employeeDetails);
if (res)
{
Navigation.PopAsync();
}
else
{
DisplayAlert("Message", "Data Failed To Update", "Ok");
}
}
}
Richard Deeming 7-Sep-23 8:38am    
Any unhandled exception in an event handler will normally terminate the process.

Start by wrapping the code in a try..catch block, and examining the exception that's being thrown.

Without that information, there's no way to diagnose the problem.
Richard Deeming 7-Sep-23 8:39am    
Also, you appear to be storing your users' credentials in plain text. Don't do that!

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
Graeme_Grant 7-Sep-23 8:55am    
Update your question using the "Improve question" link as here is inappropriate.

Statements such as:
C#
DependencyService.Get<isqlite>().UpdateEmployee(employeeDetails);

are a bad idea. If the Get call fails for any reason then a NullPointerException will follow. And since your code is not catching exceptions you will likely miss the critical information.
 
Share this answer
 
We can't tell: we have no idea what your code is doing, and no way to access it.

So start by looking at the SaveEmployee method, and use the debugger to find out what exactly it is doing. At a guess, it's your connections string, or the SQL command that is faulty - and throwing an exception which causes your app to close.

But we can't help with that as we can't run yoru code here!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900