0

我正在处理一些酒店应用程序。我在主窗口中有一个带有酒店住宿列表的列表视图。Listview 有一个复选框列,用于通知天气住宿是否完成。Listview 也绑定到视图模型的属性。复选框绑定到来自视图模型的命令。

这是listview的绑定

<ListView SelectionMode="Single" Height="428" HorizontalAlignment="Left" Margin="6,6,0,0" Name="lvStays" VerticalAlignment="Top" Width="654" BorderBrush="Black" Foreground="Black" ItemsSource="{Binding Path=MainGuests}" SelectedItem="{Binding Path= MainGuest}" />

主窗口视图模型

 private ServiceReference1.tblStayGuest mainGuest;
    public ServiceReference1.tblStayGuest MainGuest
    {
        get
        {
            return mainGuest;
        }
        set
        {
            mainGuest = value;
            OnPropertyChanged("MainGuest");
        }
    }

    private ObservableCollection<ServiceReference1.tblStayGuest> mainGuests;
    public ObservableCollection<ServiceReference1.tblStayGuest> MainGuests     
    {
        get
        {
            return mainGuests;
        }
        set
        {
            mainGuests = value;
            OnPropertyChanged("MainGuests");
        }
    }

private ICommand _FinishedStay;
    public ICommand FinishedStay
    {
        get
        {
            if (_FinishedStay == null)
            {
                _FinishedStay = new DelegateCommand(delegate()
                {
                    try
                    {
                        ServiceReference1.Service1Client wcf = new ServiceReference1.Service1Client();
                        wcf.FinishedStay(MainGuest);

                        if (MainGuest.tblStay.IsFinished == true)
                        {

                            MainGuests.Remove(MainGuest);
                        }                            
                    }
                    catch
                    {
                        Trace.WriteLine("working...", "MyApp");
                    }
                });
            }
            return _FinishedStay;
        }
    }

这是WCF服务上的方法

 bool IService1.FinishedStay(tblStayGuest mainGuest)
    {
        try
        {
            context = new HotelBaseEntities();

            tblStayGuest stGuest = (from stg in context.tblStayGuests where stg.StayGuestID == mainGuest.StayGuestID select stg).FirstOrDefault();
            tblStay stay = (from st in context.tblStays where st.StayID == mainGuest.StayID select st).FirstOrDefault();
            tblGuest guest = (from g in context.tblGuests where g.GuestID == mainGuest.GuestID select g).FirstOrDefault();

            guest.IsCheckedOut = true;
            stGuest.IsMainGuest = false;
            stay.IsFinished = true;
            context.SaveChanges();

            return true;
        }
        catch (Exception e)
        {
            e.StackTrace.ToString();
            return false;
        }
    }

我在这里尝试管理的是将mainGuest.IsMainGuest的值更改为false。它是 wcf 方法上的值更改,但在我尝试执行此操作的 FinishedStay 命令上: MainGuests.Remove(MainGuest); MainGuest.IsMainGuest 的值返回 True。此值在数据库表中也不会更改。为什么会这样?

4

0 回答 0