工作日历设置-webform

1.工作日设置

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Cannder.aspx.cs" Inherits="SqliteDemo.Demo.Cannder" %>





    
    工作日设置
    
    
    


    
今天是:<%=string.Format("{0:yyyy年MM月dd日}", DateTime.Now) %> 当前月:<%=string.Format("{0:yyyy年MM月}", DateTime.Now) %>
星期一 星期二 星期三 星期四 星期五 星期六 星期天
aspx页面
public partial class Cannder : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        [WebMethod]
        public static string GetCurrentYeayAllHoliday(string year)
        {
            return FindCurrentYeayAllHoliday(Convert.ToInt32(year));
        }

        protected static string FindCurrentYeayAllHoliday(int year)
        {
            //JjrszbServiceBase serviceBase = new JjrszbServiceBase();
            int count;
            //var list = serviceBase.Find(string.Format("JJRSJ > to_date('{0}-11-30 23:59:59','yyyy-mm-dd hh24:mi:ss') AND JJRSJ < to_date('{1}-04-01 00:00:00','yyyy-mm-dd hh24:mi:ss')", year - 1, year + 1), "JJRSJ", out count);

            var dateSb = new StringBuilder();
            dateSb.Append("{");

            //if (list != null && list.Count > 0)
            //{
            //    foreach (var item in list)
            //    {
            //        if (dateSb.Length > 1)
            //            dateSb.Append(",");
            //        dateSb.AppendFormat("\"{0:yyyy_MM_dd}\":\"{1}\"", item.JJRSJ, item.JJRLB);
            //    }
            //}

            dateSb.Append("}");

            return dateSb.ToString();
            //return "";
        }
    }
.cs页面
/*
*    Start Date    : 2012-4-30 00:29:45
*  Update Date    : 2012-4-30 00:29:45
*  Update Date : 2012-5-2  17:37:50
*  Comment     : 对扩展函数处理 throw new TypeError() 的使用
*    Author        : qingbo.guo
*    
*    作用            : 字符串扩展类
*/


/* 
*    格式化字符串 
*/
if (!String.prototype.format)
    String.prototype.format = function () {
        var args = arguments && arguments[0] instanceof Array ? arguments[0] : arguments;
        return this.replace(/{(\d+)}/g, function (_search, _replace, _index, _string) {
            //_search  搜索的结果 要被替换的字符串
            //_replace 将被替换成的字符串
            //_index   搜索结果 要被替换的字符串索引
            //_string  被操作的原字符串
            return args[_replace];
        });
    };
/* 
*    去除所有空格 
*    String.prototype.trimAll = function () {
*        return this.replace(/(^\s*)|(\s*)|(\s*$)/g, "");
*    };
*/
if (!String.prototype.trimAll)
    String.prototype.trimAll = function () {
        if (this == null) //throw new TypeError() 抛出一个异常
            throw new TypeError('String.prototype.trimAll called on null or undefined');
        return String.prototype.replace.call(this, /(^\s+)|(\s+)|(\s+$)/g, '');
    };
/* 
*    去两边空格 
*    String.prototype.trimAll = function () {
*        return this.replace(/(^\s*)|(\s*$)/g, "");
*    };
*/
if (!String.prototype.trim)
    String.prototype.trim = function () {
        if (this == null) //throw new TypeError() 抛出异常
            throw new TypeError('String.prototype.trimAll called on null or undefined');
        return this.replace(/(^\s*)|(\s*$)/g, "");
    };
    
string.js
#region 实体

        

        /// 
        /// 表名
        /// 
        public string TableName
        {
            get { return "JJRSZB"; }
        }
        
        /// 
        /// 主键名
        /// 
        public string PrimaryKey
        {
            get { return "JJRSZID"; }
        }

        
        /// _summary>
        /// 
        /// _/summary>
        public Double JJRSZID { get; set; }


        /// _summary>
        /// 
        /// _/summary>
        public DateTime JJRSJ { get; set; }


        /// _summary>
        /// 
        /// _/summary>
        public Double JJRLB { get; set; }



        #endregion
JjrszbBase实体类

2.获取工作日

/// 
        /// 计算从开始时间到x天之后出去休息日要多少天
        /// 
        /// 计算开始时间
        /// 多少天之后
        /// 
        public int IntervalNoJobDays(DateTime NowData, int IntervalDay)
        {
            int outCount;
             int countday =0;
             if (IntervalDay <= 0)
                 return 0;
            for (int i = 1; i >0;i++ )
            {
                NowData = NowData.AddDays(1);
                List list = Find(" to_char(jjrsj,'yyyy-MM-dd') = '"+NowData.ToString("yyyy-MM-dd")+"'","",out outCount);
                if (outCount > 0)
                {
                    if (list[0].JJRLB == 2)
                    {
                        countday++;
                    }
                }
                else
                { 
                    int weekday =(int)NowData.DayOfWeek;
                    if (!(weekday==0||weekday==6))
                        countday++;               
                }
                if (countday>= IntervalDay)
                    return i;
            } 
            return countday;
        
        }
        /// 
        /// 计算两时间段的工作日
        /// 
        /// 开始时间
        /// 结束时间
        /// 
        public int JobDayCount(DateTime beginDateTime, DateTime endDateTime)
        {
            TimeSpan ts1 = new TimeSpan(beginDateTime.Ticks);
            TimeSpan ts2 = new TimeSpan(endDateTime.Ticks);
            TimeSpan ts = ts1.Subtract(ts2).Duration();
            int days = ts.Days+1;
            int outCount;
            List list = Find("jjrsj>=to_date('" + beginDateTime.ToString("yyyy-MM-dd") + "','yyyy-MM-dd') and jjrsj<=to_date('" + endDateTime.ToString("yyyy-MM-dd") + "','yyyy-MM-dd')", "", out outCount);
            for (int i = 1; i <= ts.Days; i++)
            {
                DateTime time = beginDateTime.AddDays(i);
                JjrszbBase listJrisz = list.Find(o => o.JJRSJ.ToString("yyyy/MM/dd").Equals(time.ToString("yyyy/MM/dd")));
                if (listJrisz != null && listJrisz.JJRSZID > 0 && listJrisz.JJRLB == 3)
                {
                    days--;
                }
                else
                { 
                 int weekday =(int)time.DayOfWeek;
                 if ((weekday == 0 || weekday == 6))
                     days--;
                }
            }
            return days;
        }
获取工作日
/// 
    /// 获取工作日天数
    /// 
    /// 
    /// 
    /// 
    public static int GetWorkingdaysNum(DateTime startDate, DateTime endDate)
    {
        //取两个时间的Date
        startDate = startDate.Date;
        endDate = endDate.Date;
        int workingdays = 0;
        //获取两个日期之间的特殊时间
        JjrszbServiceBase serviceBase = new JjrszbServiceBase();
        //List list = serviceBase.Find("", "", out count);
        //获取两个时间内的时间设置
        var list = from special in serviceBase.GetAll() where special.JJRSJ >= startDate && special.JJRSJ <= endDate select special;
        while (startDate <= endDate)
        {
            var day = startDate.DayOfWeek.ToString();
            //表示是周末
            if (startDate.DayOfWeek == DayOfWeek.Sunday || startDate.DayOfWeek == DayOfWeek.Saturday)
            {
                //查询周末是否上班
                if (list.Count(p => p.JJRSJ == startDate && p.JJRLB == 2) > 0)
                    workingdays++;
            }
            else
            {
                //查询工作日是否休息
                if (list.Count(p => p.JJRSJ == startDate && p.JJRLB == 3) == 0)
                    workingdays++;

            }
            //判断是否是周末
            startDate = startDate.AddDays(1);
        }


        return workingdays;
    }
获取工作日天数

 工作日历设置-webform_第1张图片

读取工作日休息日未全自动实现。

设置工作日,休息日没有实现保存到数据库,请自行修改保存相关的内容

 

转载于:https://www.cnblogs.com/lovable/p/9187557.html

你可能感兴趣的:(c#,json,xhtml)