Beispiel #1
0
 /// <summary>
 /// Método que faz a inserção de dados no banco
 /// </summary>
 /// <param name="sql">Código SQL</param>
 /// <returns></returns>
 public int insertSOF(string sql, string p_data1 = null, string p_data2 = null)
 {
     try
     {
         ManipulaBD objManipulaBD = ManipulaBD.GetInstance(stringConn);
         objManipulaBD.openConnection();
         SqlCeCommand cmd = new SqlCeCommand(sql, objSqlCeConnection);
         if ((!string.IsNullOrEmpty(p_data1)) && (!string.IsNullOrEmpty(p_data2)))
         {
             //Converte as datas informadas para o formato de inserção no banco
             System.Globalization.DateTimeFormatInfo dateInfoBr = new System.Globalization.DateTimeFormatInfo();
             dateInfoBr.ShortDatePattern = "dd/MM/yyyy";
             DateTime data1 = Convert.ToDateTime(p_data1, dateInfoBr);
             DateTime data2 = Convert.ToDateTime(p_data2, dateInfoBr);
             cmd.Parameters.Add("@p_data1", SqlDbType.DateTime).Value = data1;
             cmd.Parameters.Add("@p_data2", SqlDbType.DateTime).Value = data2;
         }
         cmd.CommandText = sql;
         cmd.CommandType = CommandType.Text;
         return(cmd.ExecuteNonQuery());
     }
     catch (Exception exc)
     {
         MessageBox.Show("SQL ERRO: " + sql);
         MessageBox.Show("ERRO INSERT: " + exc.ToString());
         throw;
     }
 }
Beispiel #2
0
        /// <param name="sql">Consulta SQL</param>
        /// <param name="table">Tabela</param>
        /// <returns></returns>
        public DataTable selectListaSOF(string sql, string table)
        {
            ManipulaBD objManipulaBD = ManipulaBD.GetInstance(stringConn);

            objManipulaBD.openConnection();
            SqlCeDataAdapter dad = new SqlCeDataAdapter(sql, objSqlCeConnection);

            dad.SelectCommand.CommandType = CommandType.Text;
            DataSet ds = new DataSet();

            try
            {
                dad.Fill(ds, table);
                if (ds.Tables[table].Rows.Count > 0)
                {
                    return(ds.Tables[table]);
                }
                else
                {
                    return(ds.Tables[table]);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Carrega os registros de uma tabela em um DataGridView
        /// </summary>
        /// <param name="sql">Consulta SQL</param>
        /// <param name="table">Tabela</param>
        /// <returns></returns>
        public DataSet selectSOF1(string sql, string tabela, string codigo = null)
        {
            ManipulaBD objManipulaBD = ManipulaBD.GetInstance(stringConn);

            objManipulaBD.openConnection();
            SqlCeDataAdapter dad = new SqlCeDataAdapter(sql, objSqlCeConnection);

            dad.SelectCommand.CommandType = CommandType.Text;
            DataSet ds = new DataSet();

            try
            {
                dad.Fill(ds, tabela);
                return(ds);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #4
0
 /// <summary>
 /// Faz um select no banco retornando um registro em específico
 /// </summary>
 /// <param name="sql">Consulta SQL</param>
 /// <returns></returns>
 public string selectSOF(string sql)
 {
     try
     {
         ManipulaBD objManipulaBD = ManipulaBD.GetInstance(stringConn);
         objManipulaBD.openConnection();
         SqlCeCommand    cmd    = new SqlCeCommand(sql, objSqlCeConnection);
         SqlCeDataReader reader = cmd.ExecuteReader();
         string          num    = "";
         while (reader.Read())
         {
             num = reader[0].ToString();
         }
         return(num);
     }
     catch (Exception)
     {
         throw;
     }
 }
Beispiel #5
0
 /// <summary>
 /// Método que apaga um ou todos os registos de uma tabela
 /// </summary>
 /// <param name="sql">Código SQL</param>
 /// <returns></returns>
 public int deleteSOF(string sql, string p_empr_codigo = null, string p_cod_representante = null)
 {
     try
     {
         ManipulaBD objManipulaBD = ManipulaBD.GetInstance(stringConn);
         objManipulaBD.openConnection();
         SqlCeCommand cmd = new SqlCeCommand(sql, objSqlCeConnection);
         cmd.CommandType = CommandType.Text;
         if (!string.IsNullOrEmpty(p_empr_codigo))
         {
             cmd.Parameters.AddWithValue("@empr_codigo", p_empr_codigo);
         }
         if (!string.IsNullOrEmpty(p_cod_representante))
         {
             cmd.Parameters.AddWithValue("@cod_representante", p_cod_representante);
         }
         return(cmd.ExecuteNonQuery());
     }
     catch (Exception)
     {
         throw;
     }
 }