Beispiel #1
0
        public CargoEditViewModel()
        {
            _SelectedUnits     = "";
            _UnitsCollection   = WebApiOperate.StatiCargosUnits;
            _SelectedGroupName = "";
            _PicPath           = "";
            _EditModel         = "添加";
            WeakReferenceMessenger.Default.Register <string, string>(this, "DataCom", Decode);
            WindowsStatus.CargoEditWindowOpen = true;
            _GroupNameCollection  = WebApiOperate.StatiCargosGroups;
            PDCreatePdCodeCommand = new RelayCommand(() =>
            {
                var S = DateTime.Now.ToString("yyyyMMddHHmmss") + WebApiOperate.StatiCargoInfoModels.Count.ToString("D5");
                NewDetialMoedl.PDCode = S;
            });
            PDSaveThisGoodC0Mmand = new RelayCommand(() =>
            {
                WebApiOperate.InserOrUpdateCargo(NewDetialMoedl);
            });
            AddGroupNameCommand = new RelayCommand(() =>
            {
                if (!string.IsNullOrEmpty(NewGroupNameInput))
                {
                    WebApiOperate.StatiCargosGroups = WebApiOperate.InserOrUpdateGroup(NewGroupNameInput).Result;
                }
                GroupNameCollection = WebApiOperate.StatiCargosGroups;
                NewGroupNameInput   = "";
            });
            AddUnitCommand = new RelayCommand(() =>
            {
                if (!string.IsNullOrEmpty(InputUnit))
                {
                    WebApiOperate.StatiCargosUnits = WebApiOperate.InserOrUpdateunit(InputUnit).Result;
                }
                UnitsCollection = WebApiOperate.StatiCargosUnits;
                InputUnit       = "";
            });
            SelectPicPath = new RelayCommand <TextBox>(T =>
            {
                var Dialog    = new OpenFileDialog();
                Dialog.Filter = "All Image Files|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;*.png;*.tif;*.tiff|" + "Windows Bitmap(*.bmp)|*.bmp|" + "Windows Icon(*.ico)|*.ico|" + "Graphics Interchange Format (*.gif)|(*.gif)|" + "JPEG File Interchange Format (*.jpg)|*.jpg;*.jpeg|" + "Portable Network Graphics (*.png)|*.png|" + "Tag Image File Format (*.tif)|*.tif;*.tiff";
                var Result    = Dialog.ShowDialog();
                if ((bool)Result)
                {
                    PicPath = Dialog.FileName;
                    NewDetialMoedl.PicPath = Dialog.SafeFileName;
                    WebApiOperate.UpLoadPic(PicPath);
                }
            });
            ClosedCommand = new RelayCommand(() =>
            {
                WindowsStatus.CargoEditWindowOpen = false;
            });
            GroupSelectedCommand = new RelayCommand <CargosGroup>(g =>
            {
                if (g != null)
                {
                    SelectedGroupName = g.PDGroup;
                }
                else
                {
                    SelectedGroupName = "";
                }

                if (NewDetialMoedl == null)
                {
                    NewDetialMoedl = new CargoInfoModel();
                }

                NewDetialMoedl.PDGroup = g.PDGroup;
            });
            UnitSelectedComamnd = new RelayCommand <CargoUnit>(u =>
            {
                if (u != null)
                {
                    SelectedUnits = u.Unit;
                }
                else
                {
                    SelectedUnits = "";
                }

                if (NewDetialMoedl == null)
                {
                    NewDetialMoedl = new CargoInfoModel();
                }

                NewDetialMoedl.PDUnit = u.Unit;
            });
        }