コード例 #1
0
        public void send_text_blast(String tbid)
        {
            String    query = "";
            DataTable contacts = null;
            DataTable address_book = null;
            String    number = "", message = "";
            int       min_delay = 0;
            int       day_delay = 0;
            String    d_name = "", d_code = "";;


            Thread.Sleep(4000);
            try
            {
                // query = "SELECT d_cntc FROM rssys.tb_recip WHERE tbid='" + date_to_send.Rows[r]["tbid"].ToString() + "'";

                query    = "select * from rssys.tb_recip r LEFT JOIN rssys.tb_hdr h ON r.tbid=h.tbid LEFT JOIN rssys.tb_category c on c.tb_cat_id=h.tbtemp_id WHERE r.send_stat = 'N' AND h.tbid ='" + tbid + "'";
                contacts = db.QueryBySQLCode(query);
                if (contacts.Rows.Count >= 0)
                {
                    for (int c = 0; c < contacts.Rows.Count; c++)
                    {
                        tbid   = contacts.Rows[c]["tbid"].ToString();
                        number = contacts.Rows[c]["mobile1"].ToString();
                        //message = date_to_send.Rows[r]["message"].ToString();
                        message = contacts.Rows[c]["message"].ToString();
                        if (contacts.Rows[c]["cat_time_delay"].ToString() != "")
                        {
                            min_delay = Convert.ToInt32(contacts.Rows[c]["cat_time_delay"].ToString());
                        }
                        if (contacts.Rows[c]["cat_day_delay"].ToString() != "")
                        {
                            day_delay = Convert.ToInt32(contacts.Rows[c]["cat_day_delay"].ToString());
                        }
                        d_code       = contacts.Rows[c]["d_code"].ToString();
                        address_book = db.QueryBySQLCode("SELECT firstname,lastname,mname  FROM rssys.address_book WHERE code='" + d_code + "'");
                        if (address_book.Rows.Count > 0)
                        {
                            d_name  = address_book.Rows[0]["firstname"].ToString() + " " + address_book.Rows[0]["mname"].ToString() + " " + address_book.Rows[0]["lastname"].ToString();
                            message = "Dear " + d_name + " : " + message;
                        }

                        Thread.Sleep(min_delay * 60000);

                        if (send_message(number, message))
                        {
                            if (db.UpdateOnTable("tb_recip", "send_stat='Y'", "tbid='" + tbid + "' AND d_code='" + d_code + "'"))
                            {
                                lbl_status.Invoke(new Action(() =>
                                {
                                    lbl_status.Text = "Sending messages";
                                }));
                            }
                        }
                        else
                        {
                            lbl_status.Invoke(new Action(() =>
                            {
                                lbl_status.Text = "Func :send_text_blast => Message not sent";
                            }));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lbl_status.Invoke(new Action(() =>
                {
                    lbl_status.Text = "Func :send_text_blast => " + ex.Message;
                }));
            }
        }