protected void btnSalvar_Click(object sender, EventArgs e) { try { if (ValidarCampos()) { ProdutoModel oModel = new ProdutoModel(); ProdutoNegocios oNegocios = new ProdutoNegocios(); if (!string.IsNullOrEmpty(Produto_Id.Value)) { oModel.Codigo = UTIL.UTIL.Parse <int>(Produto_Id.Value); } oModel.Codigo_Funcionario = UTIL.UTIL.Parse <int>(cdFuncionario.Text); oModel.Codigo_Fornecedor = UTIL.UTIL.Parse <int>(cmbFornecedor.SelectedValue); if (!string.IsNullOrEmpty(txQuantMinima.Text)) { oModel.QuantidadeEstoque_Minima = UTIL.UTIL.Parse <int>(txQuantMinima.Text); } oModel.Descricao = txDescricao.Text; if (!string.IsNullOrEmpty(txDataValidade.Text)) { oModel.DataValidade = UTIL.UTIL.Parse <DateTime>(txDataValidade.Text); } oModel.PrecoCompra = UTIL.UTIL.Parse <Decimal>(txValorCompra.Text); oModel.PrecoVenda = UTIL.UTIL.Parse <Decimal>(txValorVenda.Text); oModel = oNegocios.Salvar(oModel); Produto_Id.Value = oModel.Codigo.ToString(); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SUCESSbtnSalvar_Click", "$(document).MensagemModal(1,'Registro salvo com <strong>sucesso</strong>!');", true); } } catch (Exception ex) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ERROR", "$(document).MensagemModal(3,'Ocorreu um erro inesperado! Mensagem = " + new JavaScriptSerializer().Serialize(ex.Message.ToString()) + "');", true); } }