Example #1
0
        public List<Cliente> buscar(String nome)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT * FROM Clientes where Nome LIKE '%" + nome + "%'";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            List<Cliente> listaClientes = new List<Cliente>();

            while (reader.Read())
            {
                Cliente cliente = new Cliente();
                cliente.id_cliente = Int32.Parse(string.Format("{0}", reader[0]));
                cliente.nome = string.Format("{0}", reader[1]);
                cliente.cpf = string.Format("{0}", reader[2]);
                cliente.saldo = double.Parse(string.Format("{0}", reader[3]));

                listaClientes.Add(cliente);
            }

            con.closeConnection();
            return listaClientes;
        }
Example #2
0
        public List<Carro> buscar(String nome)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT * FROM Carro where modelo LIKE '%" + nome + "%' OR marca LIKE '%" + nome + "%'";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            List<Carro> listaCarros = new List<Carro>();

            while (reader.Read())
            {
                Carro carro = new Carro();
                carro.id_carro = Int32.Parse(string.Format("{0}", reader[0]));
                carro.modelo = string.Format("{0}", reader[1]);
                carro.marca = string.Format("{0}", reader[2]);
                carro.cor = string.Format("{0}", reader[3]);

                listaCarros.Add(carro);
            }

            con.closeConnection();
            return listaCarros;
        }
Example #3
0
        public List<Mensalista> buscar(String nomeCliente)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT * FROM Mensalistas m INNER JOIN Clientes c ON m.Id_cliente = c.Id_Cliente WHERE c.Nome like '%"+ nomeCliente +"%'";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            List<Mensalista> listaMensalistas = new List<Mensalista>();

            while (reader.Read())
            {
                Mensalista mensalista = new Mensalista();
                mensalista.id_mensalista = Int32.Parse(string.Format("{0}", reader[0]));
                mensalista.id_cliente = Int32.Parse(string.Format("{0}", reader[1]));

                Cliente cliente = new Cliente();
                cliente.nome = string.Format("{0}", reader[4]);

                mensalista.nome_cliente = cliente.nome;
                mensalista.data_termino = string.Format("{0}", reader[2]);

                listaMensalistas.Add(mensalista);
            }
            con.closeConnection();
            return listaMensalistas;
        }
Example #4
0
 public Boolean editar(Ticket ticket, Carro carro, Cliente cliente, Servicos servico)
 {
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     String sql = "UPDATE Tickets SET Id_cliente = " + cliente.id_cliente + ", id_Carro = " + carro.id_carro + ", Id_Servico = " + servico.id_servico + ", DataEntrada = '" + ticket.data_entrada + "', DataSaida = '" + ticket.data_saida + "', ValorTotal = " + ticket.valorTotal + ", Placa = '" + ticket.placa + "', UF = '" + ticket.uf + "', Cidade = '" + ticket.cidade + "'";
     command.CommandText = sql;
     command.CommandType = CommandType.Text;
     command.Connection = con.getConnection();
     command.ExecuteNonQuery();
     con.closeConnection();
     return true;
 }
Example #5
0
 public Boolean editar(Carro carro)
 {
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     String sql = "UPDATE Carro set marca='" + carro.marca + "', modelo ='" + carro.modelo + "',  cor = '" + carro.cor + "' where ID_carro = " + carro.id_carro;
     command.CommandText = sql;
     command.CommandType = CommandType.Text;
     command.Connection = con.getConnection();
     command.ExecuteNonQuery();
     con.closeConnection();
     return true;
 }
Example #6
0
 public Boolean editar(Mensalista mensalista)
 {
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     String sql = "UPDATE Mensalistas set Data_termino ='" + mensalista.data_termino +"' where Id_Mensalista = "+mensalista.id_mensalista;
     command.CommandText = sql;
     command.CommandType = CommandType.Text;
     command.Connection = con.getConnection();
     command.ExecuteNonQuery();
     con.closeConnection();
     return true;
 }
Example #7
0
        public Boolean deletar(Mensalista mensalista)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "DELETE Mensalistas WHERE Id_Mensalista = " + mensalista.id_mensalista;
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            con.closeConnection();

            return true;
        }
Example #8
0
        public Boolean deletar(Ticket ticket)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "DELETE Tickets WHERE ID_ticket = " + ticket.id_ticket;
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            con.closeConnection();

            return true;
        }
Example #9
0
        public Boolean deletar(Carro carro)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "DELETE Carro WHERE ID_carro = " + carro.id_carro;
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            con.closeConnection();

            return true;
        }
Example #10
0
        public List<Ticket> buscar(String placa)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT * FROM Tickets WHERE placa LIKE '%" + placa + "%' ORDER BY DataEntrada";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            List<Ticket> listaTickets = new List<Ticket>();

            while (reader.Read())
            {
                Ticket ticket = new Ticket();

                //Ticket
                ticket.id_ticket = int.Parse(string.Format("{0}", reader[0]));

                //Cliente
                ticket.id_cliente = int.Parse(string.Format("{0}", reader[1]));
                //Carro
                ticket.id_carro = Convert.ToInt32(string.Format("{0}", reader["id_Carro"]));
                //Servico
                ticket.id_servico = int.Parse(string.Format("{0}", reader["Id_Servico"]));
                //Ticket
                ticket.data_entrada = Convert.ToDateTime(reader["DataEntrada"]).ToString("dd/MM/yyyy HH:mm");
                ticket.data_saida = Convert.ToDateTime(reader["DataSaida"]).ToString("dd/MM/yyyy HH:mm");
                ticket.valorTotal = Convert.ToDouble(string.Format("{0}", reader[6]));

                //Placa carro
                ticket.placa = string.Format("{0}", reader[7]);
                ticket.uf = string.Format("{0}", reader[8]);
                ticket.cidade = string.Format("{0}", reader[9]);

                listaTickets.Add(ticket);
            }

            con.closeConnection();
            return listaTickets;
        }
Example #11
0
    public void UpdateFaildLoginAttempsDL(string LoginId, int newFailedAttempts)
    {
        DataTable dt = new DataTable();

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "UPDATE [P_UsersMaster] SET failed_login_attempts=@AttemptsCount WHERE LoginID=@LoginID";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@LoginId", DbType = DbType.String, Size = 50, Value = LoginId
                    });
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@AttemptsCount", DbType = DbType.Int32, Value = newFailedAttempts
                    });
                    cmd.ExecuteNonQuery();
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                cmd.Dispose();
                sCon = null;
            }
        }
    }
        /// <summary>
        /// Actualiza un pedido
        /// </summary>
        /// <param name="pedido">El pedido a actualizar</param>
        /// <returns>true si se ha actualizado correctamente, false en caso contrario</returns>
        public static bool actualizarPedido(Pedido pedido)
        {
            Connection    conexion      = new Connection();
            SqlConnection sqlConnection = new SqlConnection();
            SqlCommand    command       = null;

            try
            {
                //Obtener conexion
                sqlConnection = conexion.getConnection();

                command             = new SqlCommand("pr_actualizarPedido", sqlConnection);
                command.CommandType = CommandType.StoredProcedure;

                //Definicion de los parametros del comando
                command.Parameters.AddWithValue("@Id_Pedido", pedido.id);
                command.Parameters.AddWithValue("@Id_Cliente", pedido.idCliente);
                command.Parameters.AddWithValue("@UserName_Vendedor", pedido.nombreVendedor);
                command.Parameters.AddWithValue("@Fecha_Pedido", pedido.fechaPedido);
                command.Parameters.AddWithValue("@Fecha_Entrega", pedido.fechaEntrega);
                command.Parameters.AddWithValue("@Total_Pedido", pedido.totalPedido);

                SqlParameter exitoOutput = new SqlParameter("@exito", SqlDbType.Bit);
                exitoOutput.Direction = ParameterDirection.Output;
                command.Parameters.Add(exitoOutput);

                //Ejecutar la consulta
                command.ExecuteNonQuery();
            }
            catch (SqlException ex) { throw ex; }
            finally
            {
                //Cerramos el lector y la conexion
                conexion.closeConnection(ref sqlConnection);
            }

            return((bool)command.Parameters["@exito"].Value);
        }
Example #13
0
        public bool UpdateProfile(Employee emp)
        {
            SqlConnection con = Connection.getConnection();
            SqlCommand    cmd = null;

            bool success = false;

            try
            {
                con.Open();
                cmd = new SqlCommand("UPDATE Employee SET lastName = @ln, firstName = @fn, gender = @g, birthDate = @bd, username = @un, password = @pw, roleID = @roleID, status = @s, photo = @pho WHERE empID = @empID", con);
                cmd.Parameters.AddWithValue("@ln", emp.LastName);
                cmd.Parameters.AddWithValue("@fn", emp.FirstName);
                cmd.Parameters.AddWithValue("@g", emp.Gender);
                cmd.Parameters.AddWithValue("@bd", emp.BirthDate);
                cmd.Parameters.AddWithValue("@un", emp.UserName);
                cmd.Parameters.AddWithValue("@pw", emp.Password);
                cmd.Parameters.AddWithValue("@roleID", emp.Roles.ID);
                cmd.Parameters.AddWithValue("@s", emp.Status);
                cmd.Parameters.AddWithValue("@pho", emp.Photo);
                cmd.Parameters.AddWithValue("@empID", emp.ID);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    success = true;
                }
            }
            catch (Exception e)
            {
                success = false;
                MessageError(e.Message, "Error Update Profile");
            }
            finally
            {
                cmd.Dispose();
                con.Close();
            }
            return(success);
        }
Example #14
0
    public DataSet getMenuItemsForRecipe()
    {
        MySqlConnection  con = null;
        MySqlDataAdapter da;
        DataSet          ds;

        try
        {
            string[]     strSQL  = XMLWrapper.getSQLString("getMenuItemsForRecipe");
            MySqlCommand command = new MySqlCommand(strSQL[0]);
            con = Connection.getConnection();
            command.Connection = con;
            da = new MySqlDataAdapter(command);
            ds = new DataSet();
            da.Fill(ds);
            return(ds);
        }

        finally
        {
            Connection.closeConnection(con);
        }
    }
Example #15
0
        private string calcularIdPlan(string descripcion)
        {
            String unaQuery = "SELECT pla_codigo Codigo FROM PICO_Y_PALA.planes WHERE pla_desc = '" + descripcion + "'";
            string codPlan  = "";

            using (SqlConnection cx1 = Connection.getConnection())
            {
                try
                {
                    SqlCommand sqlCmd = new SqlCommand(unaQuery, cx1);
                    cx1.Open();
                    SqlDataReader sqlReader = sqlCmd.ExecuteReader();
                    sqlReader.Read();
                    codPlan = sqlReader["Codigo"].ToString();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(codPlan);
        }
        private ICollection <Sistema> listarTodos()
        {
            ICollection <Sistema> listSistemas = new List <Sistema>();
            Sistema       sistema;
            SqlConnection con = Connection.getConnection();
            SqlCommand    cmd = new SqlCommand("sp_sistema_sel", con);

            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                sistema           = new Sistema();
                sistema.Codigo    = Convert.ToInt32(reader["idSistema"]);
                sistema.Nome      = reader["nome"].ToString();
                sistema.Descricao = reader["descricao"].ToString();

                listSistemas.Add(sistema);
            }
            reader.Close();

            return(listSistemas);
        }
        private void loadListView()
        {
            SqlConnection Conn  = Connection.getConnection();
            String        query = "SELECT DD.PartNo, DD.Qty, DD.SellPrice FROM Debt D INNER JOIN DebtDetails DD ON DD.DebtId = D.DebtId WHERE D.DebtId = @DebtId";

            using (Conn)
            {
                SqlCommand cmd = new SqlCommand(query, Conn);
                cmd.CommandType = CommandType.Text;

                cmd.Parameters.AddWithValue("@DebtId", DebtId);

                Conn.Open();
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                    ListViewItem Item = new ListViewItem(sdr[0].ToString());
                    Item.SubItems.Add(sdr[2].ToString());
                    Item.SubItems.Add(sdr[1].ToString());
                    listView1.Items.AddRange(new ListViewItem[] { Item });
                }
            }
        }
        private int calcularFilasTotal()
        {
            String unaQuery = sqlCount.ToString();
            int    numeroAfi;

            using (SqlConnection cx1 = Connection.getConnection())
            {
                try
                {
                    SqlCommand sqlCmd = new SqlCommand(unaQuery, cx1);
                    cx1.Open();
                    SqlDataReader sqlReader = sqlCmd.ExecuteReader();
                    sqlReader.Read();
                    numeroAfi = Int32.Parse(sqlReader["Total"].ToString());
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

            return(numeroAfi);
        }
        private void registrarResultadoSinDiagnostico()
        {
            SqlConnection cx = null;

            try
            {
                cx = Connection.getConnection();
                cx.Open();
                SqlCommand sqlCmd = new SqlCommand("PICO_Y_PALA.registarResultadoSinDiagnostico", cx);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@consultaID", SqlDbType.Int).Value = Int32.Parse(this.dgv_ConsultasProfesional.SelectedRows[0].Cells[0].Value.ToString());
                sqlCmd.ExecuteNonQuery();
                sqlCmd.Dispose();
                MessageBox.Show("Se ha generado la consulta y registrado la llegada correctamente!");
                cx.Close();
            }
            catch (Exception exception)
            {
                cx.Close();
                MessageBox.Show(exception.Message);
                return;
            }
        }
Example #20
0
        /// <summary>
        /// Actualiza una linea de pedido
        /// </summary>
        /// <param name="linea">La línea de pedido a actualizar</param>
        /// <returns>true si se ha actualizado correctamente, false en caso contrario</returns>
        public static bool actualizarLineaPedidoDePedidoPorIdDeProducto(LineaPedido linea)
        {
            SqlConnection miConexion   = new SqlConnection();
            SqlCommand    command      = null;
            Connection    gestConexion = new Connection();

            try
            {
                miConexion = gestConexion.getConnection();

                command             = new SqlCommand("pr_actualizarLineaPedido", miConexion);
                command.CommandType = CommandType.StoredProcedure;

                command.Parameters.AddWithValue("@Id_Pedido", linea.idPedido);
                command.Parameters.AddWithValue("@Id_Producto ", linea.idProducto);
                command.Parameters.AddWithValue("@Precio_Unitario", linea.precioUnitario);
                command.Parameters.AddWithValue("@Cantidad", linea.cantidad);
                command.Parameters.AddWithValue("@Impuestos", linea.impuestos);
                command.Parameters.AddWithValue("@SubtotaL", linea.subtotal);

                SqlParameter exitoOutput = new SqlParameter("@exito", SqlDbType.Bit);
                exitoOutput.Direction = ParameterDirection.Output;
                command.Parameters.Add(exitoOutput);

                command.ExecuteNonQuery();
            }
            catch (SqlException exSql)
            {
                throw exSql;
            }
            finally
            {
                gestConexion.closeConnection(ref miConexion);
            }

            return((bool)command.Parameters["@exito"].Value);
        }
Example #21
0
    public DataTable GetReceivedtDL(string MinId)
    {
        DataTable dt = new DataTable();

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "Usp_GetRecivedPpr";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@MinId", DbType = DbType.String, Value = MinId
                    });
                    //cmd.Parameters.Add(new SqlParameter { ParameterName = "@UserId", DbType = DbType.String, Value = "" });
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        da.Fill(dt);
                    }
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            cmd.Dispose();
            sCon = null;
        }
        return(dt);
    }
Example #22
0
    public bool UpdateLoginDateTimeDL(string LoginId)
    {
        DataTable dt     = new DataTable();
        int       result = 0;

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "UPDATE [P_UsersMaster] SET Date_last_login=GETDATE() WHERE LoginId=@LoginId";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@LoginId", DbType = DbType.String, Size = 50, Value = LoginId
                    });
                    result = cmd.ExecuteNonQuery();
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                cmd.Dispose();
                sCon = null;
            }
        }
        return(result > 0);
    }
Example #23
0
        private bool RestoreEmployee(int id)
        {
            SqlCommand    cmd     = null;
            SqlConnection con     = Connection.getConnection();
            bool          success = false;

            try
            {
                con.Open();
                cmd = new SqlCommand("UPDATE Employee SET deletedDate = @dDate, status = @stu WHERE empID = @id", con);
                cmd.Parameters.AddWithValue("@dDate", DateTime.Now);
                cmd.Parameters.AddWithValue("@stu", true);
                cmd.Parameters.AddWithValue("@id", id);
                if (cmd.ExecuteNonQuery() > 0)
                {
                    success = true;
                }
            }
            catch (Exception e)
            {
                MessageError(e.Message, "Error Delete");
                success = false;
            }
            finally
            {
                try
                {
                    cmd.Dispose();
                    con.Close();
                }
                catch (NullReferenceException ex)
                {
                    MessageError(ex.Message, "Restore");
                }
            }
            return(success);
        }
    public DataTable GetAgencyWiseEmailDL(string AgencyId)
    {
        DataTable dt = new DataTable();

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "Sp_SelectAgencyWiseEmailId";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@AgencyId", DbType = DbType.String, Value = AgencyId
                    });
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        da.Fill(dt);
                    }
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            cmd.Dispose();
            sCon = null;
        }
        return(dt);
    }
Example #25
0
        public Carro getCarrobyId(Carro carro)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT * FROM Carro where ID_carro =" + carro.id_carro;
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();
            Carro returnCarro = new Carro();
            while (reader.Read())
            {
                returnCarro.id_carro = Int32.Parse(string.Format("{0}", reader[0]));
                returnCarro.modelo = string.Format("{0}", reader[1]);
                returnCarro.marca = string.Format("{0}", reader[2]);
                returnCarro.cor = string.Format("{0}", reader[3]);

                return returnCarro;
            }
            con.closeConnection();
            return returnCarro;
        }
Example #26
0
    public int SendMdbMappingDL(string UserId, string Mdbid)
    {
        int success = 0;

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "Sp_InsertMdbMapping";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@UserId", DbType = DbType.String, Value = UserId
                    });
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@Mdbid", DbType = DbType.String, Value = Mdbid
                    });
                    success = cmd.ExecuteNonQuery();
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            cmd.Dispose();
            sCon = null;
        }
        return(success);
    }
Example #27
0
    public int ImportPprDataDL(string PprId, string UserID)
    {
        int success = 0;

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SpImportPprData";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@PprId", DbType = DbType.String, Value = PprId
                    });
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@UserID", DbType = DbType.String, Value = UserID
                    });
                    success = int.Parse(cmd.ExecuteScalar().ToString());
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            cmd.Dispose();
            sCon = null;
        }
        return(success);
    }
Example #28
0
    public int SendMappedMemoireDataDL(string AidMemId, string McId)
    {
        int success = 0;

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "Sp_AddMappedMemoireData";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@AidMemId", DbType = DbType.String, Value = AidMemId
                    });
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@McId", DbType = DbType.String, Value = McId
                    });
                    success = cmd.ExecuteNonQuery();
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            cmd.Dispose();
            sCon = null;
        }
        return(success);
    }
Example #29
0
        /// <summary>
        /// Metodo que borra una linea de pedido dadas sus ID del pedido y su ID del producto
        /// </summary>
        /// <param name="idPedido">ID del pedido</param>
        /// <param name="idProducto">ID del producto</param>
        /// <returns>true si se ha borrado correctamente, false en caso contrario</returns>
        public static bool borrarLineaPedidoDePedidoPorIdProducto(int idPedido, int idProducto)
        {
            Connection    miconexion    = new Connection();
            SqlConnection sqlconnection = null;
            SqlCommand    sqlCommand;

            try
            {
                //Obtener conexion abierta
                sqlconnection = miconexion.getConnection();

                //Definimos los parametros del comando
                sqlCommand             = new SqlCommand("pr_borrarLineaDePedido", sqlconnection);
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Parameters.Add("@Id_Pedido", SqlDbType.Int).Value   = idPedido;
                sqlCommand.Parameters.Add("@ID_Producto", SqlDbType.Int).Value = idPedido;

                SqlParameter exitoOutput = new SqlParameter("@exito", SqlDbType.Bit);
                exitoOutput.Direction = ParameterDirection.Output;
                sqlCommand.Parameters.Add(exitoOutput);


                //Definir la conexion
                sqlCommand.Connection = sqlconnection;

                //Ejecutar la sentencia. Si hay filas afectadas, se devuelve true y viceversa
                sqlCommand.ExecuteNonQuery();
            }
            catch (SqlException ex) { throw ex; }
            finally
            {
                miconexion.closeConnection(ref sqlconnection);
            }

            return((bool)sqlCommand.Parameters["@exito"].Value);
        }
Example #30
0
        private List <Especialidad> obtenerEspecialidadesProfesional(int nroDoc, String query)
        {
            using (SqlConnection cx = Connection.getConnection())
            {
                try
                {
                    SqlCommand sqlCmd = new SqlCommand(query, cx);
                    cx.Open();
                    SqlDataReader       sqlReader           = sqlCmd.ExecuteReader();
                    List <Especialidad> especialidadesLocal = new List <Especialidad>();

                    while (sqlReader.Read())
                    {
                        especialidadesLocal.Add(new Especialidad(int.Parse(sqlReader["ID"].ToString()), sqlReader["Especialidad"].ToString()));
                    }

                    return(especialidadesLocal);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Example #31
0
 private void insertarTurno(int nroDocAfi, int nroDocProf, int espId, DateTime fechaHoraTurno)
 {
     using (SqlConnection cx = Connection.getConnection())
     {
         try
         {
             cx.Open();
             SqlCommand sqlCmd = new SqlCommand("PICO_Y_PALA.darTurno", cx);
             sqlCmd.CommandType = CommandType.StoredProcedure;
             sqlCmd.Parameters.Add("@nroDocAfi", SqlDbType.Decimal).Value       = nroDocAfi;
             sqlCmd.Parameters.Add("@nroDocProf", SqlDbType.Decimal).Value      = nroDocProf;
             sqlCmd.Parameters.Add("@espId", SqlDbType.Int).Value               = espId;
             sqlCmd.Parameters.Add("@fechaHoraTurno", SqlDbType.DateTime).Value = fechaHoraTurno;
             sqlCmd.ExecuteNonQuery();
             sqlCmd.Dispose();
         }
         catch (Exception ex)
         {
             Console.WriteLine("ERROR AL INSERTAR EL TURNO");
             Console.WriteLine(ex);
             MessageBox.Show("Se produjo un error al insertar el turno", "Error al registrar el turno", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Example #32
0
    public DataTable getOldPPRdetailsDL(string pprid)
    {
        DataTable dt = new DataTable();

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "USP_GetOLDPPRDetails";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@PPRId", DbType = DbType.Int32, Value = pprid
                    });
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        da.Fill(dt);
                    }
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            cmd.Dispose();
            sCon = null;
        }
        return(dt);
    }
Example #33
0
    public int ResetUserAccountDL(string Action, string UserId)
    {
        int success = 0;

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "Usp_GetUserResetAccountDetails";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@Action", DbType = DbType.String, Value = Action
                    });
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@UserId", DbType = DbType.String, Value = UserId
                    });
                    success = cmd.ExecuteNonQuery();
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            cmd.Dispose();
            sCon = null;
        }
        return(success);
    }
 public string getIdOfUser()
 {
     try
     {
         String          qry             = "select ifnull(max(_id),10000) _id from create_user";
         Connection      connection      = new Connection();
         MySqlConnection mySqlConnection = connection.getConnection();
         MySqlDataReader mySqlDataReader = connection.selectDataQuery(qry);
         if (mySqlDataReader.Read())
         {
             int val = Int32.Parse(mySqlDataReader.GetString(0));
             val++;
             return(val.ToString());
         }
         else
         {
             return(Utility.Constants.emptyString);
         }
     }
     catch (Exception)
     {
         return(Utility.Constants.emptyString);
     }
 }
Example #35
0
    public DataTable GetNodalIDDL(string ministryid)
    {
        DataTable dt = new DataTable();

        try
        {
            sCon = new Connection();
            con  = new SqlConnection();
            cmd  = new SqlCommand();
            using (con = sCon.getConnection())
            {
                using (cmd = con.CreateCommand())
                {
                    cmd.CommandText = "usp_GetNodalID";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter {
                        ParameterName = "@ministryid", DbType = DbType.String, Value = ministryid
                    });
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        da.Fill(dt);
                    }
                }
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        finally
        {
            cmd.Dispose();
            sCon = null;
        }
        return(dt);
    }
Example #36
0
        public static int getMaxIdOrder(DateTime systemTime)
        {
            String strQuery = "SELECT MAX(RIGHT(ID, 4))"
                              + " FROM DON_DAT_HANG "
                              + " WHERE SUBSTRING(ID, 3, 2) = @mm "
                              + " AND SUBSTRING(ID, 5, 2) = @yy ";
            SqlCommand cmd = new SqlCommand(strQuery);

            cmd.CommandType = CommandType.Text;
            cmd.Connection  = Connection.getConnection();
            cmd.Parameters.AddWithValue("@mm", systemTime.ToString("MM"));
            cmd.Parameters.AddWithValue("@yy", systemTime.ToString("yy"));
            SqlDataReader reader = cmd.ExecuteReader();

            reader.Read();
            int numOrderInMonth = 0;

            if (!reader.IsDBNull(0))
            {
                numOrderInMonth = int.Parse(reader.GetString(0));
            }
            reader.Close();
            return(numOrderInMonth);
        }
Example #37
0
        public SqlDataReader getDebtByCustomer(String dateFrom, String dateTo, String idKhachHang = "")
        {
            String strQuery = "SELECT a.ID"
                              + ", a.NGAY_GIAO"
                              + ", sp.TEN_SAN_PHAM"
                              + ", ISNULL(sp.CD_CR, '') AS CD_CR"
                              + ", ISNULL(sp.KICH_THUOC, '') AS KICH_THUOC"
                              + ", ISNULL(sp.SO_TRANG, 0) AS SO_TRANG"
                              + ", ISNULL(sp.LOAI_BIA, '') AS LOAI_BIA"
                              + ", ISNULL(sp.LOAI_GIAY, '') AS LOAI_GIAY"
                              + ", ISNULL(sp.SO_LUONG, 0) AS SO_LUONG"
                              + ", ISNULL(sp.DON_GIA, 0) AS DON_GIA"
                              + ", ISNULL(sp.CHIET_KHAU, 1) AS CHIET_KHAU"
                              + ", ISNULL(sp.THANH_TIEN, 0) AS THANH_TIEN"
                              + ", ISNULL(a.VAT, 0) AS VAT"
                              + ", sp.THANH_TIEN + sp.THANH_TIEN * ISNULL(a.VAT, 0)/100 AS TONG_TIEN"
                              + " FROM DON_DAT_HANG a"
                              + " LEFT JOIN DON_DAT_HANG_SP sp"
                              + " ON a.ID = sp.ID_DON_DAT_HANG"
                              + " WHERE a.NGAY_DAT >= '" + dateFrom + "' AND a.NGAY_DAT <= '" + dateTo + "'";

            if (StringUtils.isNotBlank(idKhachHang))
            {
                strQuery += " AND a.ID_KHACH_HANG = '" + idKhachHang + "'";
                //+ "     AND a.TRANG_THAI_THANH_TOAN = 'false'"
            }

            strQuery += " ORDER BY NGAY_GIAO DESC";
            SqlCommand cmd = new SqlCommand(strQuery);

            cmd.CommandType = CommandType.Text;
            cmd.Connection  = Connection.getConnection();
            SqlDataReader reader = cmd.ExecuteReader();

            return(reader);
        }
Example #38
0
        public List<Cliente> buscarTicket(Boolean mensalista,String busca)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "";
            if (mensalista == true)
            {
               sql = "SELECT C.Id_Cliente,C.Nome,C.Cpf,C.Saldo FROM Ticketcar.dbo.Clientes AS C LEFT JOIN Ticketcar.dbo.Mensalistas AS M ON C.Id_Cliente = M.Id_cliente WHERE M.Id_cliente IS NOT NULL AND DAY(M.Data_termino) = DAY(GETDATE()) AND C.Nome LIKE '%" + busca + "%'";
            }
            else
            {
                sql = "SELECT  C.Id_Cliente,C.Nome,C.Cpf,C.Saldo FROM Ticketcar.dbo.Clientes AS C LEFT JOIN Ticketcar.dbo.Mensalistas AS M ON C.Id_Cliente = M.Id_cliente WHERE M.Id_cliente IS NULL  AND C.Nome LIKE '%" + busca+"%'";
            }
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            List<Cliente> listaClientes = new List<Cliente>();

            while (reader.Read())
            {
                Cliente cliente = new Cliente();
                cliente.id_cliente = Int32.Parse(string.Format("{0}", reader[0]));
                cliente.nome = string.Format("{0}", reader[1]);
                cliente.cpf = string.Format("{0}", reader[2]);
                cliente.saldo = double.Parse(string.Format("{0}", reader[3]));

                listaClientes.Add(cliente);
            }

            con.closeConnection();
            return listaClientes;
        }
Example #39
0
    public int GetAlunoId(Aluno umAluno)
    {
        MySqlConnection db = Connection.getConnection();

        try
        {
            MySqlCommand mySQLcmd = db.CreateCommand();
            mySQLcmd.CommandType = CommandType.Text;
            mySQLcmd.CommandText = string.Format("Select * from aluno where usuario = '{0}' and senha = MD5('{1}') and ativo;",
                                                 umAluno.GetUsuario(), umAluno.GetSenha());

            //execução sem retorno
            MySqlDataReader rsAluno = mySQLcmd.ExecuteReader();

            if (rsAluno.HasRows)
            {
                while (rsAluno.Read())
                {
                    return(rsAluno.GetInt32("id"));
                }
            }
        }
        catch (MySqlException ex)
        {
            throw new ExcecaoSAG("Erro ao carregar um usuário. Código " + ex.ToString());
        }
        catch (ExcecaoSAG ex)
        {
            throw ex;
        }
        finally
        {
            db.Close();
        }
        return(0);
    }
        public void update_a_message()
        {
            //Create message

            Connection one = new Connection();

            MessageRepo repo = new MessageRepo(new Connection(), new ReactionRepo(new Connection()));

            MessageModel message = new MessageModel();

            message.message  = "testmessage";
            message.subject  = "subject";
            message.forum    = "1";
            message.software = "1";

            int id = repo.store(message, 1);

            message.id = id;

            //Give message a new name

            message.message = "new name!";
            repo.update(message);

            one.Connect();
            SqlCommand    sqlCommand = new SqlCommand("select * from message where message = 'new name!'", one.getConnection());
            SqlDataReader reader     = sqlCommand.ExecuteReader();

            Assert.AreEqual(true, reader.HasRows);
            one.disConnect();

            repo.destroy(id);
        }
Example #41
0
        public Boolean inserir(Carro carro)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            string sql = "INSERT INTO Carro (marca,modelo,cor) VALUES('" + carro.marca + "','" + carro.modelo + "','" + carro.cor + "')";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            command.ExecuteNonQuery();

            con.closeConnection();

            return true;
        }
Example #42
0
        public Mensalista getMensalistabyId_cliente(int id_cliente)
        {
            Mensalista returnMensalista = null;

            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "select * from Mensalistas m inner join Clientes c on m.Id_cliente = c.Id_Cliente where m.Id_cliente = " + id_cliente + " ";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            if (reader.Read())
            {
                while (reader.Read())
                {
                    returnMensalista.id_mensalista = Int32.Parse(string.Format("{0}", reader[0]));
                    returnMensalista.id_cliente = Int32.Parse(string.Format("{0}", reader[1]));
                    returnMensalista.nome_cliente = string.Format("{0}", reader[4]);
                    returnMensalista.data_termino = string.Format("{0}", reader[2]);
                }
            }

            return returnMensalista;
        }
Example #43
0
        public double getTotalCaixa()
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT SUM(ValorTotal) AS TotalCaixa FROM Ticketcar.dbo.Tickets WHERE CAST(DataEntrada AS DATE) = CAST(GETDATE() AS DATE)";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            Double total = 0;

            while (reader.Read())
            {
                total = double.Parse(string.Format("{0}", reader["TotalCaixa"]));
            }

            return total;
        }
Example #44
0
 public Boolean inserir(Ticket ticket, Carro carro, Cliente cliente, Servicos servico)
 {
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     string sql = "INSERT INTO Tickets (Id_cliente,Id_carro,Id_Servico,DataEntrada,DataSaida,ValorTotal,Placa,UF,Cidade) VALUES(" + cliente.id_cliente + "," + carro.id_carro + "," + servico.id_servico + ",'" + ticket.data_entrada + "','" + ticket.data_saida + "'," + ticket.valorTotal + ",'" + ticket.placa + "','" + ticket.uf + "','" + ticket.cidade + "')";
     command.CommandText = sql;
     command.CommandType = CommandType.Text;
     command.Connection = con.getConnection();
     command.ExecuteNonQuery();
     con.closeConnection();
     return true;
 }
Example #45
0
        public Cliente getClientebyId(Cliente cliente)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT * FROM Clientes where Id_cliente =" + cliente.id_cliente;
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();
            Cliente returnCliente = new Cliente();
            while (reader.Read())
            {
                returnCliente.id_cliente = Int32.Parse(string.Format("{0}", reader[0]));
                returnCliente.nome = string.Format("{0}", reader[1]);
                returnCliente.cpf = string.Format("{0}", reader[2]);
                returnCliente.saldo = double.Parse(string.Format("{0}", reader[3]));

                return returnCliente;
            }
            con.closeConnection();
            return returnCliente;
        }
Example #46
0
        public Boolean deletar(Cliente cliente)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "DELETE Clientes WHERE Id_cliente = " + cliente.id_cliente;
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            con.closeConnection();

            return true;
        }
Example #47
0
 public Boolean debitarSaldo( Cliente cliente, Double valor)
 {
     Double saldo = (cliente.saldo - valor);
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     String sql = "UPDATE Clientes SET Saldo = " + saldo + " where Id_cliente = " + cliente.id_cliente;
     command.CommandText = sql;
     command.CommandType = CommandType.Text;
     command.Connection = con.getConnection();
     command.ExecuteNonQuery();
     con.closeConnection();
     return true;
 }
Example #48
0
        public Boolean inserir(Cliente cliente)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            string sql = "INSERT INTO Clientes (Nome,Cpf,Saldo) VALUES('" + cliente.nome + "','" + cliente.cpf + "'," + cliente.saldo + ")";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            command.ExecuteNonQuery();

            con.closeConnection();

            return true;
        }
Example #49
0
        public Ticket getTicketbyId(Ticket ticket)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT T.ID_ticket,Cl.Id_Cliente,Cl.Nome,Cl.Cpf,Ca.ID_carro,Ca.Marca,Ca.Modelo,T.Placa,T.UF,T.Cidade,S.ID_servico,S.Descricao,S.Preco,T.DataEntrada,T.DataSaida,T.ValorTotal FROM ticketcar.dbo.Tickets AS T INNER JOIN Clientes AS Cl ON T.Id_cliente = Cl.Id_Cliente INNER JOIN Carro AS Ca ON T.id_Carro = Ca.ID_carro INNER JOIN Servicos AS S ON T.Id_Servico = S.ID_servico WHERE T.ID_ticket =" + ticket.id_ticket;
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            Ticket returnTicket = new Ticket();

            while (reader.Read())
            {
                //Ticket
                ticket.id_ticket = int.Parse(string.Format("{0}", reader[0]));

                //Cliente
                ticket.id_cliente = int.Parse(string.Format("{0}", reader[1]));
                //Carro
                ticket.id_carro = Convert.ToInt32(string.Format("{0}", reader["id_Carro"]));
                //Servico
                ticket.id_servico = int.Parse(string.Format("{0}", reader["Id_Servico"]));
                //Ticket
                ticket.data_entrada = Convert.ToDateTime(reader["DataEntrada"]).ToString("dd/MM/yyyy HH:mm");
                ticket.data_saida = Convert.ToDateTime(reader["DataSaida"]).ToString("dd/MM/yyyy HH:mm");
                ticket.valorTotal = Convert.ToDouble(string.Format("{0}", reader[6]));

                //Placa carro
                ticket.placa = string.Format("{0}", reader[7]);
                ticket.uf = string.Format("{0}", reader[8]);
                ticket.cidade = string.Format("{0}", reader[9]);

                return returnTicket;
            }

            con.closeConnection();
            return returnTicket;
        }
Example #50
0
        public Boolean inserir(Mensalista mensalista)
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            string sql = "INSERT INTO Mensalistas (Id_cliente, Data_termino) VALUES(" + mensalista.id_cliente + ",'" + mensalista.data_termino + "')";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            command.ExecuteNonQuery();

            con.closeConnection();

            return true;
        }
Example #51
0
 //Initialize values
 private void Initialize()
 {
     connection = Connection.getConnection();
 }
Example #52
0
        public List<Ticket> listaarCaixa()
        {
            Connection con = new Connection();
            con.openConnection();
            SqlCommand command = new SqlCommand();
            SqlDataReader reader;
            string sql = "SELECT ID_ticket,Id_cliente,id_Carro,Id_Servico,DataEntrada,DataSaida,ValorTotal, Placa,UF,Cidade FROM Ticketcar.dbo.Tickets WHERE CAST(DataEntrada AS DATE) = CAST(GETDATE() AS DATE)";
            command.CommandText = sql;
            command.CommandType = CommandType.Text;
            command.Connection = con.getConnection();
            reader = command.ExecuteReader();

            List<Ticket> listaTickets = new List<Ticket>();

            while (reader.Read())
            {
                Ticket ticket = new Ticket();

                //Ticket
                ticket.id_ticket = int.Parse(string.Format("{0}", reader[0]));

                //Cliente
                ticket.id_cliente = int.Parse(string.Format("{0}", reader[1]));
                //Carro
                ticket.id_carro = Convert.ToInt32(string.Format("{0}", reader["id_Carro"]));
                //Servico
                ticket.id_servico = int.Parse(string.Format("{0}", reader["Id_Servico"]));
                //Ticket
                ticket.data_entrada = Convert.ToDateTime(reader["DataEntrada"]).ToString("dd/MM/yyyy HH:mm");
                ticket.data_saida = Convert.ToDateTime(reader["DataSaida"]).ToString("dd/MM/yyyy HH:mm");
                ticket.valorTotal = Convert.ToDouble(string.Format("{0}", reader[6]));

                //Placa carro
                ticket.placa = string.Format("{0}", reader[7]);
                ticket.uf = string.Format("{0}", reader[8]);
                ticket.cidade = string.Format("{0}", reader[9]);

                listaTickets.Add(ticket);
            }

            con.closeConnection();
            return listaTickets;
        }
        private void btn_aceptar_Click(object sender, EventArgs e)
        {
            if (validarCampos())
            {
                using (SqlConnection cx = Connection.getConnection())
                {
                    SqlTransaction tx = null;
                    try
                    {
                        cx.Open();
                        tx = cx.BeginTransaction();
                        Especialidad espSeleccionada = this.especialidades.Find(especialidad => especialidad.Descripcion.Equals(this.cmb_especialidades.SelectedItem.ToString()));
                        this.totalHoras = 0;
                        SqlCommand sqlCmd = new SqlCommand("SELECT pico_y_pala.cantHorasSemanaProf(@nroDocProf, @fechaActual)", cx, tx);
                        sqlCmd.Parameters.Add("@nroDocProf", SqlDbType.Decimal).Value = this.profesional.NroDoc;
                        sqlCmd.Parameters.Add("@fechaActual", SqlDbType.Date).Value   = DateTime.Parse(Program.fechaActual).Date;
                        this.totalHoras += Convert.ToDouble(sqlCmd.ExecuteScalar());
                        if (this.chk_lunes.Checked && this.cmb_hora_desde_lunes.SelectedItem != null)
                        {
                            this.totalHoras += TimeSpan.Parse(this.cmb_hora_hasta_lunes.SelectedItem.ToString()).Subtract(TimeSpan.Parse(this.cmb_hora_desde_lunes.SelectedItem.ToString())).TotalHours;
                            procesarRegistrarAgenda(cx, tx, new Dia(2, "Lunes"), espSeleccionada, this.dtp_desde_lunes, this.dtp_hasta_lunes, this.cmb_hora_desde_lunes, this.cmb_hora_hasta_lunes, this.cmb_error_lunes, this.lbl_error_lunes);
                        }
                        if (this.chk_martes.Checked && this.cmb_hora_desde_martes.SelectedItem != null)
                        {
                            this.totalHoras += TimeSpan.Parse(this.cmb_hora_hasta_martes.SelectedItem.ToString()).Subtract(TimeSpan.Parse(this.cmb_hora_desde_martes.SelectedItem.ToString())).TotalHours;
                            procesarRegistrarAgenda(cx, tx, new Dia(3, "Martes"), espSeleccionada, this.dtp_desde_martes, this.dtp_hasta_martes, this.cmb_hora_desde_martes, this.cmb_hora_hasta_martes, this.cmb_error_martes, this.lbl_error_martes);
                        }
                        if (this.chk_miercoles.Checked && this.cmb_hora_desde_miercoles.SelectedItem != null)
                        {
                            this.totalHoras += TimeSpan.Parse(this.cmb_hora_hasta_miercoles.SelectedItem.ToString()).Subtract(TimeSpan.Parse(this.cmb_hora_desde_miercoles.SelectedItem.ToString())).TotalHours;
                            procesarRegistrarAgenda(cx, tx, new Dia(4, "Miercoles"), espSeleccionada, this.dtp_desde_miercoles, this.dtp_hasta_miercoles, this.cmb_hora_desde_miercoles, this.cmb_hora_hasta_miercoles, this.cmb_error_miercoles, this.lbl_error_miercoles);
                        }
                        if (this.chk_jueves.Checked && this.cmb_hora_desde_jueves.SelectedItem != null)
                        {
                            this.totalHoras += TimeSpan.Parse(this.cmb_hora_hasta_jueves.SelectedItem.ToString()).Subtract(TimeSpan.Parse(this.cmb_hora_desde_jueves.SelectedItem.ToString())).TotalHours;
                            procesarRegistrarAgenda(cx, tx, new Dia(5, "Jueves"), espSeleccionada, this.dtp_desde_jueves, this.dtp_hasta_jueves, this.cmb_hora_desde_jueves, this.cmb_hora_hasta_jueves, this.cmb_error_jueves, this.lbl_error_jueves);
                        }
                        if (this.chk_viernes.Checked && this.cmb_hora_desde_viernes.SelectedItem != null)
                        {
                            this.totalHoras += TimeSpan.Parse(this.cmb_hora_hasta_viernes.SelectedItem.ToString()).Subtract(TimeSpan.Parse(this.cmb_hora_desde_viernes.SelectedItem.ToString())).TotalHours;
                            procesarRegistrarAgenda(cx, tx, new Dia(6, "Viernes"), espSeleccionada, this.dtp_desde_viernes, this.dtp_hasta_viernes, this.cmb_hora_desde_viernes, this.cmb_hora_hasta_viernes, this.cmb_error_viernes, this.lbl_error_viernes);
                        }
                        if (this.chk_sabado.Checked && this.cmb_hora_desde_sabado.SelectedItem != null)
                        {
                            this.totalHoras += TimeSpan.Parse(this.cmb_hora_hasta_sabado.SelectedItem.ToString()).Subtract(TimeSpan.Parse(this.cmb_hora_desde_sabado.SelectedItem.ToString())).TotalHours;
                            procesarRegistrarAgenda(cx, tx, new Dia(6, "Sabado"), espSeleccionada, this.dtp_desde_sabado, this.dtp_hasta_sabado, this.cmb_hora_desde_sabado, this.cmb_hora_hasta_sabado, this.cmb_error_sabado, this.lbl_error_sabado);
                        }

                        this.lbl_error_horas_profesional.Visible = this.totalHoras > MAXIMO_HORAS;

                        if (!this.lbl_error_lunes.Visible && !this.lbl_error_martes.Visible && !this.lbl_error_miercoles.Visible &&
                            !this.lbl_error_jueves.Visible && !this.lbl_error_viernes.Visible && !this.lbl_error_sabado.Visible &&
                            !this.lbl_error_horas_profesional.Visible && !this.lbl_error_horas_profesional.Visible)
                        {
                            tx.Commit();
                            this.Close();
                        }
                        else
                        {
                            this.lbl_error_horas_profesional.Text = this.lbl_error_horas_profesional.Text.Replace("{0}", this.totalHoras.ToString());
                            tx.Rollback();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("ERROR AL INTENTAR REGISTRAR AGENDA!!");
                        Console.WriteLine(ex);
                        if (tx != null)
                        {
                            tx.Rollback();
                        }
                        MessageBox.Show("Se produjo un error al registrar las agendas", "Error al registrar agenda", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #54
0
 public Boolean editar(Cliente cliente)
 {
     Connection con = new Connection();
     con.openConnection();
     SqlCommand command = new SqlCommand();
     String sql = "UPDATE Clientes set Nome='" + cliente.nome + "', Cpf ='" + cliente.cpf + "',  Saldo = " + cliente.saldo+ " where Id_cliente = " + cliente.id_cliente;
     command.CommandText = sql;
     command.CommandType = CommandType.Text;
     command.Connection = con.getConnection();
     command.ExecuteNonQuery();
     con.closeConnection();
     return true;
 }