您好,我无法弄清楚我的表格出了什么问题。我已经尝试调试,并且会给我这个:
'ProjectDAD.exe' (CLR v4.0.30319: ProjectDAD.exe): Loaded'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\UIAutomationProvider\v4.0_4.0.0.0__31bf3856ad364e35\UIAutomationProvider.dll'. Cannot find or open the PDB file.
'ProjectDAD.exe' (CLR v4.0.30319: ProjectDAD.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Accessibility\v4.0_4.0.0.0__b03f5f7f11d50a3a\Accessibility.dll'. Cannot find or open the PDB file.
'ProjectDAD.exe' (CLR v4.0.30319: ProjectDAD.exe): Loaded 'C:\WINDOWS\system32\WinMetadata\Windows.UI.winmd'. Module was built without symbols.
'ProjectDAD.exe' (CLR v4.0.30319: ProjectDAD.exe): Loaded 'C:\WINDOWS\system32\WinMetadata\Windows.Foundation.winmd'. Module was built without symbols.
'ProjectDAD.exe' (CLR v4.0.30319: ProjectDAD.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.InteropServices.WindowsRuntime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.InteropServices.WindowsRuntime.dll'. Module was built without symbols.
'ProjectDAD.exe' (CLR v4.0.30319: ProjectDAD.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.WindowsRuntime\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.WindowsRuntime.dll'. Cannot find or open the PDB file.
The program '[13388] ProjectDAD.exe' has exited with code 0 (0x0).
除了我每次运行该表单并单击该表单上的按钮时,都不会显示任何错误,它什么也不会做。不会给我任何错误。就像我单击按钮时事件未运行。
这是我的表格的Cs代码:
using System;
using System.Windows;
using ProjectDAD.Models.DB;
namespace ProjectDAD.Rental_Management
{
/// <summary>
/// Interaction logic for toRent.xaml
/// </summary>
public partial class toRent : Window
{
public toRent()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
System.Windows.Data.CollectionViewSource truckRentalViewSource =
((System.Windows.Data.CollectionViewSource)
(this.FindResource("truckRentalViewSource")));
// Load data by setting the CollectionViewSource.Source property:
// truckRentalViewSource.Source = [generic data source]
System.Windows.Data.CollectionViewSource truckCustomerViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("truckCustomerViewSource")));
// Load data by setting the CollectionViewSource.Source property:
// truckCustomerViewSource.Source = [generic data source]
System.Windows.Data.CollectionViewSource truckPersonViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("truckPersonViewSource")));
// Load data by setting the CollectionViewSource.Source property:
// truckPersonViewSource.Source = [generic data source]
}
private void Button_Click(object sender, RoutedEventArgs e)
{
TruckCustomer cust = new TruckCustomer();
cust.Age = int.Parse(ageTextBox.Text);
cust.LicenseNumber = licenseNumberTextBox.Text;
cust.LicenseExpiryDate = licenseExpiryDateDatePicker.SelectedDate.Value.Date;
TruckPerson per = new TruckPerson();
per.Address = addressTextBox.Text;
per.Telephone = telephoneTextBox.Text;
per.Name = nameTextBox.Text;
int truckId = int.Parse(truckIdTextBox.Text);
IndividualTruck truck = DataService.searchTruckByID(truckId);
decimal priceTotal = decimal.Parse(totalPriceTextBox.Text);
TruckRental toRent = new TruckRental();
toRent.TotalPrice = priceTotal;
toRent.RentDate = new DateTime();
toRent.ReturnDate = new DateTime();
toRent.Customer = cust;
toRent.Truck = truck;
truck.Status = "Rented";
DataService.rentTruck(toRent, true);
MessageBox.Show("Truck rented succesfully");
}
}
}
这是我的数据服务CS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectDAD.Models.DB;
using Microsoft.EntityFrameworkCore;
namespace ProjectDAD
{
public class DataService
{
public static void rentTruck(TruckRental toRent, bool isNewCustomer)
{
using (var ctx = new DAD_TruckRental_RGMContext())
{
if(!isNewCustomer)
{
ctx.Entry(toRent.Customer).State = EntityState.Unchanged;
}
ctx.Entry(toRent.Customer).State = EntityState.Modified;
ctx.TruckRental.Add(toRent);
ctx.SaveChanges();
}
}
public static IndividualTruck searchTruckByID(int truckid)
{
using (var ctx = new DAD_TruckRental_RGMContext())
{
return ctx.IndividualTruck.Where(t => t.TruckId == truckid).FirstOrDefault();
}
}
}
}
答案 0 :(得分:0)
请检查按钮绑定,并确保已将其正确绑定到单击处理程序。 您可以使用“探听”来查看可视化树,运行时绑定和所有属性。它还显示了UI触发了哪些事件。您可以找到它here。 希望这会有所帮助。
答案 1 :(得分:0)
您需要在XAML中挂接事件处理程序:
<Button FontSize="25" Content="Sell" HorizontalAlignment="Left"
Margin="340,318,0,0" VerticalAlignment="Top" Width="129" Height="37"
Click="Button_Click" />