【问题标题】:Add item to listbox and then send email to target recipient将项目添加到列表框,然后向目标收件人发送电子邮件
【发布时间】:2019-06-23 13:15:50
【问题描述】:

大家好,我是 c# 中的半中级人员,我需要有关上述标题的代码方面的帮助,实际上它不适用于我实现的代码。但这里是这样的场景,如果添加了列表框项,则所述添加的目标将在我声明的秒/秒内向特定的目标电子邮件地址发送电子邮件。

这是我的代码和程序。

1.) statmessage的过程:

public void 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.)形式:

私有 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();
                }

        }

    }
  • 非常感谢您的反馈,这将有助于改善上述问题,非常感谢您

【问题讨论】:

  • 您的实际问题是什么?像``` int i = listBox1.SelectedItems.Count + 1; if (i
  • 感谢您的回答。实际上,关于 timer_tick 程序代码。列表框中目标添加事务中电子邮件的声明秒数不起作用。如何更正这些语法?
  • 你的 if 条件永远不能成立,就是说 i 小于 1,列表至少可以为零,但是你给它加 1,所以它永远不会满足小于 1 的条件
  • 感谢您的建议,实际上我将 if 条件更改为 (i
  • you want i > 0 if do i

标签: c# listbox email-validation


【解决方案1】:

朋友,我会显示我的代码更改,如果有问题请重新编写,谢谢..

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

【讨论】:

    猜你喜欢
    • 2019-03-04
    • 1970-01-01
    • 2021-07-19
    • 2012-05-18
    • 1970-01-01
    • 2012-09-24
    相关资源
    最近更新 更多