protected void btnAlterarProduto_Click(object sender, EventArgs e) { Produto produto = CarregaProdutoFromCampos(); FuncoesProduto funcoes = new FuncoesProduto(); if (funcoes.UpdateProduto(produto) ) { lblStatus.Text = "Dados do produto atualizados com sucesso."; } else { lblStatus.Text = "Mão foi possível localizar este produto."; } }
protected void btnInserirProduto_Click(object sender, EventArgs e) { //Boolean fileOK = false; Boolean fileOK = true; //String path = Server.MapPath("~/Catalog/Images/"); //if (fileCaminhoFoto.HasFile) //{ // String fileExtension = System.IO.Path.GetExtension(fileCaminhoFoto.FileName).ToLower(); // String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" }; // for (int i = 0; i < allowedExtensions.Length; i++) // { // if (fileExtension == allowedExtensions[i]) // { // fileOK = true; // } // } //} if (fileOK) { //try //{ // // Save to Images folder. // fileCaminhoFoto.PostedFile.SaveAs(path + fileCaminhoFoto.FileName); // // Save to Images/Thumbs folder. // fileCaminhoFoto.PostedFile.SaveAs(path + "Thumbs/" + fileCaminhoFoto.FileName); //} //catch (Exception ex) //{ // lblInserirStatus.Text = ex.Message; //} // Inserir produto no BD FuncoesProduto funcoesProduto = new FuncoesProduto(); Produto novoProduto = CarregaProdutoFromCampos(); bool sucessoInsercao = funcoesProduto.InserirProduto(novoProduto); if (sucessoInsercao) { // Reload the page. string pageUrl = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.Count() - Request.Url.Query.Count()); Response.Redirect(pageUrl + "?Retorno=inserido"); } else { lblStatus.Text = "Unable to add new product to database."; } } else { lblStatus.Text = "Unable to accept file type."; } }