Example #1
0
        private void RemoveRecibo(Recibo R)
        {
            //used to add a new recibo to the database
            if (!verifyBDConnection())
            {
                return;
            }
            SqlCommand cmd = new SqlCommand("removeRecibo", cn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@rID", SqlDbType.Int).Value = R.reciboID;

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to update recibo in database. \n ERROR MESSAGE: \n" + ex.Message);
            }
            finally
            {
                listBoxProdutosRecibo.Items.Clear();
                cn.Close();
            }
        }
Example #2
0
        private void reciboSearch()
        {
            if (!verifyBDConnection())
            {
                return;
            }

            using (SqlCommand cmd = new SqlCommand("searchRecibo", cn))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@reciboID", reciboSearchID);
                SqlDataReader reader = cmd.ExecuteReader();
                listBoxRecibos.Items.Clear();
                while (reader.Read())
                {
                    Recibo R = new Recibo();
                    R.reciboID    = int.Parse(reader["reciboID"].ToString());
                    R.ClienteNIF  = int.Parse(reader["ClienteNIF"].ToString());
                    R.EmpNIF      = int.Parse(reader["EmpNIF"].ToString());
                    R.data_recibo = DateTime.Parse(reader["data_recibo"].ToString());
                    R.valor       = float.Parse(reader["valor"].ToString());
                    listBoxRecibos.Items.Add(R);
                }
                reader.Close();
            }
        }
Example #3
0
        private void SubmitRecibo(Recibo R)
        {
            //used to add a new recibo to the database
            if (!verifyBDConnection())
            {
                return;
            }
            SqlCommand cmd = new SqlCommand("insertRecibo", cn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@valor", SqlDbType.Float).Value      = R.valor;
            cmd.Parameters.Add("@ClienteNIF", SqlDbType.Int).Value   = R.ClienteNIF;
            cmd.Parameters.Add("@EmpNIF", SqlDbType.Int).Value       = R.EmpNIF;
            cmd.Parameters.Add("@data_recibo", SqlDbType.Date).Value = R.data_recibo;

            try
            {
                cmd.ExecuteNonQuery();

                cmd = new SqlCommand("getLastReciboID", cn);

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@lastID", System.Data.SqlDbType.Int).Direction = System.Data.ParameterDirection.ReturnValue;
                cmd.ExecuteNonQuery();
                R.reciboID = (int)cmd.Parameters["@lastID"].Value;

                cmd = new SqlCommand("insertCompra", cn);

                cmd.CommandType = CommandType.StoredProcedure;

                foreach (Produto prod in reciboProds)
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("@reciboID", R.reciboID);
                    cmd.Parameters.AddWithValue("@produtoID", prod.ID);
                    cmd.ExecuteNonQuery();
                }

                foreach (Produto prod in reciboProds)
                {
                    cmd             = new SqlCommand("getProdutoQ", cn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Produto_ID", prod.ID);
                    cmd.Parameters.AddWithValue("@recibo_ID", R.reciboID);
                    cmd.Parameters.Add("@prodQ", System.Data.SqlDbType.Int).Direction = System.Data.ParameterDirection.ReturnValue;
                    cmd.ExecuteNonQuery();
                    prod.quantidade = (int)cmd.Parameters["@prodQ"].Value;
                }
                reciboProds.Clear();
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to update recibo in database. \n ERROR MESSAGE: \n" + ex.Message);
            }
            finally
            {
                cn.Close();
            }
        }
Example #4
0
        public void ShowProdsInRecibo()
        {
            if (!verifyBDConnection())
            {
                return;
            }

            Recibo recibo = new Recibo();

            recibo = (Recibo)listBoxRecibos.Items[currentRecibo];

            using (SqlCommand cmd = new SqlCommand("getProdutosInRecibo", cn))
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@reciboID", recibo.reciboID);

                SqlDataReader reader = cmd.ExecuteReader();
                listBoxProdutosRecibo.Items.Clear();
                while (reader.Read())
                {
                    Produto P = new Produto();
                    P.ID         = int.Parse(reader["ID_P"].ToString());
                    P.preco      = float.Parse(reader["precoP"].ToString());
                    P.tipo       = int.Parse(reader["tipoP"].ToString());
                    P.nome       = reader["nomeP"].ToString();
                    P.quantidade = int.Parse(reader["quantidade"].ToString());
                    listBoxProdutosRecibo.Items.Add(P);
                }
                reader.Close();
            }
        }
Example #5
0
        public void ShowRecibo()
        {   //shows information of Recibo
            if (listBoxRecibos.Items.Count == 0 | currentRecibo < 0)
            {
                return;
            }
            Recibo recibo = new Recibo();

            recibo = (Recibo)listBoxRecibos.Items[currentRecibo];

            textBoxClienteNIF.Text = recibo.ClienteNIF.ToString();
            textBoxEmpNIF.Text     = recibo.EmpNIF.ToString();
            textBoxValor.Text      = recibo.valor.ToString();
            dateTimePicker1.Value  = recibo.data_recibo;
            //used to show the information of the Recibo in the corresponding boxes
        }
Example #6
0
        private bool SaveRecibo()
        {
            Recibo R = new Recibo();

            if (adding)
            {
                try
                {
                    R.ClienteNIF  = int.Parse(textBoxClienteNIF.Text);
                    R.EmpNIF      = int.Parse(textBoxEmpNIF.Text);
                    R.data_recibo = dateTimePicker1.Value.Date;
                    R.valor       = float.Parse(textBoxValor.Text);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return(false);
                }

                SubmitRecibo(R);
                listBoxRecibos.Items.Add(R);
                adding = false;
            }
            if (removing)
            {
                try
                {
                    R = (Recibo)listBoxRecibos.Items[currentRecibo];
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return(false);
                }
                RemoveRecibo(R);
                listBoxRecibos.Items.Remove(R);
                removing = false;
            }
            return(true);
        }
Example #7
0
        private void loadRecibos()
        {   //loads all Recibos from the DB
            if (!verifyBDConnection())
            {
                return;
            }


            using (SqlCommand cmd = new SqlCommand("SELECT * FROM Cafes.Recibo", cn)){;
                                                                                      SqlDataReader reader = cmd.ExecuteReader();
                                                                                      listBoxRecibos.Items.Clear();

                                                                                      while (reader.Read())
                                                                                      {
                                                                                          Recibo R = new Recibo();
                                                                                          R.reciboID    = int.Parse(reader["reciboID"].ToString());
                                                                                          R.ClienteNIF  = int.Parse(reader["ClienteNIF"].ToString());
                                                                                          R.EmpNIF      = int.Parse(reader["EmpNIF"].ToString());
                                                                                          R.data_recibo = DateTime.Parse(reader["data_recibo"].ToString());
                                                                                          R.valor       = float.Parse(reader["valor"].ToString());
                                                                                          listBoxRecibos.Items.Add(R);
                                                                                      }
                                                                                      reader.Close(); }
            cn.Close();
            currentRecibo = 0;
        }