zoukankan      html  css  js  c++  java
  • 一个广告位的三种状态的判断

               需求分析:有一个广告位,后台添加。需要实现对各个广告期限的判断(一个周期为两个月,距离截止日期15天将予以提醒),因此会有未过期、将过期、和已过期的三种状态。前台页面每次进入时执行该方法,后台进入前也执行该方法。

               多重if else的判断,简单的实现该功能。

                

            private void check()
            {
                DateTime nowtime = DateTime.Now;
                string sql = "select pubDate,enddate,zsate,id from [K_U_VaulAdd]";
                DataTable dt = KingTop.Common.InfoHelper.ExecuteSQL(sql);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DateTime dateEnd = DateTime.Parse(dt.Rows[i]["enddate"].ToString());
    
                    if (nowtime < dateEnd)
                    {
                        if (nowtime >= dateEnd.AddDays(-15) && nowtime < dateEnd)
                        {
                            string sqlUp = "update [K_U_VaulAdd] set Zsate=1 where id=" + dt.Rows[i]["id"] + "";
    
                            int M = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlUp, null);
                        }
                        else
                        {
                            string sqlUp = "update [K_U_VaulAdd] set Zsate=0 where id=" + dt.Rows[i]["id"] + "";
    
                            int N = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlUp, null);
    
                        }
    
                    }
                    else
                    {
                        string sqlUp = "update [K_U_VaulAdd] set Zsate=2 where id=" + dt.Rows[i]["id"] + "";
                        int j = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlUp, null);
    
                    }
                }
            }
    

      

             简要分析:以当前日期为标准,使用截止日期与之对比。

             当前日期等于或大于截止日期为过期  nowtime>=enddate.Addday(-15)    sate=2

              若不符合上述的条件,几位将过期   sate=1

             当前日期小于截止日期为未过期        nowtime<enddate                         返回为空(默认值为未过期 sate=0)          

              

              仅供参考

    以上文章由本人收集整理进行撰写,版权归属博客园及本人。欢迎转载和引用,但必须在转载和引用的开头或来源标注博客名称和该篇文章的链接地址。
  • 相关阅读:
    samba linux windows 请联系管理员
    centos chrome
    centos6.5 中文
    Hibernate 中update hql语句
    嵌入式Linux应用程序开发环境搭建记录
    JDK-windows7环境变量配置-亲测版本 以及HelloWorld
    windows tcp端口映射或端口转发
    VMWare Workstation:局域网PC连接虚拟机里的远程桌面或端口
    正则提取文本中的颜色值 #xxxx,不严谨版本
    Python 2.7.3 urllib2.urlopen 获取网页出现乱码解决方案
  • 原文地址:https://www.cnblogs.com/whitehouse/p/2410713.html
Copyright © 2011-2022 走看看