将项目添加到列表框,然后将电子邮件发送给目标收件人

时间:2019-01-30 09:44:10

标签: c# listbox email-validation

伙计们,我在C#中处于半中等水平,我需要有关所述标题的代码方面的帮助,实际上它不适用于我实现的代码。但是在这种情况下,如果添加了列表框项目,则所添加的目标将在我声明的秒数内将电子邮件发送到特定的目标电子邮件地址。

这是我的代码和程序。

1。)统计消息的程序:

公共无效statmessage()

    {
        string connstr = "server = ***.***.***.***; database = dbname; UID = ****; password = ****;";
        SqlConnection dbconn = new SqlConnection(connstr);
        string sqlstr = "select a.or_date, a.TransactionNo , a.email, a.bemail from vw_forEmailSending a where a.or_date between '2019-01-01 00:00:00.000' and '2500-12-31 00:00:00.000' order by or_date asc";
        SqlCommand cmd = new SqlCommand(sqlstr, dbconn);

        dbconn.Open();

        SqlDataReader rdr = cmd.ExecuteReader();
        listBox1.BeginUpdate();
        listBox1.Items.Clear();

        while (rdr.Read())
        {

               listBox1.Items.Add(new EItem(rdr.GetSqlDateTime(0) + " - " + "Transaction No.: " + rdr.GetString(1) + " has been submitted successfully all the details at " + rdr.GetString(2) + "."));


            lblcount.Text = listBox1.Items.Count.ToString();
            listBox1.SelectedIndex = listBox1.Items.Count - 1;



        }

        rdr.Close();
        dbconn.Close();
        listBox1.EndUpdate();
        listBox1.Refresh();

    }

2。)格式:

private int计数器;

    public Form1()
    {
        counter = 100;
        InitializeComponent();

    }

3。)实际上,我为此使用了计时器,这是滴答程序代码:

    private void timer1_Tick(object sender, EventArgs e)
    {
        statmessage();

        int i = listBox1.SelectedItems.Count + 1;

      if (i < 1)
        {
            var exp = (EItem)listBox1.Items[i];
            var timeVisible = DateTime.Now - exp.Added;
            if (timeVisible.TotalSeconds > 5)
                if (counter == 100)
                {

                SendMessage();
                counter = counter - 1;
                ++i;
                }
                else if (counter <= 0)
                {

                statmessage();
                }

        }

    }
  • 非常感谢您的反馈,这将有助于改善您的担忧,非常感谢

1 个答案:

答案 0 :(得分:0)

队友,我将显示我对代码的更改,如果有问题,请重新编写,谢谢。

        private void timer1_Tick(对象发送者,EventArgs e)         {             statmessage();             int i = listBox1.SelectedItems.Count +1;             做             {                 var exp =(EItem)listBox1.Items [i];                 var timeVisible = DateTime.Now-exp.Added;                 如果(timeVisible.TotalSeconds> 5)                     如果(计数器== 100)                     {                         发信息();                         计数器=计数器-1;                         ++ i;                     }                     否则,如果(计数器