示例#1
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, "Badr.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 (MySqlConnection _sqlConnection = new MySqlConnection(Configs._urlServer))
                {
                    MySqlCommand cmd = new MySqlCommand(sql, _sqlConnection);
                    // _dataReader = new MySqlDataReader(sql, _sqlConnection);
                    DataSet ds = new DataSet();
                    cmd.Connection.Open();
                    _dataReader = cmd.ExecuteReader(); //(_command);
                    dt.Load(_dataReader);
                    cmd.Connection.Close();
                }
            }
            catch (Exception ex)
            {
                Configs.Debug(ex, "Badr.Models.Query.executeSql", "impossible d'exécuter cette requette : " + sql);
            }

            return(dt);
        }
示例#2
0
        public DataTable executeProc(string name, string parameters = "", Boolean open = false, char spliter = '@', char spliter2 = '#')
        {
            DataTable dt = new DataTable();

            try
            {
                using (MySqlConnection _sqlConnection = new MySqlConnection("server=localhost; user id=root; password=; database=gs_stock; pooling=false;"))
                {
                    _command             = new MySqlCommand();
                    _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.AddWithValue("?" + valPrm[0], DBNull.Value);//.Value = DBNull.Value;
                                }
                                else
                                {
                                    _command.Parameters.AddWithValue("?" + valPrm[0], Convert.ToDateTime(valPrm[2]));//.Value = Convert.ToDateTime(valPrm[2]);
                                }
                            }
                            else if (valPrm[1] == "string")
                            {
                                _command.Parameters.AddWithValue("?" + valPrm[0], valPrm[2]);//.Value = valPrm[2];
                            }
                            else if (valPrm[1] == "int")
                            {
                                if (valPrm[2].Trim() == "")
                                {
                                    valPrm[2] = "0";
                                }
                                _command.Parameters.AddWithValue("?" + valPrm[0], valPrm[2]);
                            }
                            else if (valPrm[1] == "double" || valPrm[1] == "float")
                            {
                                if (valPrm[2].Trim() == "")
                                {
                                    valPrm[2] = "0";
                                }
                                _command.Parameters.AddWithValue("?" + valPrm[0], double.Parse(valPrm[2]));
                            }
                        }
                    }
                    _command.Connection.Open();


                    _command.CommandTimeout = 120;
                    _dataReader             = _command.ExecuteReader(); //(_command);
                    dt.Load(_dataReader);
                }
            }
            catch (Exception exx)
            {
                Configs.Debug(exx, "Badr.Models.Query.executeProc", name + " => " + parameters);
            }

            return(dt);
        }
示例#3
0
        public DataSet executeProcPlus(string name, string parameters = "", Boolean open = false, char spliter = '@', char spliter2 = '#')
        {
            DataSet ds = null;

            using (MySqlConnection Con = new MySqlConnection(Configs._urlServer))
            {
                MySqlCommand     _command;
                MySqlDataAdapter _dataAdapter;
                try
                {
                    _command = new MySqlCommand();

                    _command.CommandTimeout = 380;
                    _command.CommandType    = CommandType.StoredProcedure;
                    _command.Connection     = Con;
                    _command.CommandText    = name;

                    if (parameters != "")
                    {
                        string[] prm = parameters.Split(spliter2);

                        for (int i = 0; i < prm.Length; i++)
                        {
                            string[] valPrm = prm[i].Split(spliter);

                            if (valPrm.Length < 3)
                            {
                                continue;
                            }

                            if (valPrm[2] == null || DBNull.Value.Equals(valPrm[2]))
                            {
                                valPrm[2] = "";
                            }

                            if (valPrm[1] == "date")
                            {
                                if (valPrm[2] == "")
                                {
                                    _command.Parameters.Add("@" + valPrm[0], MySqlDbType.DateTime).Value = DBNull.Value;
                                }
                                else
                                {
                                    _command.Parameters.Add("@" + valPrm[0], MySqlDbType.DateTime).Value = Convert.ToDateTime(valPrm[2]);
                                }
                            }
                            else if (valPrm[1] == "string")
                            {
                                _command.Parameters.Add("@" + valPrm[0], MySqlDbType.String).Value = valPrm[2];
                            }
                            else if (valPrm[1] == "int")
                            {
                                if (valPrm[2].Trim() == "")
                                {
                                    valPrm[2] = "0";
                                }
                                _command.Parameters.Add("@" + valPrm[0], MySqlDbType.Int64).Value = valPrm[2];
                            }
                            else if (valPrm[1] == "double" || valPrm[1] == "float")
                            {
                                //double tmp = 0;
                                //if (valPrm[2].IndexOf('.') > 0 && double.TryParse(valPrm[2].Replace('.', ','), out tmp))
                                //if (valPrm[2].IndexOf(',') > 0 && double.TryParse(valPrm[2].Replace(',', '.'), out tmp))

                                if (valPrm[2].Trim() == "")
                                {
                                    valPrm[2] = "0";
                                }
                                _command.Parameters.Add("@" + valPrm[0], MySqlDbType.Float).Value = double.Parse(valPrm[2]);
                            }
                        }
                    }

                    _dataAdapter = new MySqlDataAdapter(_command);
                    ds           = new DataSet();

                    _dataAdapter.Fill(ds);
                }
                catch (Exception exx)
                {
                    ds = null;
                    Configs.Debug(exx, "executeProcPlus", name + " => " + parameters);
                }
                finally
                {
                    _dataAdapter = null;
                    _command     = null;
                    // CloseConnection(Con);
                }
            }
            return(ds);
        }
示例#4
0
        public DataTable executeProcMail(string name, string parameters = "", Boolean open = false, char spliter = '$', char spliter2 = '#')
        {
            DataTable dt = new DataTable();

            try
            {
                using (MySqlConnection _sqlConnection = new MySqlConnection(Configs._urlServer))
                {
                    _command             = new MySqlCommand();
                    _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], MySqlDbType.DateTime).Value = DBNull.Value;
                                }
                                else
                                {
                                    _command.Parameters.Add("@" + valPrm[0], MySqlDbType.DateTime).Value = Convert.ToDateTime(valPrm[2]);
                                }
                            }
                            else if (valPrm[1] == "string")
                            {
                                _command.Parameters.Add("@" + valPrm[0], MySqlDbType.VarString).Value = valPrm[2];
                            }
                            else if (valPrm[1] == "int")
                            {
                                if (valPrm[2].Trim() == "")
                                {
                                    valPrm[2] = "0";
                                }
                                _command.Parameters.Add("@" + valPrm[0], MySqlDbType.Int64).Value = valPrm[2];
                            }
                            else if (valPrm[1] == "double" || valPrm[1] == "float")
                            {
                                if (valPrm[2].Trim() == "")
                                {
                                    valPrm[2] = "0";
                                }
                                _command.Parameters.Add("@" + valPrm[0], MySqlDbType.Float).Value = valPrm[2];
                            }
                        }
                    }

                    _dataReader = _command.ExecuteReader(); //(_command);
                    dt.Load(_dataReader);
                }
            }
            catch (Exception exx)
            {
                Configs.Debug(exx, "Badr.Models.Query.executeProc", name + " => " + parameters);
                //if (open == true) Configs._sqlConnection.Close();
            }

            return(dt);
        }