Ejemplo n.º 1
0
        public static bool Insert(Sale sale)
        {
            if (!ValidatorSaleMessage(sale))
            {
                return(false);
            }

            DataTable dt = new DataTable();

            try
            {
                using (DAO.PgsqlConnection = new NpgsqlConnection(DAO.ConnString))
                {
                    //Abra a conexão com o PgSQL
                    DAO.PgsqlConnection.Open();

                    if (sale.Customer is null)
                    {
                        sale.Customer = new Customer(null, null);
                    }

                    string cmd = string.Format("select * from inserir_venda('{0}','{1}','{2}','{3}')",
                                               sale.Customer.CPF, sale.Date,
                                               sale.TotalMoney.ToString("N", CultureInfo.CreateSpecificCulture("en-US")),
                                               sale.TotalCard.ToString("N", CultureInfo.CreateSpecificCulture("en-US")));

                    using (NpgsqlDataAdapter Adpt = new NpgsqlDataAdapter(cmd, DAO.PgsqlConnection))
                    {
                        Adpt.Fill(dt);
                    }

                    if (dt.Rows.Count > 0)
                    {
                        string id_venda = dt.Rows[0]["inserir_venda"].ToString(); // Captura ID da venda
                        for (int i = 0; i < sale.SaleItem_.Count; i++)
                        {
                            sale.SaleItem_[i].VendaID = id_venda;
                        }
                    }
                }
            }
            catch (NpgsqlException ex)
            {
                MessageBox.Show("Erro: " + ex.Message + ".\nPor Favor contate o suporte.", "Erro de Banco de Dados",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message + ".\nPor Favor contate o suporte.", "Erro de Sofware",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                DAO.PgsqlConnection.Close();
            }

            return(SalelItemDAO.MultiInsertAuto(sale.SaleItem_)); // Executa inserção dos itens_venda
        }
Ejemplo n.º 2
0
        public static bool Insert(BillItem billItem)
        {
            if (!ValidatorSaleMessage(billItem.Sale))
            {
                return(false);
            }

            DataTable dt = new DataTable();

            try
            {
                using (DAO.PgsqlConnection = new NpgsqlConnection(DAO.ConnString))
                {
                    //Abra a conexão com o PgSQL
                    DAO.PgsqlConnection.Open();

                    string inserirVendaCMD = string.Format("select * from inserir_venda('{0}','{1}','{2}','{3}')",
                                                           billItem.Sale.Customer.CPF, billItem.Sale.Date,
                                                           billItem.Sale.TotalMoney.ToString("N", CultureInfo.CreateSpecificCulture("en-US")),
                                                           billItem.Sale.TotalCard.ToString("N", CultureInfo.CreateSpecificCulture("en-US")));

                    using (NpgsqlDataAdapter Adpt = new NpgsqlDataAdapter(inserirVendaCMD, DAO.PgsqlConnection))
                    {
                        Adpt.Fill(dt);
                    }

                    if (dt.Rows.Count > 0)
                    {
                        billItem.Sale.ID = dt.Rows[0]["inserir_venda"].ToString(); // Captura ID da venda
                        for (int i = 0; i < billItem.Sale.SaleItem_.Count; i++)
                        {
                            billItem.Sale.SaleItem_[i].VendaID = billItem.Sale.ID;
                        }

                        SalelItemDAO.MultiInsertAuto(billItem.Sale.SaleItem_);

                        string inserirItemContaCMD = string.Format("select * from inserir_item_conta('{0}','{1}','{2}')",
                                                                   billItem.Sale.ID, billItem.Sale.Customer.CPF,
                                                                   billItem.Total.ToString("N", CultureInfo.CreateSpecificCulture("en-US")));

                        return(GenericDAO.genericBool(inserirItemContaCMD));
                    }
                }
            }
            catch (NpgsqlException ex)
            {
                MessageBox.Show("Erro: " + ex.Message + ".\nPor Favor contate o suporte.", "Erro de Banco de Dados",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro: " + ex.Message + ".\nPor Favor contate o suporte.", "Erro de Sofware",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            finally
            {
                DAO.PgsqlConnection.Close();
            }

            return(false);
        }