예제 #1
0
        private void BtnSalvar_Click(object sender, EventArgs e)
        {
            if (TextDescricao.Text.Length == 0 || NumericLucro.Value == 0 || NumericMarkup.Value == 0 || TextCodigo.Text.Length == 0 || TextDescricaoCompleta.Text.Length == 0)
            {
                MessageBox.Show("Favor preencher todo os campos marcados com '*' !", "Erro !", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else if (IdProduto.Length == 0)
            {
                MessageBox.Show(
                    "Favor realizar uma pesquisa!", "Atenção !",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Exclamation);
            }
            else
            {
                for (int i = 0; i < ListMateriaPrima.Rows.Count; i++)

                {
                    for (int j = 0; j < AuxMateriaPrima.Items.Count; j++)
                    {
                        try
                        {
                            if (ListMateriaPrima.Rows[i].Cells["ID"].Value.ToString().Contains(AuxMateriaPrima.Items[j].Text))
                            {
                                AuxMateriaPrima.Items[j].Remove();
                            }
                            else
                            {
                            }
                        }
                        catch (Exception f)
                        {
                            MessageBox.Show(f.ToString());
                        }
                    }
                }
                //servico
                for (int i = 0; i < ListServicos.Rows.Count; i++)

                {
                    for (int j = 0; j < AuxServico.Items.Count; j++)
                    {
                        try
                        {
                            if (ListServicos.Rows[i].Cells["IDSERVICO"].Value.ToString().Contains(AuxServico.Items[j].Text))
                            {
                                AuxServico.Items[j].Remove();
                            }
                            else
                            {
                            }
                        }
                        catch (Exception f)
                        {
                            MessageBox.Show(f.ToString());
                        }
                    }
                }
                // aviamenos
                for (int i = 0; i < ListAviamentos.Rows.Count; i++)

                {
                    for (int j = 0; j < AuxAviamento.Items.Count; j++)
                    {
                        try
                        {
                            if (ListAviamentos.Rows[i].Cells["IDAVIAMENTO"].Value.ToString().Contains(AuxAviamento.Items[j].Text))
                            {
                                AuxAviamento.Items[j].Remove();
                            }
                            else
                            {
                            }
                        }
                        catch (Exception f)
                        {
                            MessageBox.Show(f.ToString());
                        }
                    }
                }
                //Custos
                for (int i = 0; i < ListCustos.Rows.Count; i++)

                {
                    for (int j = 0; j < AuxCustos.Items.Count; j++)
                    {
                        try
                        {
                            if (ListCustos.Rows[i].Cells["IDCUSTO"].Value.ToString().Contains(AuxCustos.Items[j].Text))
                            {
                                AuxCustos.Items[j].Remove();
                            }
                            else
                            {
                            }
                        }
                        catch (Exception f)
                        {
                            MessageBox.Show(f.ToString());
                        }
                    }
                }
                DataTable MatPrima   = Conversor.DataGridView2DataTable(ListMateriaPrima);
                DataTable Servicos   = Conversor.DataGridView2DataTable(ListServicos);
                DataTable Aviamento  = Conversor.DataGridView2DataTable(ListAviamentos);
                DataTable Custo      = Conversor.DataGridView2DataTable(ListCustos);
                string    Disponivel = "";
                if (RadioDisponivel.Checked)
                {
                    Disponivel = "S";
                }
                else
                {
                    Disponivel = "N";
                }
                CadastroProduto.AtualizarProduto(TextDescricaoCompleta.Text, Disponivel, TextDescricao.Text, NumericMarkup.Value, NumericDescontoAprazo.Value,
                                                 NumericDescontoAvista.Value, NumericDescontoAtacado.Value, NumericLucro.Value, MatPrima,
                                                 Servicos, Aviamento, Custo, IdProduto, AuxAviamento, AuxCustos, AuxMateriaPrima,
                                                 AuxServico, TextCodigo.Text);
                MessageBox.Show("Dados atualizados com sucesso !", "Sucesso !", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                ListAviamentos.Rows.Clear();
                ListMateriaPrima.Rows.Clear();
                ListServicos.Rows.Clear();
                ListCustos.Rows.Clear();
                NumericPrecoCusto.Value = 0;
                NumericAprazo.Value     = 0;
                NumericTotal.Value      = 0;
                NumericLucro.Value      = 0;
                NumericMarkup.Value     = 0;
                TextDescricao.Text      = "";
                IdProduto                  = "";
                TextCodigo.Text            = "";
                TextDescricaoCompleta.Text = "";
                RadioDisponivel.Checked    = true;
            }
        }