示例#1
0
        public MaterialViewModel(int siteId)
        {
            _repositoryManager = new RepositoryManager(new SqliteContext());
            SiteId             = siteId;
            _materialTypes     = ProcessMaterialTypes(_repositoryManager.GetMaterialTypes());
            _units             = ProcessUnitType(_repositoryManager.GetUnitsOfMaterial());
            var vendors   = _repositoryManager.GetVendorBySiteId(SiteId);
            var materials = _repositoryManager.GetMaterialBySiteId(SiteId).ToList();

            VendorToAdd     = new Vendor();
            MaterialToAdd   = new Material();
            AddVendor       = new RelayCommand(AddVendorCommand);
            AddMaterial     = new RelayCommand(AddMaterialCommand);
            AddMaterialType = new RelayCommand(AddMaterialTypeCmd);
            AddUnitType     = new RelayCommand(AddUnitTypeCmd);
            DeleteVendor    = new RelayCommand(DeleteVendorCommand);
            DeleteMaterial  = new RelayCommand(DeleteMaterialCommand);
            _vendors        = new ObservableCollection <Vendor>(vendors);
            _materials      = new ObservableCollection <Material>(materials);
            VendorList      = ProcessVendors(vendors);
            SelectedVendor  = new VendorKeyValue();
            MaterialToAdd.SelectedMaterialType = MaterialTypes.First();
            MaterialToAdd.SelectedUnit         = Units.First();
            MaterialTypeToAdd = new MaterialType();
            UnitTypeToAdd     = new QuantityUnitType();
        }
示例#2
0
        private void AddMaterialCommand(object model)
        {
            ErrorMessage = "";
            var material = model as Material;

            if (material.BillAmount <= 0 ||
                material.Quantity <= 0 ||
                string.IsNullOrWhiteSpace(material.BillNumber) ||
                SelectedVendor.VendorId == 0 ||
                material.SelectedMaterialType.MaterialTypeId == 0 ||
                material.SelectedUnit.UnitId == 0)
            {
                ErrorMessage = "*Please check the entry. Some field's Values are missing.";
                return;
            }
            material.SelectedVendor = Vendors.Single(x => x.VendorId == SelectedVendor.VendorId);
            material.SiteId         = SiteId;
            material.CreatedDate    = DateTime.Now;
            _repositoryManager.AddMaterial(material);
            Materials     = new ObservableCollection <Material>(_repositoryManager.GetMaterialBySiteId(SiteId));
            MaterialToAdd = new Material();
            MaterialToAdd.SelectedUnit         = Units.First();
            SelectedVendor                     = VendorList.First();
            MaterialToAdd.SelectedMaterialType = MaterialTypes.First();
            OnPropertyChanged(nameof(MaterialToAdd));
            OnPropertyChanged(nameof(SelectedVendor));
        }
示例#3
0
        private void AddMaterialTypeCmd(object obj)
        {
            var materialType = obj as MaterialType;

            if (string.IsNullOrWhiteSpace(materialType.MaterialTypeName))
            {
                return;
            }
            _repositoryManager.AddMaterialType(materialType);

            MaterialTypeToAdd = new MaterialType();
            MaterialTypes     = ProcessMaterialTypes(_repositoryManager.GetMaterialTypes());
            MaterialToAdd.SelectedMaterialType = MaterialTypes.First();
            OnPropertyChanged(nameof(MaterialToAdd));
        }