Exemplo n.º 1
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();
        }
Exemplo n.º 2
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();
        }