public static Boolean Delete(ItemTO clsItem) { String myConnection = "Server=localhost;Database=gerenciadornf;Uid=root;Pwd=;"; MySqlConnection connection = new MySqlConnection(myConnection); MySqlCommand cmd; connection.Open(); try { StringBuilder strSql = new StringBuilder(); strSql.Append("DELETE FROM Item WHERE IDItem=@IDItem"); cmd = connection.CreateCommand(); cmd.CommandText = strSql.ToString(); cmd.Parameters.AddWithValue("@IDItem", clsItem.IDItem); cmd.ExecuteNonQuery(); return true; } catch (Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } }
protected void gvwItem_RowDeleting(object sender, GridViewDeleteEventArgs e) { ItemTO clsItem = new ItemTO(); Int32 ID = (Int32)gvwItem.DataKeys[e.RowIndex].Value; clsItem = ItemBLL.GetItemByID(ID); ItemBLL.Delete(clsItem); LoadGrid(); }
public static ItemTO GetItemByID(int IDItem) { try { ItemTO clsItem = new ItemTO(); String myConnection = "Server=localhost;Database=gerenciadornf;Uid=root;Pwd=;"; MySqlConnection connection = new MySqlConnection(myConnection); MySqlCommand cmd; connection.Open(); string strSql = "SELECT Item.* FROM Item WHERE Item.IDItem = @IDItem"; cmd = connection.CreateCommand(); cmd.CommandText = strSql; cmd.Parameters.AddWithValue("@IDItem", IDItem); cmd.ExecuteNonQuery(); MySqlDataReader adap = cmd.ExecuteReader(); while (adap.Read()) { clsItem.IDItem = Convert.ToInt32(adap["IDItem"]); clsItem.Nome = adap["nome"].ToString(); clsItem.Descricao = adap["Descricao"].ToString(); } return clsItem; } catch (Exception ex) { throw new Exception(ex.Message); } finally { } }
public static void insert(ItemTO clsItem) { String myConnection = "Server=localhost;Database=gerenciadornf;Uid=root;Pwd=;"; MySqlConnection connection = new MySqlConnection(myConnection); MySqlCommand cmd; connection.Open(); try { StringBuilder strSql = new StringBuilder(); strSql.Append("INSERT INTO Item(IDItem, Nome, Descricao) "); strSql.Append("VALUES (@IDItem, @Nome, @Descricao); "); strSql.Append("SELECT Item.* FROM Item WHERE Item.IDItem=@@IDENTITY;"); cmd = connection.CreateCommand(); cmd.CommandText = strSql.ToString(); cmd.Parameters.AddWithValue("@IDItem", clsItem.IDItem); cmd.Parameters.AddWithValue("@Nome", clsItem.Nome ); cmd.Parameters.AddWithValue("@Descricao", clsItem.Descricao); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } }
public static List<ItemTO> listaItemAll() { try { List<ItemTO> clsItems = new List<ItemTO>(); String myConnection = "Server=localhost;Database=gerenciadornf;Uid=root;Pwd=;"; MySqlConnection connection = new MySqlConnection(myConnection); MySqlCommand cmd; connection.Open(); string strSql = "SELECT Item.* FROM Item"; cmd = connection.CreateCommand(); cmd.CommandText = strSql; cmd.ExecuteNonQuery(); MySqlDataReader adap = cmd.ExecuteReader(); while (adap.Read()) { ItemTO clsItem = new ItemTO(); clsItem.IDItem = Convert.ToInt32(adap["IDItem"]); clsItem.Nome = adap["nome"].ToString(); clsItem.Descricao = adap["Descricao"].ToString(); clsItems.Add(clsItem); } return clsItems; } catch (Exception ex) { throw new Exception(ex.Message); } finally { } }
private void PopulaDados() { clsItem = this.Item; txtNome.Text = clsItem.Nome; txtDescricao.Text = clsItem.Descricao; }
protected void Load() { clsItem = this.Item; clsItem.Nome = txtNome.Text; clsItem.Descricao = txtDescricao.Text; }
public static Boolean Update(ItemTO clsItem) { return ItemDAL.Update(clsItem); }
public static void insert(ItemTO clsItem) { ItemDAL.insert(clsItem); }
public static Boolean Delete(ItemTO clsItem) { return ItemDAL.Delete(clsItem); }