Данные не сохраняются в базу данных с использованием форм sqlite c # xamarin - PullRequest
0 голосов
/ 10 сентября 2018

Я пытаюсь сохранить в базу данных SQLite, но она не пишет в нее. в то время как я отлаживал, свойство text моих записей установлено на текст, который я ввел во время выполнения, но при сохранении в базе данных значения устанавливаются в null и ничего не возвращает моему ListView. Ниже моя модель для моей базы данных:

  public class Products : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private string  _Itemname;
    private string _Details;


    [PrimaryKey,AutoIncrement]
    public int ProductId { get; set; }
    [MaxLength(30)] [NotNull]
    public string Itemname {
        get
        {
            return _Itemname; 
        }
        set
        {
            if(_Itemname ==  value)
            return;

            _Itemname = value;

        }
    }

    public string ItemBrand { get; set; }

    [NotNull]
    public string Date { get; set; }
    public string Details {
        get
        {
            return _Details;
        }
        set
        {
            if (_Details == value)
                return;
            _Details = value;
        }
    }

    public string Category { get; set; }
    [NotNull]
    public string Supplier { get; set; }
    [NotNull]
    public string Price { get; set; }
    public string Quantity { get; set; }

    private void OnPropertyChanged([CallerMemberName]string propertyname=null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
    }

Приведенный ниже код является моим кодом addButton c #: MyConnection = DependencyService.Get (). Connection ();

        //CreateTable();
        BindingContext = new Products
        {
            Itemname = ItemNameTextBox.Text,
            ItemBrand = ItemBrandTextBox.Text,
            Date = DateTextBox.ToString(),
            Details = DetailsTextBox.Text,
            Category = CategoryTextBox.ToString(),
            Supplier = SupplierTextBox.Text,
            Price = PriceTextBox.Text,
            Quantity = QuantityTextBox.Text
        };
    }

    private async void SaveItemButton_Clicked(object sender, EventArgs e)
    {
        var a = BindingContext as Products;
        if(string.IsNullOrWhiteSpace(ItemNameTextBox.Text)|| string.IsNullOrWhiteSpace(ItemBrandTextBox.Text)|| string.IsNullOrWhiteSpace(SupplierTextBox.Text)
            || string.IsNullOrWhiteSpace(PriceTextBox.Text) || string.IsNullOrWhiteSpace(QuantityTextBox.Text))
        {
           await DisplayAlert("Invalid Command", "Fields cannot be empty", "Ok");
            return;
        }
        else
        {
            await MyConnection.InsertAsync(a);
            ProductAdded?.Invoke(this, a);

            await DisplayAlert("Yay!!!", "Product added successfully....", "Ok");
           var result= await  DisplayAlert("Additional Prompt", "Do you want to add another product?", "Yes", "No");

            if (result) {               ItemBrandTextBox.Text = "";
            ItemNameTextBox.Text = "";
            DetailsTextBox.Text = "";
            SupplierTextBox.Text = "";
            PriceTextBox.Text = "";
            QuantityTextBox.Text = "";}
            else
            {
             await   Navigation.PopAsync();
            }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...