亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

節假日批量設置的C#.NET程序代碼參考

發布時間:2020-07-26 19:43:24 來源:網絡 閱讀:708 作者:jirigala 欄目:編程語言

例如我們在設置審批流程時,往往需要設置限制時限,例如2天內審核好等等,這時候會遇到休息日,需要把休息日去掉,當然有各種各樣復雜的情況,我們先把問題想得簡單一些,就按普通的休息一整天,全公司都統一休息的方式。

 節假日批量設置的C#.NET程序代碼參考

下面是程序的運行效果,主要是把12個月展示在上面,有時候費力一些,黑色部分是表示休息,本想用紅色顯示,但是微軟默認是黑色的,沒能搞定

 節假日批量設置的C#.NET程序代碼參考

實現代碼可以參考

//--------------------------------------------------------------------
// All Rights Reserved ,Copyright (C) 2012 , Hairihan TECH, Ltd. .
//--------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using DotNet.Business;
using DotNet.Utilities;
namespace DotNet.WinForm
{
    public partial class FrmHolidays : BaseForm
    {
        public FrmHolidays()
        {
            InitializeComponent();
        }
        private void GetYearList()
        {
            // 綁定最近幾年就可以了
            for (int i = DateTime.Now.Year - 3; i < DateTime.Now.Year + 2; i++)
            {
                this.cmbYear.Items.Add(i.ToString());
            }
            // 今年為默認選中
            this.cmbYear.SelectedIndex = this.cmbYear.Items.Count - 2;
        }
        private void FrmHolidays_Load(object sender, EventArgs e)
        {
            this.GetYearList();
        }
        /// <summary>
        /// 獲取節假日
        /// </summary>
        /// <param name="holiday">當前點中了某個日期了</param>
        private void GetYearDas(string holiday = null)
        {
            BaseHolidaysManager manager = new BaseHolidaysManager(this.UserInfo);
            if (!string.IsNullOrEmpty(holiday))
            {
                int returnValue = manager.Delete(new KeyValuePair<string, object>(BaseHolidaysEntity.FieldHoliday, holiday));
                if (returnValue == 0)
                {
                    manager.AddHoliday(holiday, false);
                }
            }
            int year = int.Parse(this.cmbYear.SelectedItem.ToString());
            this.mc.Enabled = false;
            if (this.mc.MinDate.Year <= year)
            {
                this.mc.MaxDate = new DateTime(year, 12, 31);
                this.mc.MinDate = new DateTime(year, 1, 1);
            }
            else
            {
                this.mc.MinDate = new DateTime(year, 1, 1);
                this.mc.MaxDate = new DateTime(year, 12, 31);
            }
            this.mc.Enabled = true;
                   
            // 把這一年的變粗的都加上來,這個是后臺處理程序,所以沒考慮數據庫性能的問題,每次都讀取了一下,有需要時可以改進一下
            string where = BaseHolidaysEntity.FieldHoliday + " >= '" + this.mc.MinDate.ToString(BaseSystemInfo.DateFormat) + "'" +
                " AND " + BaseHolidaysEntity.FieldHoliday + " <= '" + this.mc.MaxDate.ToString(BaseSystemInfo.DateFormat) + "'";
            List<BaseHolidaysEntity> listEntity = manager.GetList<BaseHolidaysEntity>(where);
            List<DateTime> boldedDates = new List<DateTime>();
            foreach (BaseHolidaysEntity entity in listEntity)
            {
                boldedDates.Add(DateTime.Parse(entity.Holiday));
            }
            this.mc.BoldedDates = boldedDates.ToArray();
        }
        private void cmbYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            // 從數據庫里讀取出來節假日的設置
            GetYearDas();
        }
        private void btnInitializeYear_Click(object sender, EventArgs e)
        {
            BaseHolidaysManager manager = new BaseHolidaysManager(this.UserInfo);
            // 這里把周日,知道的5.1. 10.1 等節日進行休息日設置
            int year = int.Parse(this.cmbYear.SelectedItem.ToString());
            DateTime startDate = new DateTime(year, 1, 1);
            while (startDate.Year == year)
            {
                // 周六周日是默認休息日
                if (startDate.DayOfWeek == DayOfWeek.Saturday || startDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    manager.AddHoliday(startDate.ToString(BaseSystemInfo.DateFormat));
                }
                // 5.1 是休息日
                // 10.1 是休息日
                startDate = startDate.AddDays(1);
            }
            // 從數據庫里讀取出來節假日的設置
            GetYearDas();
        }
        private void mc_DateSelected(object sender, DateRangeEventArgs e)
        {
            GetYearDas(this.mc.SelectionStart.ToString(BaseSystemInfo.DateFormat));
        }
    }
}

還有幾個函數相關函數,可以參考一下

//-----------------------------------------------------------------
// All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd.
//-----------------------------------------------------------------
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
namespace DotNet.Business
{
    using DotNet.Utilities;
    /// <summary>
    /// BaseHolidaysManager
    /// 節假日表
    ///
    /// 修改記錄
    ///
    ///     2012.12.24 版本:1.0 JiRiGaLa 創建主鍵。
    ///    
    ///
    /// 版本:1.0
    /// </summary>
    /// <author>
    ///        <name>JiRiGaLa</name>
    ///        <date>2012.12.24</date>
    /// </author>
    /// </summary>
    public partial class BaseHolidaysManager : BaseManager //, IBaseRoleManager
    {
        /// <summary>
        /// 計算截至日期為幾號
        /// </summary>
        /// <param name="currentDay">當前日期</param>
        /// <param name="days">幾個工作日</param>
        /// <returns>應該在幾號完成 yyyy-MM-dd</returns>
        public static string CalculateDays(DateTime currentDate, int days)
        {
            // 計算有幾個節假日
            string where = BaseHolidaysEntity.FieldHoliday + " >= '" + currentDate.ToString(BaseSystemInfo.DateFormat) + "'";
            BaseHolidaysManager manager = new DotNet.Business.BaseHolidaysManager();
            List<BaseHolidaysEntity> listEntity = manager.GetList<BaseHolidaysEntity>(where);
            DateTime endDay = currentDate;
            bool find = false;
            for (int i = 0; i < days; i++)
            {
                find = false;
                // 若這個日期是節假日,需要繼續加一天
                find = listEntity.Count(entity => !string.IsNullOrEmpty(entity.Holiday) && entity.Holiday.Equals(endDay.ToString(BaseSystemInfo.DateFormat), StringComparison.OrdinalIgnoreCase)) > 0;
                while (find)
                {
                    // 若這個日期是節假日,需要繼續加一天
                    endDay = endDay.AddDays(1);
                    find = listEntity.Count(entity => !string.IsNullOrEmpty(entity.Holiday) && entity.Holiday.Equals(endDay.ToString(BaseSystemInfo.DateFormat), StringComparison.OrdinalIgnoreCase)) > 0;
                }
            }
            // 計算
            return endDay.ToString(BaseSystemInfo.DateFormat);
        }
        /// <summary>
        /// 計算截至日期為幾號
        /// </summary>
        /// <param name="currentDay">當前日期 yyyy-MM-dd</param>
        /// <param name="days">幾個工作日</param>
        /// <returns>應該在幾號完成</returns>
        public static string CalculateDays(string currentDate, int days)
        {
            DateTime dateTime = DateTime.Parse(currentDate);
            return CalculateDays(dateTime, days);
        }
        /// <summary>
        /// 前日期與指定一個日期之間的, 工作日天數對吧?
        /// </summary>
        /// <param name="currentDate">開始日期 yyyy-MM-dd</param>
        /// <param name="endDate">結束日期 yyyy-MM-dd</param>
        /// <returns>工作日天數</returns>
        public static int CalculateWorkDays(string currentDate, string endDate)
        {
            int returnValue = 0;
            // 計算這2個日期相差幾天
            DateTime dateTime1 = DateTime.Parse(currentDate);
            DateTime dateTime2 = DateTime.Parse(endDate);
            TimeSpan timeSpan = new TimeSpan(dateTime2.Ticks).Subtract(new TimeSpan(dateTime1.Ticks)).Duration();
            returnValue = timeSpan.Days;
            // 計算有幾個節假日
            string where = BaseHolidaysEntity.FieldHoliday + " >= '" + currentDate + "'" +
                " AND " + BaseHolidaysEntity.FieldHoliday + " <= '" + endDate + "'";
            BaseHolidaysManager manager = new DotNet.Business.BaseHolidaysManager();
            List<BaseHolidaysEntity> listEntity = manager.GetList<BaseHolidaysEntity>(where);
            // 在數據庫里找還有幾個工作日
            returnValue = returnValue - listEntity.Count;
            return returnValue;
        }
    }
}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

洪湖市| 上犹县| 田林县| 霸州市| 临朐县| 彭山县| 崇义县| 霞浦县| 和林格尔县| 龙游县| 百色市| 盘山县| 囊谦县| 岳阳县| 韩城市| 石城县| 安阳市| 尖扎县| 页游| 泗洪县| 西宁市| 东乌珠穆沁旗| 合川市| 黔西县| 马公市| 富源县| 宜君县| 宜章县| 准格尔旗| 闸北区| 房产| 泽库县| 宜阳县| 长乐市| 西宁市| 金沙县| 杭锦旗| 荔浦县| 五大连池市| 西乡县| 霍林郭勒市|