Ejemplo n.º 1
0
        private void Create()
        {
            Battery editItem          = new Battery();                                                //实例化一个新的model
            BatteryEditViewModel bevm = new BatteryEditViewModel(editItem, _batteryTypeServie.Items); //实例化一个新的view model

            bevm.DisplayName = "Battery-Create";
            bevm.commandType = CommandType.Create;
            var BatteryViewInstance = new BatteryView();      //实例化一个新的view

            BatteryViewInstance.DataContext = bevm;
            BatteryViewInstance.ShowDialog();                   //设置viewmodel属性
            if (bevm.IsOK == true)
            {
                _batteryService.SuperAdd(editItem);
            }
        }
Ejemplo n.º 2
0
        private void SaveAs()
        {
            Battery bc = new Battery();                                                         //实例化一个新的model
            BatteryEditViewModel bevm = new BatteryEditViewModel(bc, _batteryTypeServie.Items); //实例化一个新的view model

            bevm.Name          = _selectedItem.Name;
            bevm.BatteryType   = bevm.AllBatteryTypes.SingleOrDefault(i => i.Id == _selectedItem.BatteryType.Id);
            bevm.CycleCount    = _selectedItem.CycleCount;
            bevm.AssetUseCount = _selectedItem.AssetUseCount;
            bevm.DisplayName   = "Battery-Save As";
            bevm.commandType   = CommandType.SaveAs;
            var BatteryViewInstance = new BatteryView();      //实例化一个新的view

            BatteryViewInstance.DataContext = bevm;
            BatteryViewInstance.ShowDialog();
            if (bevm.IsOK == true)
            {
                _batteryService.SuperAdd(bc);
            }
        }
Ejemplo n.º 3
0
        private void Edit()
        {
            Battery editItem          = new Battery();                                                //实例化一个新的model
            BatteryEditViewModel bevm = new BatteryEditViewModel(editItem, _batteryTypeServie.Items); //实例化一个新的view model

            bevm.Id   = _selectedItem.Id;
            bevm.Name = _selectedItem.Name;
            //bevm.BatteryType = _selectedItem.BatteryType;     //不能用这种方式,猜是因为传来传去之后,_selectedItem.BatteryType已经不是bevm.AllBatteryTypes的一员了
            bevm.BatteryType   = bevm.AllBatteryTypes.SingleOrDefault(i => i.Id == _selectedItem.BatteryType.Id); //所以改用Id来找到List里的item
            bevm.CycleCount    = _selectedItem.CycleCount;
            bevm.AssetUseCount = _selectedItem.AssetUseCount;
            bevm.DisplayName   = "Battery-Edit";
            bevm.commandType   = CommandType.Edit;
            var BatteryViewInstance = new BatteryView();      //实例化一个新的view

            BatteryViewInstance.DataContext = bevm;
            BatteryViewInstance.ShowDialog();
            if (bevm.IsOK == true)
            {
                _batteryService.SuperUpdate(editItem);
            }
        }