Exemplo n.º 1
0
        public static string getURLContent(string url)
        {
            Uri          uri      = new Uri(url);
            WebRequest   request  = WebRequest.Create(uri);
            WebResponse  response = request.GetResponse();
            StreamReader sr       = null;

            try
            {
                sr = new StreamReader(response.GetResponseStream());
                return(sr.ReadToEnd());
            }
            catch (Exception ex)
            {
                Configs.Debug(ex);
                return(null);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }
Exemplo n.º 2
0
 public Query(Boolean open = true)
 {
     try
     {
         // if (open == true) Configs._sqlConnection.Open();
     }
     catch (Exception ex)
     {
         Configs.Debug(ex, "Omniyat.Models.Query.Query");
     }
 }
Exemplo n.º 3
0
        public static void DataTableToCSV(String filePath, DataTable dataTable)
        {
            try
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                StreamWriter sr     = new StreamWriter(filePath, false, System.Text.Encoding.GetEncoding("iso-8859-1"));
                string       values = "";
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    values += dataTable.Columns[i].ColumnName + ";";
                }

                if (values.Length > 0)
                {
                    values = values.Substring(0, values.Length - 1);
                }
                sr.WriteLine(values);
                sr.Flush();

                for (int i = 0; i < dataTable.Rows.Count; i++)
                {
                    values = "";

                    for (int j = 0; j < dataTable.Columns.Count; j++)
                    {
                        values += dataTable.Rows[i][j].ToString() + ";";
                    }

                    if (values.Length > 0)
                    {
                        values = values.Substring(0, values.Length - 1);
                    }
                    sr.WriteLine(values);
                    sr.Flush();
                }

                sr.Close();
            }
            catch (Exception ex)
            {
                Configs.Debug(ex);
            }
        }
Exemplo n.º 4
0
        public static string getCon_Config()
        {
            string res = "";

            try
            {
                string       file = HttpContext.Current.Server.MapPath("~/Config") + "/Config.dat";
                StreamReader sr   = new StreamReader(file);
                res = Cryptage.Decrypt(sr.ReadLine());
                sr.Close();
            }
            catch (Exception ex) {
                Configs.Debug(ex, "Omniyat.Models.TableGenerator.getCon_Config", "Echéc de chargement de Config/dat");
            }

            return(res);
        }
Exemplo n.º 5
0
        public static string GenerateTable(DataTable dt, string tableName)
        {
            StringBuilder resTable = new StringBuilder();

            resTable.Append("<table id='" + tableName + "' width='100%' cellspacing='4'>");

            try
            {
                if (dt != null)
                {
                    resTable.Append("<thead><tr>");
                    for (int i = 1; i < dt.Columns.Count; i++)
                    {
                        resTable.Append("<th style='text-align:center;'>" + dt.Columns[i].ColumnName + "</th>");
                    }
                    resTable.Append("</tr></thead>");

                    if (dt.Rows.Count > 0)
                    {
                        resTable.Append("<tbody>");
                    }

                    for (int irow = 0; irow < dt.Rows.Count; irow++)
                    {
                        resTable.Append("<tr index='" + dt.Rows[irow][0].ToString() + "' class='pt' style='font-size:10px;'>");
                        for (int icol = 1; icol < dt.Columns.Count; icol++)
                        {
                            resTable.Append("<td>" + dt.Rows[irow][icol].ToString() + "</td>");
                        }
                        resTable.Append("</tr>");
                    }
                    if (dt.Rows.Count > 0)
                    {
                        resTable.Append("</tbody>");
                    }
                }
                resTable.Append("</table>");
            }

            catch (Exception ex)
            {
                Configs.Debug(ex, "Omniyat.Models.TableGenerator.GenerateTable", "Echéc de la création de la table d'affichage des données : " + tableName);
            }
            return(resTable.ToString());
        }
Exemplo n.º 6
0
        //public bool verifyConnection(bool open)
        //{
        //    bool res = false;
        //    ConnectionState status = Configs._sqlConnection.State;
        //    try
        //    {
        //        if (status == ConnectionState.Broken || status == ConnectionState.Closed)
        //            Configs._sqlConnection.Open(); //if (open == true || status

        //        if (Configs._sqlConnection.State == ConnectionState.Open)
        //           res = true;
        //    }
        //    catch (Exception ex) {
        //        Configs.Debug(ex, "Omniyat.Models.Query.verifyConnection", "connection avec la BD est impossible");
        //    }

        //    return res;
        //}

        public DataTable executeSql(string sql, Boolean open = false)
        {
            DataTable dt = new DataTable();

            try
            {
                using (SqlConnection _sqlConnection = new SqlConnection(Configs._urlServer))
                {
                    _dataAdapter = new SqlDataAdapter(sql, _sqlConnection);
                    DataSet ds = new DataSet();
                    _dataAdapter.Fill(dt);
                }
            }
            catch (Exception ex)
            {
                Configs.Debug(ex, "Omniyat.Models.Query.executeSql", "impossible d'exécuter cette requette : " + sql);
            }

            return(dt);
        }
Exemplo n.º 7
0
        public int updateSql(string sql, Boolean open = false)
        {
            int returnVal = 0;

            try
            {
                using (SqlConnection _sqlConnection = new SqlConnection(Configs._urlServer))
                {
                    _command = new SqlCommand(sql, _sqlConnection);
                    _sqlConnection.Open();
                    returnVal = _command.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                Configs.Debug(ex, "Omniyat.Models.Query.updateSql", sql);
                returnVal = -1;
            }

            return(returnVal);
        }
Exemplo n.º 8
0
        public String executeScalar(string sql, Boolean open = false)
        {
            string val = "";

            try
            {
                using (SqlConnection _sqlConnection = new SqlConnection(Configs._urlServer))
                {
                    _command = new SqlCommand(sql, _sqlConnection);
                    _sqlConnection.Open();
                    Object obj = _command.ExecuteScalar();
                    val = (obj == null) ? "" : ((obj.ToString() == null) ? "" : _command.ExecuteScalar().ToString());
                }
            }
            catch (Exception ex)
            {
                Configs.Debug(ex, "Omniyat.Models.Query.executeScalar", sql);
            }

            return(val);
        }
Exemplo n.º 9
0
        public DataTable executeProc(string name, string parameters = "", Boolean open = false, char spliter = '@', char spliter2 = '#')
        {
            DataTable dt = new DataTable();

            try
            {
                using (SqlConnection _sqlConnection = new SqlConnection(Configs._urlServer))
                {
                    _command             = new SqlCommand();
                    _command.CommandType = CommandType.StoredProcedure;
                    _command.Connection  = _sqlConnection;
                    _command.CommandText = name;

                    string[] prm = parameters.Split(spliter2);

                    if (parameters != "")
                    {
                        for (int i = 0; i < prm.Length; i++)
                        {
                            string[] valPrm = prm[i].Split(spliter);
                            if (valPrm[1] == "date")
                            {
                                if (valPrm[2] == "")
                                {
                                    _command.Parameters.Add("@" + valPrm[0], SqlDbType.DateTime).Value = DBNull.Value;
                                }
                                else
                                {
                                    _command.Parameters.Add("@" + valPrm[0], SqlDbType.DateTime).Value = Convert.ToDateTime(valPrm[2]);
                                }
                            }
                            else if (valPrm[1] == "string")
                            {
                                _command.Parameters.Add("@" + valPrm[0], SqlDbType.NVarChar).Value = valPrm[2];
                            }
                            else if (valPrm[1] == "int")
                            {
                                if (valPrm[2].Trim() == "")
                                {
                                    valPrm[2] = "0";
                                }
                                _command.Parameters.Add("@" + valPrm[0], SqlDbType.BigInt).Value = valPrm[2];
                            }
                            else if (valPrm[1] == "double" || valPrm[1] == "float")
                            {
                                if (valPrm[2].Trim() == "")
                                {
                                    valPrm[2] = "0";
                                }
                                _command.Parameters.Add("@" + valPrm[0], SqlDbType.Float).Value = MCV.MyConvert.ToDouble(valPrm[2]);
                            }
                        }
                    }

                    _dataAdapter = new SqlDataAdapter(_command);
                    _dataAdapter.Fill(dt);
                }
            }
            catch (Exception exx)
            {
                Configs.Debug(exx, "Omniyat.Models.Query.executeProc", name + " => " + parameters);
            }

            return(dt);
        }