Hỏi đáp

Chia sẻ kiến thức, cùng nhau phát triển

Nhập kho-Phần mềm quản lý kho MVVM

17:23 13-11-2023 424 lượt xem 2 bình luận

Chào admin và mọi người. Em đang làm thêm phần nhập kho. Và khi em có lấy dữ liệu Tên vật tư từ Object, DateInput từ Input qua lớp InputViewModel thì có gặp lỗi :"System.Data.Entity.Validation.DbEntityValidationException: 'Validation failed for one or more entities. See 'EntityValidationErrors' property for more details" ngay ở dòng DataProvider.ins.DB.SaveChanged();
. Dưới đây là đoạn code InputViewModel của em ạ:

using Kho.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Object = Kho.Model.Object;

namespace Kho.ViewModel
{
    public class InputViewModel:BaseViewModel
    {
        private ObservableCollection<InputInfo> _List;
        public ObservableCollection<InputInfo> List { get=>_List; set { _List = value;OnPropertyChanged(); } }
        private InputInfo _SelectedItem;
        public InputInfo SelectedItem 
        { get => _SelectedItem;
            set
            {
                _SelectedItem = value;
                OnPropertyChanged();
                if (SelectedItem != null)

                    Count = (int)SelectedItem.Count;
                    InputPrice = (double)SelectedItem.InputPrice;
                    OutputPrice = (double)SelectedItem.OutputPrice;
                    Status = SelectedItem.Status;
                    ObjectDisplayname = SelectedItem.Object.DisplayName;
                    DateInput = (DateTime)SelectedItem.Input.DateInput;
            }
        }

        private string _ObjectDisplayname;
        public string ObjectDisplayname { get => _ObjectDisplayname; set { _ObjectDisplayname = value; OnPropertyChanged(); } }

        private DateTime? _DateInput;
        public DateTime? DateInput { get => _DateInput; set { _DateInput = value; OnPropertyChanged(); } }

        private int _Count;
        public int Count { get => _Count; set { _Count = value; OnPropertyChanged(); } }

        private double _InputPrice;
        public double InputPrice { get => _InputPrice; set { _InputPrice = value; OnPropertyChanged(); } }

        private double _OutputPrice;
        public double OutputPrice { get => _OutputPrice; set { _OutputPrice = value; OnPropertyChanged(); } }

        private string _Status;
        public string Status { get => _Status; set { _Status = value; OnPropertyChanged(); } }

        public ICommand AddCommand { get; set; }
        public ICommand EditCommand { get; set; }
        public InputViewModel() 
        {
            List = new ObservableCollection<InputInfo>(DataProvider.ins.DB.InputInfoes);
            AddCommand = new RelayCommand<object>((p) =>
            {
                return true;
            }, (p) =>
            {
                var _InputInfo = new InputInfo() { Count = Count, InputPrice = InputPrice, OutputPrice = OutputPrice, Status = Status };
                DataProvider.ins.DB.InputInfoes.Add(_InputInfo);
                DataProvider.ins.DB.SaveChanges();

                List.Add(_InputInfo);
            }
            );
        }
    }
}
 

Bình luận

Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.

Đăng nhập
Quyetbk đã bình luận 15:28 15-11-2023

Hình ảnh lỗi ở đây nhé mn
https://drive.google.com/file/d/17uOCO1NAcVBB3fjEBnG9TfLOAE0ZZ9J9/view?usp=sharing

Vo Tan Duc đã bình luận 20:01 13-11-2023

Bạn chụp hình dòng báo lỗi giúp mình cho mọi người dễ nắm bắt thông tin lỗi hơn nha

Câu hỏi mới nhất