Example #1
0
        public bool Insert_Log_Pipe(ref CLog_Pipe pipe)
        {
            MySqlDataReader reader;
            MySqlCommand cmd = null;
            string strcmd = "INSERT INTO [Log_Pipe]([PipeID],[LogPath]) values(" + pipe.PipeID + " ,'" + pipe.LogPath + "')";
            try
            {
                if (ConnectionState.Closed == connect.State)
                {
                    connect.Open();
                    cmd = new MySqlCommand();
                    count = 0;
                }
                else if (count >= NUMBER)
                {
                    count = 0;
                    connect.Close();
                    mysqlcmd = new MySqlCommand();
                    cmd = mysqlcmd;
                    connect.Open();
                }
                else
                {
                    count++;
                    cmd = mysqlcmd.Clone();
                }

                cmd.Connection = connect;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = strcmd;

                strcmd = "SELECT MAX([ID]) AS MAXID FROM [Log_Pipe]";
                cmd.ExecuteNonQuery();
                cmd.CommandText = strcmd;
                reader = cmd.ExecuteReader();
                reader.Read();
                pipe.ID = Convert.ToInt32(reader[0].ToString());
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Pipe of Log error : " + ex.Message);
                connect.Close();
                Console.WriteLine("Reinsrt log:");
                
                return Reinsert(ref pipe);
            }
            finally
            {
                //connect.Close();
            }
            return true;
        }
Example #2
0
        private List<CLog_Pipe> Select(string cmd)
        {
            List<CLog_Pipe> listpipe = new List<CLog_Pipe>();
            MySqlCommand com;
            MySqlDataReader reader;

            try
            {
                if(connect.State == ConnectionState.Closed)
                    connect.Open();
                com = new MySqlCommand(cmd, connect);
                reader = com.ExecuteReader();
                while (reader.Read())
                {
                    CLog_Pipe pipe = new CLog_Pipe();
                    int i = 0;
                    string tmp;
                    pipe.ID = Convert.ToInt32(reader[i++].ToString());
                    tmp = reader[i++].ToString();
                    if (tmp != null && tmp.Length > 0)
                        pipe.PipeID = Convert.ToInt32(tmp);
                    pipe.LogPath = reader[i++].ToString();
                    listpipe.Add(pipe);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Pipe of Log error : " + ex.Message);
                return null;
            }
            finally
            {
                if(connect!=null)
                connect.Close();
            }
            return listpipe;
        }
Example #3
0
        private bool Reinsert(ref CLog_Pipe pipe)
        {
            MySqlDataReader reader;
            MySqlCommand cmd = null;
            string strcmd = "INSERT INTO [Log_Pipe]([PipeID],[LogPath]) values(" + pipe.PipeID + " ,'" + pipe.LogPath + "')";
            try
            {
                connect.Open();
                cmd = new MySqlCommand();
                cmd.Connection = connect;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = strcmd;

                strcmd = "SELECT MAX([ID]) AS MAXID FROM [Log_Pipe]";
                cmd.ExecuteNonQuery();
                cmd.CommandText = strcmd;
                reader = cmd.ExecuteReader();
                reader.Read();
                pipe.ID = Convert.ToInt32(reader[0].ToString());
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Pipe of Log error : " + ex.Message);
                return false;
            }
            return true;
        }
Example #4
0
 public bool Delete_Log_Pipe(CLog_Pipe pipe)
 {
     List<string> listcmd = new List<string>();
     try
     {
         string cmd = "DELETE FROM [Log_Pipe] where ID = " + pipe.ID;
         listcmd.Add(cmd);
         ExectueCmd(listcmd);
     }
     catch (System.Exception ex)
     {
         Console.WriteLine("Pipe of Log error : " + ex.Message);
         return false;
     }
     return true;
 }