在两个日期之间绘画 [英] painting between two dates

查看:105
本文介绍了在两个日期之间绘画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在两个日期之间,我想涂成红色.示例代码如下.

Hi,
between two dates, I want to paint red. sample code as follows.

for (int i = 1; i < 32; ++i)
            {
                btn = new Button();
                btn.Size = new Size(30, haftaLENGHT);
                btn.Text = i.ToString();
                temmuzflowlayout.Controls.Add(btn);
                btn.FlatStyle = FlatStyle.Popup;
                for (int k = 0; k < dataGridView1.RowCount; k++)
                {
                    tarih = dataGridView1.Rows[k].Cells[4].Value.ToString();
                    tarih2 = dataGridView1.Rows[k].Cells[5].Value.ToString();

                    if (tarih.ToString() != "")
                    {
                        if (tarih.Substring(6, 4) == m_yıl.Text)
                        {
                            if (tarih.Substring(3, 2) == "07")
                            {
                                if ((tarih.Substring(0, 2) == btn.Text)||(tarih2.Substring(0,2)==btn.Text))
                                {
                                    btn.BackColor = Color.Red;
                                }
                            }
                        }
                    }
                }
            }

推荐答案

假设从数据集中检索到的两个值是日期,这就是我要这样做的方式(未经测试的代码):

Assuming the two values being retrieved from the dataset are dates, this is the way I''d do it (untested code):

for (int ...)
{
    tarih1 = dataGridView1.Rows[k].Cells[4].Value.ToString();
    tarih2 = dataGridView1.Rows[k].Cells[5].Value.ToString();
    DateTime tarihDate1;
    DateTime tarihDate2;
    if (DateTime.TryParse(tarih1, out tarihDate1) && DateTime.TryParse(tarih2, out out tarihDate2))
    {
        // we have valid dates, so we can continue processing)
        // I have no idea what criteria causes the button to be red, but 
        // here's some sample code that uses the parsed dates - If the 
        // dates are within 7 days of each other, the button background 
        // is changed to red
        TimeSpan span = tarihDate2 - tarihDate1;
        if (span.Days == 7)
        {
            btn.BackColor = Color.Red;
        }
    }
}



继续并进行编码.



Go forth, and code.


DateTime dt = wherever you get this from,
  startTime = the start of the time period,
  endtime = the end of the time period;
if((dt >= startTime) && (dt < endTime)) myButton.BackColor = Color.Red;



您的问题还不清楚,您的代码还不够清晰,无法确定您到底要尝试什么,但这就是您如何在C#中测试日期.



Your question is very unclear and your code is not clear enough to work out what exactly you are trying, but that is how you test dates in C#.


这篇关于在两个日期之间绘画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆