public bool DeleteFinancialProduct(IFinancialProduct financialProduct) { bool removeu; removeu = crud.DeleteFinancialProduct(FinancialProducts, financialProduct); NotificaTelaSePrecisa(FinancialProducts); return(removeu); }
public void UpdateFinancialProduct(ICollection <IFinancialProduct> listProducts, IFinancialProduct financialProduct) { try{ if (financialProduct.categoria == "Stock") { financialProduct.AtualizaEmNovaJanela(); //Não deveria atualizar ainda Stock stock = (Stock)financialProduct; connection.Open(); cmd = new System.Data.SQLite.SQLiteCommand(connection); { if (stock.Id != 0) { cmd.CommandText = "UPDATE Stock SET name=@name, code=@code WHERE Id=@Id"; //cmd.Prepare(); cmd.Parameters.AddWithValue("@Id", stock.Id); //cmd.Parameters.AddWithValue("@categoria", stock.categoria); cmd.Parameters.AddWithValue("@name", stock.name); cmd.Parameters.AddWithValue("@code", stock.code); try { cmd.ExecuteNonQuery(); } catch (Exception e) { MessageBox.Show("Erro ao atualizar ação: " + e); } } } } else { if (financialProduct.categoria == "Fund") { financialProduct.AtualizaEmNovaJanela(); //Não deveria atualizar ainda Fund fund = (Fund)financialProduct; connection.Open(); cmd = new System.Data.SQLite.SQLiteCommand(connection); { if (fund.Id > 0) { cmd.CommandText = "UPDATE Fund SET name=@name, tipo=@tipo, setor=@setor WHERE Id=@Id"; //cmd.Prepare(); cmd.Parameters.AddWithValue("@Id", fund.Id); cmd.Parameters.AddWithValue("@name", fund.name); cmd.Parameters.AddWithValue("@tipo", fund.tipo); cmd.Parameters.AddWithValue("@setor", fund.setor); try { cmd.ExecuteNonQuery(); } catch (Exception e) { MessageBox.Show("Erro ao atualizar fundo: " + e); } } } } else { MessageBox.Show("Produto de categoria desconhecida: "); return; } } } catch (Exception e) { MessageBox.Show("Erro ao estabelecer conexão com banco de dados: " + e); } finally { connection.Close(); } }
public bool DeleteFinancialProduct(ICollection <IFinancialProduct> listProducts, IFinancialProduct financialProduct) { try { connection.Open(); cmd = new System.Data.SQLite.SQLiteCommand(connection); { if (financialProduct.categoria == "Stock") { cmd.CommandText = "DELETE FROM Stock WHERE Id=@Id"; } else { if (financialProduct.categoria == "Fund") { cmd.CommandText = "DELETE FROM Fund WHERE Id=@Id"; } else { MessageBox.Show("Produto de categoria desconhecida"); return(false); } } //cmd.Prepare(); cmd.Parameters.AddWithValue("@Id", financialProduct.Id); try { cmd.ExecuteNonQuery(); listProducts.Remove(financialProduct); return(true); } catch (Exception e) { MessageBox.Show("Erro ao remover fundo: " + e); return(false); } } } catch (Exception e) { MessageBox.Show("Erro em conexão do banco de dados: " + e.Message); return(false); } finally { connection.Close(); } //using (SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(databasePath)) //{ // connection.Delete(financialProduct); // listProducts = ReadDatabase(listProducts); //} }
//public UpdateWindow() //{ // InitializeComponent(); //} public UpdateShareWindow(IFinancialProduct financialProduct) { InitializeComponent(); DataContext = financialProduct; }
public void UpdateFinancialProduct(IFinancialProduct recebido) { crud.UpdateFinancialProduct(FinancialProducts, recebido); NotificaTelaSePrecisa(FinancialProducts); }
public UpdateWindowViewModel(IFinancialProduct financialProduct) { if (financialProduct.categoria == "Ação") { } }
public void UpdateFinancialProduct(ICollection <IFinancialProduct> listProducts, IFinancialProduct recebido) { }
public bool DeleteFinancialProduct(ICollection <IFinancialProduct> listProducts, IFinancialProduct financialProduct) { return(RetornaBooleanoParaReturnDoDelete); }
//public void AtualizaTelaPorModificarList() //{ // //this.Stock = new List<Stock>(this.Stock); // //OnPropertyChanged("FinancialProducts"); // this.Produtos = new List<IFinancialProduct>(this.Produtos); // OnPropertyChanged("Shares"); //} public void UpdateFinancialProduct(ICollection <IFinancialProduct> listProducts, IFinancialProduct recebido) { recebido.AtualizaEmNovaJanela(); //if (recebido.categoria == "Ação") //{ // UpdateShareWindow updateWindow = new UpdateShareWindow(recebido); // updateWindow.Show(); //} //else if (recebido.categoria == "Fundo") //{ // UpdateFundWindow updateWindow = new UpdateFundWindow(recebido); // updateWindow.Show(); //} //MainWindow updateWindow = new UpdateWindow(recebido); //updateWindow.Show(); //listStock.Find(x => x.code == code); //AtualizaTelaPorModificarList(); //listStock.Remove(listStock.Single(x => x.code == code)); //if(!listStock.Any()) }
public bool DeleteFinancialProduct(ICollection <IFinancialProduct> listProducts, IFinancialProduct financialProduct) { return(listProducts.Remove(financialProduct)); }