1. 程式人生 > 其它 >時間日期插入和判斷工作日

時間日期插入和判斷工作日

  public bool judgeWorkDay(DateTime day, H3.IEngine engine)
    {
        List < string > allholidy= getAllHoliday(engine);
        string dayTime = day.ToString("yyyyMMdd");
        //判斷是否是工作日
        if(allholidy.Contains(dayTime))
        {
            return false;
        }
        return true;
    }

    public List < string > getAllHoliday(H3.IEngine engine)
    {
        string sql = " SELECT * FROM  i_D002033holiday ";
        List < string > allholidy = new List<string>();
        System.Data.DataTable dt = engine.Query.QueryTable(sql, null);
        if(dt.Rows.Count != 0)
        {
            for(int i = 0;i < dt.Rows.Count; i++) {
                string yearMonth = dt.Rows[i]["yearMonth"] + string.Empty;
                string day = dt.Rows[i]["day"] + string.Empty;
                allholidy.Add(yearMonth + day);
            }
        }
        return allholidy;
    }

  

        if(actionName == "Submit" && this.Request.BizObject["Checkintype"] + string.Empty == "上班打卡")
        {
            //考勤明細的構建schema
            H3.DataModel.BizObjectSchema schema = this.Request.Engine.BizObjectManager.GetPublishedSchema("D002033attendanceDetail");
            //new 一個考勤明細的物件
H3.DataModel.BizObject targetBo = new H3.DataModel.BizObject(this.Engine, schema, this.Request.UserContext.UserId); //獲取到考勤打卡的物件資訊 H3.DataModel.BizObject targetBo2 = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, "D002033Clockin", this.Request.BizObjectId, false
); //申請人 targetBo["employees"] = targetBo2["Signinperson"] + string.Empty; DateTime dtNow = Convert.ToDateTime(targetBo2["Checkinperiod"] + string.Empty); //擷取當前日期為時分格式 string now = dtNow.Year + "/" + dtNow.Month + "/" + dtNow.Day; //申請日期 targetBo["dateTime"] = now + string.Empty; //上班時間 targetBo["workTime"] = targetBo2["Checkinperiod"] + string.Empty; DateTime Checkinperiods = Convert.ToDateTime(targetBo2["Checkinperiod"]); if(!judgeWorkDay(Checkinperiods, this.Engine)) { targetBo["workhours"] = 0; targetBo["totalTime"] = 0; } else { targetBo["workhours"] = 8; targetBo["totalTime"] = 8; } //目標表單建立 targetBo.Create(); }
 if(switchOT && Checkintype == "下班打卡")//&& 
                {
                    // string onTimeSelect = masterBo["onTimeSelect"] + string.Empty;
                    // 工作日加班開始時間
                    DateTime swo = DateTime.Parse(Checkinperiod.Year + "/" + Checkinperiod.Month + "/" + Checkinperiod.Day + " 18:00:00");
                    // if(!string.IsNullOrEmpty(onTimeSelect))
                    // {
                    if(!judgeWorkDay(Checkinperiod, this.Engine))
                    {
                        // H3.DataModel.BizObject onTimeBo = H3.DataModel.BizObject.Load(this.Request.UserContext.UserId, this.Engine, this.Request.SchemaCode, onTimeSelect, false);
                        //節假日加班開始時間
                        swo = Convert.ToDateTime(Checkinperiod.Year + "/" + Checkinperiod.Month + "/" + Checkinperiod.Day + " 09:00:00");
                    }
後端,動態自動設定打卡狀態 
if(actionName == "GetList") { // 獲取本主表 // H3.DataModel.BizObject childBoArr = this.Request.BizObject; //獲取當前日期 DateTime dtNow = Convert.ToDateTime(this.Request["CheckinperiodBy"] + string.Empty); //擷取當前日期為時分格式 string now = dtNow.Hour + ":" + dtNow.Minute; //當前時間 DateTime dt1 = Convert.ToDateTime(now); response.ReturnData = new Dictionary<string, object>(); DateTime dtm1 = Convert.ToDateTime("06:00"); DateTime dtm2 = Convert.ToDateTime("12:00"); DateTime dtn1 = Convert.ToDateTime("12:01"); DateTime dtn2 = Convert.ToDateTime("23:59"); if(DateTime.Compare(dt1, dtm1) > 0 && DateTime.Compare(dt1, dtm2) < 0) { // childBoArr["Checkintype"] = "上班打卡"; // childBoArr.Update(); response.ReturnData.Add("result", 1); } else if(DateTime.Compare(dt1, dtn1) > 0 && DateTime.Compare(dt1, dtn2) < 0) { // childBoArr["Checkintype"] = "下班打卡"; // childBoArr.Update(); response.ReturnData.Add("result", 2); } }
  // 載入事件
    OnLoad: function() {
        // _this.Checkinperiod.BindChange("onChange",function(data){
        //     var dtNow=_this.Checkinperiod.GetValue();
        //     _this.Checkintype.SetValue();
        // })
        judgeTime();
        _this.Checkinperiod.BindChange( "OnChange", function( da ) {
            judgeTime();
        })
function judgeTime() {
    $.SmartForm.PostForm( "GetList", { CheckinperiodBy: _this.Checkinperiod.GetValue() }, function( data ) {
        debugger
        if( data != undefined ) {
            var result = data.ReturnData[ "result" ];
            // alert( result );
            if( result == 1 ) {
                _this.Checkintype.SetValue( "上班打卡" );
            } else if( result == 2 ) {
                _this.Checkintype.SetValue( "下班打卡" );
            }
        }
    })
氚雲資料預設顯示日期所有格式,如果要用日期查詢,則目標表要擷取日期格式
string
F0000006 = this.Request.BizObject["F0000006"] + string.Empty;//名字 string F0000003 = this.Request.BizObject["F0000003"] + string.Empty;//下班時間 DateTime dtNow = Convert.ToDateTime(this.Request.BizObject["F0000003"] + string.Empty); //擷取當前日期為時分格式 string now = dtNow.Year + "/" + dtNow.Month + "/" + dtNow.Day + " 00:00:00"; double F0000004 = Convert.ToDouble(this.Request.BizObject["F0000004"] + string.Empty);//時長 //考勤明細的構建schema H3.DataModel.BizObjectSchema schema = this.Request.Engine.BizObjectManager.GetPublishedSchema("D002033attendanceDetail"); //new 一個庫存單的物件 H3.DataModel.BizObject targetBo = new H3.DataModel.BizObject(this.Engine, schema, this.Request.UserContext.UserId); string sqlselect = "select * from i_D002033attendanceDetail where dateTime = '" + now + "' and employees='" + F0000006 + "'"; System.Data.DataTable tableSelect = this.Engine.Query.QueryTable(sqlselect, null);