如何使用if else条件和时间跨度值触发消息框?

时间:2017-08-28 07:51:09

标签: c# arrays if-statement timespan

我有这段代码

*开始时间是另一个DateTime.now

* timeSinceStart是timeSpan的数组

*我相信for循环让我能够为时间跨度创建和存储许多值并更新listview项目(请参阅下面的链接以获取表单的照片)

* f.ToString()默认为60(整数)

*图片中的MH列向上计数,例如1 2 3 4 5 6等等

private void timer2_Tick(object sender, EventArgs e)
    {

        for (int w = 0; w < listView1.Items.Count; w++)
        {
            timeSinceStart[w] = DateTime.Now - startTime[w];
            listView1.Items[w].SubItems[6].Text = (timeSinceStart[w].TotalSeconds.ToString());
            if (f.ToString() == listView1.Items[w].SubItems[6].Text)
            { 
                MessageBox.Show("dedede");
            }
            else
            {
                label3.Text = timeSinceStart[w].TotalSeconds.ToString();
            }
        }

我真的不能弹出消息框,而且,timepan值有十进制值,是否有连接为什么if条件没有触发?

我尝试将timepan转换为datetime并在if else条件下使用datetime和timespan,它似乎也无法正常工作。

这是我所说的图片:

here is the picture as i was saying.

编辑* 我有另一种形式,让用户输入一个整数和一个包含&#34;小时&#34;的组合框。 &#34; Minute&#34;。

这是它包含的代码:

   private void button1_Click(object sender, EventArgs e)
    {
        if (textBox1.Text == "")
        {
            MessageBox.Show("Please Indicate How Many Minutes/Hours.");
        }
        else
        {
            string desu = textBox1.Text;
            int temp = 0;
            if (int.TryParse(desu, out temp))
            {
                if (comboBox1.Text == "Hours")
                {
                    //hours to seconds
                    time = temp * 3600;
                    eta = desu + " Hours";
                    sot = temp;
                    this.Close();
                }
                else if (comboBox1.Text == "Minutes")
                {
                    //minutes to seconds
                    time = temp * 60;
                    eta = desu + " Minutes";
                    sot = temp;
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Please enter a valid integer");
            }
        }
    }

然后我传递&#34; time&#34;的值进入上述形式

 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        ETA_Input frm = new ETA_Input(this);
        frm.ShowDialog();
        if (frm.time != 0)
        {
            string name = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            int deku = Int32.Parse(name);
            string constring = "server=localhost;database=dbhorizon;uid=root;password=1234";
            string Query = "update tblUserIdd set User_Available = 'Ongoing' where User_ID='" + deku + "' ";

            MySqlConnection conDatabase = new MySqlConnection(constring);
            MySqlCommand cmdDatabase = new MySqlCommand(Query, conDatabase);
            MySqlDataReader myReader;

            conDatabase.Open();
            myReader = cmdDatabase.ExecuteReader();


            string id = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            string naem = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            string field = dataGridView1.CurrentRow.Cells[2].Value.ToString();



            f = frm.time;




            if (stdex == 0)
            {
                startTime[stdex] = DateTime.Now;

                stdex++;
            }
            else if (stdex >= 1)
            {
                startTime[stdex] = DateTime.Now;
                stdex++;
            }


            secondss = string.Format("{0:t}", DateTime.Now);


            string[] row = { id, naem, field, secondss, frm.eta,custb, f.ToString()  };
            var listViewItem = new ListViewItem(row);
            listView1.Items.Add(listViewItem);

            dgvref();
        }

    }

这里。

0 个答案:

没有答案
相关问题