示例#1
0
        public void ForWardMessage2(string message)
        {
            string chatid = "136331911";
            string token  = Token();

            string v  = message.Replace("/", " ");
            string v1 = v.Replace("#", " ");

            string encode = RestSharp.Contrib.HttpUtility.UrlEncode(v1);

            string v2 = v.Replace("LAPORAN", " ");


            string url = "https://api.telegram.org/bot" + token + "/sendMessage?chat_id=" + chatid + "&text=" + v1;

            var request = WebRequest.Create(url);

            request.Timeout     = 90000;
            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            try
            {
                var resa = request.GetResponse();

                using (var reader = new StreamReader(resa.GetResponseStream()))
                {
                    string content = reader.ReadToEnd();
                }

                resa.Close();
            }
            catch (WebException error)
            {
                Log log = new Log();
                log.CreateLog("error-sendForward", error.StackTrace, error.Message, null);

                SendMail mail = new SendMail();
                mail.SendEmailKeIT("Error send Forward Bot", error.Message);
            }
        }
示例#2
0
        public void InsertChat(string messageid, string userid, string text, string botname, string type, string replymessage_id, string updateid)
        {
            Log log = new Log();



            try
            {
                if (this.OpenConnection() == true)
                {
                    MySqlCommand cmd2 = new MySqlCommand();
                    cmd2.Connection  = connection;
                    cmd2.CommandText = "INSERT INTO chat(messageid,userid,text,created_at,botname,type,replymessage_id,updateid) "
                                       + "VALUES(@messageid,@userid,@text,now(),@botname,@type,@replymessage_id,@updateid)";

                    cmd2.Prepare();

                    cmd2.Parameters.AddWithValue("@messageid", messageid);
                    cmd2.Parameters.AddWithValue("@userid", userid);
                    cmd2.Parameters.AddWithValue("@text", text);
                    cmd2.Parameters.AddWithValue("@botname", botname);
                    cmd2.Parameters.AddWithValue("@type", type);
                    cmd2.Parameters.AddWithValue("@replymessage_id", replymessage_id);
                    cmd2.Parameters.AddWithValue("@updateid", updateid);
                    cmd2.ExecuteNonQuery();
                }
            }
            catch (MySqlException error)
            {
                Console.WriteLine("Error: {0}", error.ToString());

                log.CreateLog("error-SimpanChat", error.StackTrace, error.Message + " | prosesSimpanChat", null);
                SendMail mail = new SendMail();
                mail.SendEmailKeIT("Error SimpanChat", error.Message);
            }
            finally
            {
                this.CloseConnection();
            }
        }
示例#3
0
        public void JustInfo()
        {
            string CekDate = DateTime.Now.ToString("yyyy-MM-dd 15:00");
            string hari    = DateTime.Now.ToString("dd-MM-yyyy");


            DateTime time   = DateTime.Now;
            string   format = time.ToString("d");

            string cs = @"server=localhost;userid=root;
            password="******";database=telegram-tamansari";

            MySqlConnection conn  = null;
            MySqlConnection conn2 = null;

            MySqlDataReader rdr  = null;
            MySqlDataReader rdr2 = null;

            conn  = new MySqlConnection(cs);
            conn2 = new MySqlConnection(cs);

            conn.Open();
            string stm = " SELECT id,first_name FROM user ";

            MySqlCommand cmd = new MySqlCommand(stm, conn);

            cmd.Parameters.AddWithValue("@waktu", format);
            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                string id_telegram = rdr[0].ToString();
                string firstname   = rdr[1].ToString();


                try
                {
                    string       sql  = " SELECT * FROM alert WHERE userid!=@id and  DATE_FORMAT(created_at,'%d/%m/%Y')=@waktu";
                    MySqlCommand cmd2 = new MySqlCommand(sql, conn2);
                    conn2.Open();
                    cmd2.Parameters.AddWithValue("@id", id_telegram);
                    cmd2.Parameters.AddWithValue("@waktu", format);
                    rdr2 = cmd2.ExecuteReader();

                    if (rdr2.HasRows)
                    {
                    }
                    else
                    {
                        string messageToSend = "Bapak / Ibu " + firstname.ToUpper() + " Yth , Sekedar mengingatkan u ";

                        string TOKEN = Token();

                        InsertAlert(id_telegram, messageToSend);

                        Pesan pesan = new Pesan();

                        pesan.pm(TOKEN, id_telegram, messageToSend);
                    }
                    conn2.Close();
                }
                catch (Exception error)
                {
                    conn.Close();
                    Log log = new Log();
                    log.CreateLog("error-alert", error.StackTrace, error.Message, null);

                    SendMail mail = new SendMail();
                    mail.SendEmailKeIT("Error alert", error.Message);
                }
            }
            rdr2.Dispose();

            rdr.Dispose();
            conn.Close();
            conn2.Close();
        }
示例#4
0
        public void Alert()
        {
            string CekDate = DateTime.Now.ToString("yyyy-MM-dd 15:00");
            string hari    = DateTime.Now.ToString("dd-MM-yyyy");


            DateTime time   = DateTime.Now;
            string   format = DateTime.Now.ToString("dd/MM/yyyy");

            string cs = @"server=localhost;userid=root;
            password="******";database=telegram-tamansari";

            MySqlConnection conn  = null;
            MySqlConnection conn2 = null;

            MySqlDataReader rdr = null;

            conn  = new MySqlConnection(cs);
            conn2 = new MySqlConnection(cs);

            conn.Open();
            string stm = " SELECT id,first_name FROM user WHERE id NOT IN "
                         + "( "
                         + "   SELECT userid FROM laporan "
                         + "   WHERE DATE_FORMAT(created_at,'%d/%m/%Y')='" + format + "'"
                         + " ) and  id!='206390585' ORDER BY first_name ASC";

            MySqlCommand cmd = new MySqlCommand(stm, conn);

            //cmd.Parameters.AddWithValue("@waktu", format);
            rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                string id_telegram = rdr[0].ToString();
                string firstname   = rdr[1].ToString();


                try
                {
                    #region off
                    //string sql = " SELECT * FROM alert WHERE userid=@id and  DATE_FORMAT(created_at,'%d/%m/%Y')=@waktu";
                    //MySqlCommand cmd2 = new MySqlCommand(sql, conn2);
                    //conn2.Open();
                    //cmd2.Parameters.AddWithValue("@id", id_telegram);
                    //cmd2.Parameters.AddWithValue("@waktu", format);
                    //rdr2 = cmd2.ExecuteReader();

                    //if (rdr2.HasRows)
                    //{

                    //    string messageToSend = "Bapak / Ibu " + firstname.ToUpper() + " Anda Belum Melaporkan Pekerjaan Dinas Harian " + hari +" Mohon Untuk Segera Mengirimkan Laporan tks";

                    //    string TOKEN = Token();

                    //    InsertAlert(id_telegram, messageToSend);

                    //    Pesan pesan = new Pesan();

                    //    pesan.pm(TOKEN, id_telegram, messageToSend);

                    //}
                    //else
                    //{
                    //    string messageToSend = "Bapak / Ibu " + firstname.ToUpper() + " Anda Belum Melaporkan Pekerjaan Dinas Harian " + hari + " Mohon Untuk Segera Mengirimkan Laporan tks";

                    //    string TOKEN = Token();

                    //    InsertAlert(id_telegram, messageToSend);

                    //    Pesan pesan = new Pesan();

                    //    pesan.pm(TOKEN, id_telegram, messageToSend);


                    //}
                    #endregion
                    Log log = new Log();
                    log.CreateLog("alert", id_telegram, firstname + "| " + stm, null);

                    string messageToSend = "Bapak / Ibu " + firstname.ToUpper() + ", \nAnda Belum Melaporkan Pekerjaan Dinas Harian " + hari + " Mohon Untuk Segera Mengirimkan Laporan \nTerima kasih";

                    string TOKEN = Token();

                    InsertAlert(id_telegram, messageToSend);

                    Pesan pesan = new Pesan();

                    pesan.pm(TOKEN, id_telegram, messageToSend);
                    conn2.Close();
                }
                catch (Exception error)
                {
                    conn.Close();
                    Log log = new Log();
                    log.CreateLog("error-alert", error.StackTrace, error.Message, null);

                    SendMail mail = new SendMail();
                    mail.SendEmailKeIT("Error alert", error.Message);
                }
            }
            //rdr2.Dispose();

            rdr.Dispose();
            conn.Close();
            // conn2.Close();
        }
示例#5
0
        public string CekLaporan(string id, string waktu)
        {
            string   result = null;
            DateTime time   = DateTime.Now;
            string   format = time.ToString("d");
            string   hari   = DateTime.Now.ToString("dd-MM-yyyy");

            try
            {
                if (this.OpenConnection() == true)
                {
                    string stm = " SELECT id,first_name FROM user WHERE id NOT IN "
                                 + "( "
                                 + "   SELECT userid FROM laporan "
                                 + "   WHERE DATE_FORMAT(created_at,'%d/%m/%Y')='" + format + "'"
                                 + " )";
                    MySqlCommand cmd = new MySqlCommand(stm, connection);
                    //Create a data reader and Execute the command
                    MySqlDataReader dataReader = cmd.ExecuteReader();

                    //cmd.Parameters.AddWithValue("@waktu", format);
                    dataReader = cmd.ExecuteReader();

                    while (dataReader.Read())
                    {
                        string id_telegram = dataReader[0].ToString();
                        string firstname   = dataReader[1].ToString();


                        try
                        {
                            string       sql  = " SELECT * FROM alert WHERE userid=@id and  DATE_FORMAT(created_at,'%d/%m/%Y')=@waktu";
                            MySqlCommand cmd2 = new MySqlCommand(sql, connection);
                            cmd2.Connection = connection;
                            cmd2.Parameters.AddWithValue("@id", id);
                            cmd2.Parameters.AddWithValue("@waktu", format);
                            dataReader = cmd2.ExecuteReader();

                            if (dataReader.HasRows)
                            {
                            }
                            else
                            {
                                string messageToSend = "Bapak/Ibu " + firstname.ToUpper() + " ANDA BELUM MELAPORKAN PEKERJAAN DINAS HARIAN " + hari;

                                //string TOKEN = Token();

                                //InsertAlert(id_telegram, messageToSend);
                                //pm(TOKEN, id_telegram, messageToSend);
                            }

                            this.CloseConnection();
                        }
                        catch (Exception error)
                        {
                            Log log = new Log();
                            log.CreateLog("error-CekLaporan", error.StackTrace, error.Message, null);

                            SendMail mail = new SendMail();
                            mail.SendEmailKeIT("Error CekLaporan", error.Message);

                            this.CloseConnection();
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Log log = new Log();
                log.CreateLog("error-CekLaporan", error.StackTrace, error.Message, null);

                SendMail mail = new SendMail();
                mail.SendEmailKeIT("Error CekLaporan", error.Message);
            }


            return(result);
        }
示例#6
0
        public string InsertLaporan(string userid, string chatid, string judul, string desc, string header)
        {
            DateTime time   = DateTime.Now;
            string   format = time.ToString("d");

            Console.WriteLine(time.ToString(format));
            MySqlDataReader rdr = null;

            string result = null;

            try
            {
                if (this.OpenConnection() == true)
                {
                    string stm = "SELECT * FROM laporan where userid='" + userid + "'" + " and DATE_FORMAT(created_at,'%d/%m/%Y')='" + format + "'";

                    MySqlCommand cmd = new MySqlCommand(stm, connection);
                    //cmd.Parameters.AddWithValue("@id", userid);
                    //cmd.Parameters.AddWithValue("@waktu", format);
                    rdr = cmd.ExecuteReader();

                    int jumlah_laporan = rdr.FieldCount;
                    // if (rdr.Read())
                    if (rdr.HasRows)
                    {
                        int res = 0;
                        while (rdr.Read())
                        {
                            ++res;
                        }

                        if (res > 5)
                        {
                            result = "LaporanSudahAda";
                        }
                        else
                        {
                            this.CloseConnection();
                            rdr.Close();
                            //conn.Close();

                            if (this.OpenConnection() == true)
                            {
                                MySqlCommand cmd2 = new MySqlCommand();
                                cmd2.Connection  = connection;
                                cmd2.CommandText = "INSERT INTO laporan(userid,chatid,judul,deskripsi,created_at,header) VALUES(@userid,@chatid,@judul,@desc,now(),@header)";
                                cmd2.Prepare();

                                cmd2.Parameters.AddWithValue("@userid", userid);
                                cmd2.Parameters.AddWithValue("@chatid", chatid);
                                cmd2.Parameters.AddWithValue("@judul", judul);
                                cmd2.Parameters.AddWithValue("@desc", desc);
                                cmd2.Parameters.AddWithValue("@header", header);
                                cmd2.ExecuteNonQuery();
                                result = "LaporanTersimpan";
                            } //end if
                        }     //end else
                    }
                    else
                    {
                        this.CloseConnection();
                        rdr.Close();
                        //conn.Close();

                        if (this.OpenConnection() == true)
                        {
                            MySqlCommand cmd2 = new MySqlCommand();
                            cmd2.Connection  = connection;
                            cmd2.CommandText = "INSERT INTO laporan(userid,chatid,judul,deskripsi,created_at,header) VALUES(@userid,@chatid,@judul,@desc,now(),@header)";
                            cmd2.Prepare();

                            cmd2.Parameters.AddWithValue("@userid", userid);
                            cmd2.Parameters.AddWithValue("@chatid", chatid);
                            cmd2.Parameters.AddWithValue("@judul", judul);
                            cmd2.Parameters.AddWithValue("@desc", desc);
                            cmd2.Parameters.AddWithValue("@header", header);
                            cmd2.ExecuteNonQuery();
                            result = "LaporanTersimpan";
                        }//end if
                    }
                }

                //return true;
            }
            catch (MySqlException error)
            {
                Console.WriteLine("Error: {0}", error.ToString());

                result = "failed";
                Log log = new Log();
                log.CreateLog("error-InsertLaporan", error.StackTrace, error.Message, null);

                SendMail mail = new SendMail();
                mail.SendEmailKeIT("Error InsertLaporan", error.Message);
            }
            finally
            {
                this.CloseConnection();
            }

            return(result);
        }