Ejemplo n.º 1
0
        //publClass1.csic override int ExecuteSql(string Sql, List<ImageParameter> ImagePar)
        //{
        //    SqlCommand cmd = new SqlCommand();
        //    cmd.Connection = privateconn;
        //    cmd.Transaction = ts;
        //    cmd.CommandTimeout = 0;
        //    cmd.CommandType = CommandType.Text;
        //    cmd.CommandText = Sql;
        //    for (int i = 0; i < ImagePar.Count; i++)
        //    {
        //        SqlParameter p = new SqlParameter(ImagePar[i].Name, SqlDbType.VarBinary, ImagePar[i].Value.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, ImagePar[i].Value);
        //        cmd.Parameters.Add(p);
        //    }
        //    return cmd.ExecuteNonQuery();
        //}

        public override int ExecuteProcedure(string ProcedureName, List <ProcedureParameter> ProcedurePar)
        {
            return(DbCatch.Catch <int>(_isWatchTime, privateconn.DataSource, ProcedureName, ProcedurePar, () =>
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = privateconn;
                cmd.Transaction = ts;
                cmd.CommandTimeout = 0;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = ProcedureName;
                for (int i = 0; i < ProcedurePar.Count; i++)
                {
                    MySqlParameter p = ParameterTransform(ProcedurePar[i]);
                    cmd.Parameters.Add(p);
                }
                int result = cmd.ExecuteNonQuery();
                for (int i = 0; i < cmd.Parameters.Count; i++)
                {
                    switch (cmd.Parameters[i].Direction)
                    {
                    case ParameterDirection.InputOutput:
                    case ParameterDirection.Output:
                    case ParameterDirection.ReturnValue:
                        ProcedurePar[i] = new ProcedureParameter(ProcedurePar[i].Name, ProcedurePar[i].ParType, ProcedurePar[i].Size, ProcedurePar[i].Direction, cmd.Parameters[i].Value);
                        break;
                    }
                }
                return result;
            }));
        }
Ejemplo n.º 2
0
 public override void SqlBulkCopy(DataTable dt, string datatablename, string Sql, List <ProcedureParameter> ProcedurePar, int BatchSize = 0)
 {
     var r = DbCatch.Catch <int>(_isWatchTime, privateconn.DataSource, (string.IsNullOrWhiteSpace(Sql) ? datatablename : Sql), ProcedurePar, () =>
     {
         SqlBulkCopy sqlBulkCopy          = new SqlBulkCopy(privateconn, SqlBulkCopyOptions.Default, ts);
         sqlBulkCopy.DestinationTableName = datatablename;
         if (BatchSize > 0)
         {
             sqlBulkCopy.BatchSize = BatchSize;
         }
         sqlBulkCopy.WriteToServer(dt);
         sqlBulkCopy.Close();
         return(0);
     });
 }
Ejemplo n.º 3
0
 public override DbDataReader SqlToDbReader(string Sql, List <ProcedureParameter> ProcedurePar)
 {
     return(DbCatch.Catch <DbDataReader>(_isWatchTime, privateconn.DataSource, Sql, ProcedurePar, () =>
     {
         MySqlCommand cmd = new MySqlCommand();
         cmd.Connection = privateconn;
         cmd.Transaction = ts;
         cmd.CommandTimeout = 0;
         cmd.CommandType = CommandType.Text;
         cmd.CommandText = Sql;
         if (ProcedurePar != null)
         {
             for (int i = 0; i < ProcedurePar.Count; i++)
             {
                 MySqlParameter p = ParameterTransform(ProcedurePar[i]);
                 cmd.Parameters.Add(p);
             }
         }
         return cmd.ExecuteReader();
     }));
 }
Ejemplo n.º 4
0
 public override object ExecuteScalar(string Sql, CommandType CmdType, List <ProcedureParameter> ProcedurePar)
 {
     return(DbCatch.Catch <object>(_isWatchTime, privateconn.DataSource, Sql, ProcedurePar, () =>
     {
         SqlCommand cmd = new SqlCommand();
         cmd.Connection = privateconn;
         cmd.Transaction = ts;
         cmd.CommandTimeout = 0;
         cmd.CommandType = CmdType;
         cmd.CommandText = Sql;
         if (ProcedurePar != null)
         {
             for (int i = 0; i < ProcedurePar.Count; i++)
             {
                 SqlParameter p = ParameterTransform(ProcedurePar[i]);
                 cmd.Parameters.Add(p);
             }
         }
         return cmd.ExecuteScalar();
     }));
 }
Ejemplo n.º 5
0
        //public override void SqlBulkCopy(DataTable dt, string datatablename, string Sql, List<ProcedureParameter> ProcedurePar, int BatchSize = 0)
        //{
        //    var r = DbCatch.Catch<int>(_isWatchTime, privateconn.DataSource, (string.IsNullOrWhiteSpace(Sql) ? datatablename : Sql), ProcedurePar, () =>
        //    {
        //        SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(privateconn, SqlBulkCopyOptions.Default, ts);
        //        sqlBulkCopy.DestinationTableName = datatablename;
        //        if (BatchSize > 0)
        //        {
        //            sqlBulkCopy.BatchSize = BatchSize;
        //        }
        //        sqlBulkCopy.WriteToServer(dt);
        //        sqlBulkCopy.Close();
        //        return 0;
        //    });
        //}

        //public override void SqlBulkCopy(DataTable dt, string datatablename, string Sql, List<ProcedureParameter> ProcedurePar, Dictionary<string, string> mapps, int BatchSize = 0)
        //{
        //    var r = DbCatch.Catch<int>(_isWatchTime, privateconn.DataSource, (string.IsNullOrWhiteSpace(Sql) ? datatablename : Sql), ProcedurePar, () =>
        //    {
        //        SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(privateconn, SqlBulkCopyOptions.Default, ts);
        //        sqlBulkCopy.DestinationTableName = datatablename;
        //        foreach (var mapp in mapps)
        //        {
        //            sqlBulkCopy.ColumnMappings.Add(mapp.Key, mapp.Value);
        //        }
        //        if (BatchSize > 0)
        //        {
        //            sqlBulkCopy.BatchSize = BatchSize;
        //        }
        //        sqlBulkCopy.WriteToServer(dt);
        //        sqlBulkCopy.Close();
        //        return 0;
        //    });
        //}

        public override void SqlToDataSet(DataSet ds, string Sql, List <ProcedureParameter> ProcedurePar, string TableName)
        {
            var r = DbCatch.Catch <int>(_isWatchTime, privateconn.DataSource, Sql, ProcedurePar, () =>
            {
                MySqlCommand selectCmd   = new MySqlCommand();
                selectCmd.CommandTimeout = 0;
                selectCmd.Transaction    = ts;
                selectCmd.Connection     = privateconn;
                selectCmd.CommandType    = CommandType.Text;
                selectCmd.CommandText    = Sql;
                if (ProcedurePar != null)
                {
                    for (int i = 0; i < ProcedurePar.Count; i++)
                    {
                        MySqlParameter p = ParameterTransform(ProcedurePar[i]);
                        selectCmd.Parameters.Add(p);
                    }
                }
                MySqlDataAdapter da = new MySqlDataAdapter();
                da.SelectCommand    = selectCmd;
                da.Fill(ds, TableName);
                return(0);
            });
        }