コード例 #1
0
 public static int insPlantas(ePlantas planta)
 {
     try
     {
         dPlantas db = new dPlantas();
         return(db.insPlantas(planta));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
        public int insPlantas(ePlantas planta)
        {
            int idRetorno = 0;

            objSqlConect = new SqlConnection();
            objSqlCom    = new SqlCommand();
            con          = new duConexao();

            objSqlCom.CommandType = CommandType.StoredProcedure;
            objSqlCom.CommandText = "USP_INS_PLANTAS";

            if (planta.Id == 0)
            {
                objSqlCom.Parameters.AddWithValue("@Id", null);
            }
            else
            {
                objSqlCom.Parameters.AddWithValue("@Id", planta.Id);
            }

            objSqlCom.Parameters.AddWithValue("@Nome", planta.Nome);
            objSqlCom.Parameters.AddWithValue("@Preco", float.Parse(planta.Preco));
            objSqlCom.Parameters.AddWithValue("@Qtd", planta.Qtd);
            objSqlCom.Parameters.AddWithValue("@Especial", planta.Especial);
            objSqlCom.Parameters.AddWithValue("@Status", planta.Status);
            objSqlCom.Parameters.Add("@Id_Retorno", SqlDbType.Int).Direction = ParameterDirection.Output;

            objSqlConect         = con.abrirConexao();
            objSqlCom.Connection = objSqlConect;

            try
            {
                objSqlCom.ExecuteNonQuery();
                idRetorno = int.Parse(objSqlCom.Parameters["@Id_Retorno"].Value.ToString());
            }
            catch (Exception ex)
            {
                if (!idRetorno.Equals(0))
                {
                    MessageBox.Show("Erro de Conexão \n" + ex.Message);
                }
            }
            finally
            {
                objSqlConect.Dispose();
                objSqlConect.Close();
                objSqlConect = null;
            }

            return(idRetorno);
        }
コード例 #3
0
        public ePlantas SetarObjeto(IDataReader dr)
        {
            ePlantas planta = new ePlantas();

            planta.Id           = Convert.ToInt32(dr["Id"]);
            planta.Nome         = dr["Nome"].ToString();
            planta.Preco        = dr["Preco"].ToString();
            planta.Qtd          = Convert.ToInt32(dr["Qtd"]);
            planta.NomeEspecial = dr["EspecialNome"].ToString();
            planta.Especial     = Convert.ToBoolean(dr["Especial"]);
            planta.Status       = Convert.ToBoolean(dr["Status"]);

            return(planta);
        }
コード例 #4
0
        private void btnPlantaEdtFinalizar_Click(object sender, EventArgs e)
        {
            float Preco = 0;
            int   qtd   = 0;


            if (listaTodasPlantas != null && listaTodasFotos != null)
            {
                listaPlanta = listaTodasPlantas.Where(c => c.Nome == lsPlanta.SelectedItem.ToString()).ToList();
                listaFoto   = listaTodasFotos.Where(c => c.IdPlanta == listaPlanta[0].Id).ToList();
            }
            else
            {
                listaTodasPlantas = nPlantas.selPlantas(null);
                listaTodasFotos   = nFotos.selFotos(null);

                listaPlanta = listaTodasPlantas.Where(c => c.Nome == lsPlanta.SelectedItem.ToString()).ToList();
                listaFoto   = listaTodasFotos.Where(c => c.IdPlanta == listaPlanta[0].Id).ToList();
            }


            if (!string.IsNullOrEmpty(tbPlantaEdtNome.Text) && float.TryParse(tbPlantaEdtPreco.Text, out Preco) == true &&
                int.TryParse(tbPlantaEdtQtd.Text, out qtd) == true && (rbPlantaEdtNao.Checked || rbPlantaEdtSim.Checked))
            {
                ePlantas planta = new ePlantas();

                planta.Id     = listaPlanta[0].Id;
                planta.Nome   = tbPlantaEdtNome.Text;
                planta.Preco  = Preco.ToString();
                planta.Qtd    = qtd;
                planta.Status = true;
                if (rbPlantaEdtNao.Checked == true)
                {
                    planta.Especial = false;
                }
                else if (rbPlantaEdtSim.Checked == true)
                {
                    planta.Especial = true;
                }

                nPlantas.insPlantas(planta);
                eFotos foto     = new eFotos();
                string fileName = string.Empty;
                try
                {
                    fileName = Path.GetFileName(pbPlantaImg.ImageLocation);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro ao pegar arquivo imagem \n\n", ex.Message);
                }

                caminho = @"E:\Projetos\AnotacoesDeCasa\Aplicação\FloriculturaImperial\FloriculturaImperial\ImgApp\";

                if (!File.Exists(caminho + fileName))
                {
                    File.Copy(pbPlantaImg.ImageLocation, caminho + fileName);
                }

                foto.Caminho = caminho + fileName;

                foto.IdPlanta = planta.Id;
                foto.Id       = listaFoto[0].Id;
                foto.Status   = true;
                if (nFotos.insFotos(foto))
                {
                    MessageBox.Show("Edição efetuada com Sucesso", "Edição sucedido", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    listaTodasPlantas = nPlantas.selPlantas(null);
                    listaTodasFotos   = nFotos.selFotos(null);
                    limparTudo(true);
                    preencherLista(tbPlantaEdtNome.Text);
                }
                else
                {
                    MessageBox.Show("Falha ao Editar", "Falha na Edição", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Há campos invalido", "Campo invalido", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #5
0
        private void btnPlantaCadFinalizar_Click(object sender, EventArgs e)
        {
            float Preco    = 0;
            int   qtd      = 0;
            int   idPlanta = 0;

            if (!string.IsNullOrEmpty(tbPlantasCadNome.Text) && float.TryParse(tbPlantaCadPreco.Text, out Preco) == true &&
                int.TryParse(tbPlantaCadQtd.Text, out qtd) == true && (rbPlantaEdtNao.Checked || rbPlantaEdtSim.Checked))
            {
                ePlantas planta = new ePlantas();

                planta.Nome  = tbPlantasCadNome.Text;
                planta.Preco = Preco.ToString();
                planta.Qtd   = qtd;
                if (rbPlantaCadNao.Checked)
                {
                    planta.Especial = false;
                }
                else if (rbPlantaCadSim.Checked)
                {
                    planta.Especial = true;
                }
                planta.Status = true;

                idPlanta = nPlantas.insPlantas(planta);

                eFotos foto     = new eFotos();
                string fileName = string.Empty;
                if (isImg)
                {
                    fileName = Path.GetFileName(pbPlantaImg.ImageLocation);
                    if (!File.Exists(caminho + fileName))
                    {
                        File.Copy(ofdImg.FileName, caminho);
                    }

                    foto.Caminho = caminho;
                }
                else
                {
                    foto.Caminho = @"E:\Projetos\AnotacoesDeCasa\Aplicação\FloriculturaImperial\FloriculturaImperial\ImgApp\img_nao_disponivel.jpg";
                }
                foto.Status   = true;
                foto.IdPlanta = idPlanta;

                if (nFotos.insFotos(foto))
                {
                    MessageBox.Show("Cadastro efetuado com Sucesso", "Cadastro sucedido", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    listaTodasPlantas = nPlantas.selPlantas(null);
                    listaTodasFotos   = nFotos.selFotos(null);
                    limparTudo(true);
                    preencherLista(tbPlantasCadNome.Text);
                }
                else
                {
                    MessageBox.Show("Falha ao cadastrar", "Falha no Cadastro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Há campos invalido", "Campo invalido", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #6
0
        private void btnVendasFinalizar_Click(object sender, EventArgs e)
        {
            bool gravou1 = false, gravou2 = false;

            if (lsVendasProdutos.SelectedItems.Count > 0)
            {
                if (lsVendasProdutos.Items.Count == listaTodasPlantas.Count)
                {
                    decimal  PrecoTotal = 0;
                    string[] Itens      = new string[lsVendasProdutos.SelectedItems.Count];

                    for (int i = 0; i < lsVendasProdutos.SelectedItems.Count; i++)
                    {
                        ePlantas planta            = new ePlantas();
                        decimal  PrecoTotalPorFlor = 0;

                        planta.Nome = lsVendasProdutos.SelectedItems[i].ToString();
                        if (listaTodasPlantas.Exists(c => c.Nome == planta.Nome))
                        {
                            planta = listaTodasPlantas.Find(c => c.Nome == planta.Nome);

                            if (listaPlantaVenda.Exists(c => c.Nome == planta.Nome))
                            {
                                planta.QtdVendida = listaPlantaVenda.Find(c => c.Nome == planta.Nome).QtdVendida;
                                PrecoTotalPorFlor = decimal.Parse(planta.Preco) * planta.QtdVendida;
                                if (listaTodasPlantas.Find(c => c.Nome == planta.Nome).Qtd > 0)
                                {
                                    planta.Qtd = planta.Qtd - planta.QtdVendida;
                                }
                            }
                            else
                            {
                                planta.QtdVendida = 1;
                                PrecoTotalPorFlor = decimal.Parse(planta.Preco) * planta.QtdVendida;
                                planta.Qtd        = planta.Qtd - 1;
                            }
                        }

                        nPlantas.insPlantas(planta);
                        eVendas vendasUnidade = new eVendas();

                        vendasUnidade.Preco        = PrecoTotalPorFlor;
                        vendasUnidade.Produto      = planta.Nome;
                        vendasUnidade.QtdVendidas  = planta.QtdVendida;
                        vendasUnidade.QtdEstocadas = planta.Qtd;

                        if (nVendas.insVendaProduto(vendasUnidade))
                        {
                            gravou1 = true;
                        }
                    }

                    //Cadastrando Vendas Totais

                    PrecoTotal = decimal.Parse(tbVendasPrecoTotal.Text.Replace("R$ ", ""));
                    string ItensXml = string.Empty;
                    string Auxilio  = "<Produtos>";

                    for (int i = 0; i < lsVendasProdutos.SelectedItems.Count; i++)
                    {
                        string Nome = lsVendasProdutos.SelectedItems[i].ToString();

                        if (listaTodasPlantas.Exists(c => c.Nome == Nome))
                        {
                            if (listaPlantaVenda.Exists(c => c.Nome == Nome))
                            {
                                Itens[i] = string.Format("<NomeProduto" + (i + 1) + ">{0}</NomeProduto" + (i + 1) + "><Preco" + (i + 1) + ">{1}</Preco" + (i + 1) + "><Qtd" + (i + 1) + ">{2}</Qtd" + (i + 1) + ">"
                                                         , Nome, listaTodasPlantas.Find(c => c.Nome == Nome).Preco, listaPlantaVenda.Find(c => c.Nome == Nome).QtdVendida);
                            }
                            else
                            {
                                Itens[i] = string.Format("<NomeProduto" + (i + 1) + ">{0}</NomeProduto" + (i + 1) + "><Preco" + (i + 1) + ">{1}</Preco" + (i + 1) + "><Qtd" + (i + 1) + ">{2}</Qtd" + (i + 1) + ">"
                                                         , Nome, listaTodasPlantas.Find(c => c.Nome == Nome).Preco, 1);
                            }
                        }
                    }

                    for (int i = 0; i < Itens.Length; i++)
                    {
                        ItensXml = ItensXml + Itens[i];
                    }

                    eVendas vendasTotal = new eVendas();

                    vendasTotal.ProdutoXml  = Auxilio + ItensXml + "</Produtos>";
                    vendasTotal.PrecoTotal  = PrecoTotal;
                    vendasTotal.QtdProdutos = Itens.Length;

                    if (nVendas.insVendaTotal(vendasTotal))
                    {
                        gravou2 = true;
                    }

                    if (gravou1 && gravou2)
                    {
                        MessageBox.Show("Venda Efetuada com sucesso", "Produtos Vendidos", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        lsVendasProdutos.ClearSelected();
                        checkesVendas();
                        listaPlantaVenda.Clear();
                    }
                }
            }
        }