Esempio n. 1
0
        internal Compromisso instanciarCompromisso()
        {
            DateTime horaInicio, horaFim;

            Compromisso c = new Compromisso();

            if (mskInicio.Text != null)
            {
                c.Inicio = dtpInicio.Value.Date;
                horaInicio = Convert.ToDateTime(mskInicio.Text);
                c.Inicio = c.Inicio.AddHours(horaInicio.Hour);
                c.Inicio = c.Inicio.AddMinutes(horaInicio.Minute);
            }

            if (mskFim.Text != null)
            {
                c.Fim = dtpFim.Value.Date;
                horaFim = Convert.ToDateTime(mskFim.Text);
                c.Fim = c.Fim.AddHours(horaFim.Hour);
                c.Fim = c.Fim.AddMinutes(horaFim.Minute);
            }

            c.Descricao = txtDescricao.Text;

            return c;
        }
 public static void exportarCompromisso(Compromisso c, String arquivo)
 {
     try
     {
         CompromissoDAO.exportar(c, arquivo);
     }
     catch (Exception err)
     {
         throw err;
     }
 }
        public FrmEditCompromisso(Compromisso c)
        {
            this.Text = "Editar compromisso";

            this.compromisso = c;

            dtpInicio.Value = c.Inicio.Date;
            dtpFim.Value = c.Fim.Date;
            mskInicio.Text = c.Inicio.TimeOfDay.ToString();
            mskFim.Text = c.Fim.TimeOfDay.ToString();
            txtDescricao.Text = c.Descricao;
        }
 public static void excluirCompromisso(Compromisso c)
 {
     try
     {
         Usuario u = SessaoBusiness.UsuarioLogado;
         CompromissoDAO.excluir(u, c);
         Conexao.commit();
     }
     catch (Exception err)
     {
         Conexao.rollback();
         throw err;
     }
 }
 public static void cadastrarCompromisso(Compromisso c)
 {
     try
     {
         validarCompromisso(c);
         Usuario u = SessaoBusiness.UsuarioLogado;
         CompromissoDAO.cadastrar(u, c);
         Conexao.commit();
     }
     catch (Exception err)
     {
         Conexao.rollback();
         throw err;
     }
 }
Esempio n. 6
0
        public static void excluir(Usuario u, Compromisso c)
        {
            try
            {
                SqlCeConnection conn = Conexao.ConexaoSql;
                SqlCeCommand cmd = conn.CreateCommand();
                cmd.Transaction = Conexao.Transacao;

                cmd.CommandText = "delete compromisso where cpm_id = @id";
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@id", c.Id);

                cmd.ExecuteNonQuery();
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Esempio n. 7
0
        public static void cadastrar(Usuario u, Compromisso c)
        {
            try
            {
                SqlCeConnection conn = Conexao.ConexaoSql;
                SqlCeCommand cmd = conn.CreateCommand();
                cmd.Transaction = Conexao.Transacao;

                cmd.CommandText = "insert into compromisso (cpm_login, cpm_inicio, cpm_fim, cpm_descricao) " +
                    "values (@login, @inicio, @fim, @descricao)";
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@login", u.Login);
                cmd.Parameters.AddWithValue("@inicio", c.Inicio);
                cmd.Parameters.AddWithValue("@fim", c.Fim);
                cmd.Parameters.AddWithValue("@descricao", c.Descricao);

                cmd.ExecuteNonQuery();
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Esempio n. 8
0
        public static void alterar(Usuario u, Compromisso c)
        {
            try
            {
                SqlCeConnection conn = Conexao.ConexaoSql;
                SqlCeCommand cmd = conn.CreateCommand();
                cmd.Transaction = Conexao.Transacao;

                cmd.CommandText = "update compromisso set cpm_inicio = @inicio, " +
                    "cpm_fim = @fim, cpm_descricao = @descricao " +
                    "where cpm_id = @id";
                cmd.Prepare();
                cmd.Parameters.AddWithValue("@id", c.Id);
                cmd.Parameters.AddWithValue("@inicio", c.Inicio);
                cmd.Parameters.AddWithValue("@fim", c.Fim);
                cmd.Parameters.AddWithValue("@descricao", c.Descricao);

                cmd.ExecuteNonQuery();
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Esempio n. 9
0
        public static void exportar(Compromisso c, String arquivo)
        {
            try
            {
                JavaScriptSerializer serializador = new JavaScriptSerializer();
                String compromissoSerial = serializador.Serialize(c);

                // adiciona ao final do arquivo
                StreamWriter sw = new StreamWriter(arquivo, true);
                sw.Write(",");
                sw.Write(compromissoSerial);
                sw.Close();
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Esempio n. 10
0
        public static List<DateTime> listaDatas(Usuario u)
        {
            try
            {
                SqlCeConnection conn = Conexao.ConexaoSql;
                SqlCeCommand cmd = conn.CreateCommand();

                cmd.CommandText = "select * from compromisso " +
                    "where cpm_login = @login";

                cmd.Prepare();
                cmd.Parameters.AddWithValue("@login", u.Login);

                SqlCeDataReader reader = cmd.ExecuteReader();

                HashSet<DateTime> listaDatas = new HashSet<DateTime>();

                while (reader.Read())
                {
                    Compromisso c = new Compromisso(reader);
                    DateTime data = c.Inicio.Date;

                    do
                    {
                        listaDatas.Add(data);
                        data = data.AddDays(1);
                    }
                    while (data <= c.Fim);
                }

                return listaDatas.ToList();
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Esempio n. 11
0
        public static List<Compromisso> lista(Usuario u, DateTime data)
        {
            try
            {
                SqlCeConnection conn = Conexao.ConexaoSql;
                SqlCeCommand cmd = conn.CreateCommand();

                cmd.CommandText = "select * from compromisso " +
                    "where cpm_login = @login and ((datepart(day, cpm_inicio) = @dataDia " +
                        "and datepart(month, cpm_inicio) = @dataMes " +
                        "and datepart(year, cpm_inicio) = @dataAno) or " +
                        "(datepart(day, cpm_fim) = @dataDia " +
                        "and datepart(month, cpm_fim) = @dataMes " +
                        "and datepart(year, cpm_fim) = @dataAno) or " +
                        "(cpm_inicio < @data and cpm_fim > @data)) " +
                    "order by cpm_inicio asc";

                cmd.Prepare();
                cmd.Parameters.AddWithValue("@login", u.Login);
                cmd.Parameters.AddWithValue("@data", data);
                cmd.Parameters.AddWithValue("@dataDia", data.Day);
                cmd.Parameters.AddWithValue("@dataMes", data.Month);
                cmd.Parameters.AddWithValue("@dataAno", data.Year);

                SqlCeDataReader reader = cmd.ExecuteReader();

                List<Compromisso> lista = new List<Compromisso>();

                while (reader.Read())
                {
                    Compromisso c = new Compromisso(reader);
                    lista.Add(c);
                }

                return lista;
            }
            catch (Exception err)
            {
                throw err;
            }
        }
Esempio n. 12
0
        public static List<Compromisso> lista(Usuario u)
        {
            try
            {
                SqlCeConnection conn = Conexao.ConexaoSql;
                SqlCeCommand cmd = conn.CreateCommand();

                cmd.CommandText = "select * from compromisso " +
                    "where cpm_login = @login " +
                    "order by cpm_inicio asc";

                cmd.Prepare();
                cmd.Parameters.AddWithValue("@login", u.Login);

                SqlCeDataReader reader = cmd.ExecuteReader();

                List<Compromisso> lista = new List<Compromisso>();

                while (reader.Read())
                {
                    Compromisso c = new Compromisso(reader);
                    lista.Add(c);
                }

                return lista;
            }
            catch (Exception err)
            {
                throw err;
            }
        }
        private static bool validarCompromisso(Compromisso c)
        {
            if (c.Inicio > c.Fim)
            {
                throw new Exception("Data de início deve ser menor ou igual a data final.");
            }

            return true;
        }