コード例 #1
0
        /*botão salvar*/
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            try
            {
                string resp = "";
                if (this.txtNome.Text == string.Empty)
                {
                    MensagemErro("Preencha todos os campos");
                    errorIcone.SetError(txtNome, "Informe o nome");
                }
                else
                {
                    if (this.eNovo)
                    {
                        resp = NServico.Inserir(this.txtNome.Text.Trim(), Convert.ToDecimal(this.txtPreco.Text.Trim()));
                    }
                    else
                    {
                        resp = NServico.Editar(Convert.ToInt32(this.txtCodigo.Text), this.txtNome.Text.Trim(), Convert.ToDecimal(this.txtPreco.Text.Trim()));
                    }

                    if (resp.Equals("OK"))
                    {
                        if (this.eNovo)
                        {
                            this.MensagemOK("Registro salvo com sucesso");
                        }
                        else
                        {
                            this.MensagemOK("Registro editado com sucesso");
                        }
                    }
                    else
                    {
                        this.MensagemErro(resp);
                    }

                    this.eNovo   = false;
                    this.eEditar = false;
                    this.Botoes();
                    this.Limpar();
                    this.Mostrar();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
コード例 #2
0
        /*botão excluir*/
        private void btnExcluir_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult Opcao;
                Opcao = MessageBox.Show("Deseja excluir o registro?", "Sistema OS", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (Opcao == DialogResult.OK)
                {
                    string Codigo;
                    string Resp = "";

                    foreach (DataGridViewRow row in dataLista.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells[0].Value))
                        {
                            Codigo = Convert.ToString(row.Cells[1].Value);
                            Resp   = NServico.Excluir(Convert.ToInt32(Codigo));

                            if (Resp.Equals("OK"))
                            {
                                this.MensagemOK("Registro excluido com sucesso");
                            }
                            else
                            {
                                this.MensagemErro(Resp);
                            }
                        }
                    }
                    this.Mostrar();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
コード例 #3
0
 /*Buscar pelo Nome*/
 private void BuscarNome()
 {
     this.dataLista.DataSource = NServico.BuscarNome(this.txtBuscar.Text);
     this.OcultarColunas();
     lblTotal.Text = "Total de Registros: " + Convert.ToString(dataLista.Rows.Count);
 }
コード例 #4
0
 /*Mostrar no Data grid*/
 private void Mostrar()
 {
     this.dataLista.DataSource = NServico.Mostrar();
     this.OcultarColunas();
     lblTotal.Text = "Total de Registros: " + Convert.ToString(dataLista.Rows.Count);
 }