//考勤打卡表单
using System; using System.Collections.Generic; using System.Text; using H3; public class D002033Clockin: H3.SmartForm.SmartFormController { public D002033Clockin(H3.SmartForm.SmartFormRequest request): base(request) { } protected override void OnLoad(H3.SmartForm.LoadSmartFormResponse response) { this.Request.BizObject["ProjectAssociations"] = "储能科技公司基建域多项目工作协同体系开发建设劳务辅助项目"; base.OnLoad(response); } protected override void OnSubmit(string actionName, H3.SmartForm.SmartFormPostValue postValue, H3.SmartForm.SubmitSmartFormResponse response) { 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); } } if(actionName == "Submit") { H3.DataModel.BizObject masterBo = this.Request.BizObject; if(!Convert.ToBoolean(masterBo["isOTed"])) { masterBo["isOTed"] = true; //下班时间 DateTime Checkinperiod = Convert.ToDateTime(masterBo["Checkinperiod"]); //获取是否按钮 bool switchOT = Convert.ToBoolean(masterBo["SwitchOT"]); string Checkintype = masterBo["Checkintype"] + string.Empty; 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(Checkinperiod > swo) { //获取D002033d77c757585ff46658b0465482e43fec7表单的表单结构对象 H3.DataModel.BizObjectSchema aSchema = Engine.BizObjectManager.GetPublishedSchema("D002033d77c757585ff46658b0465482e43fec7"); //new一个D002033d77c757585ff46658b0465482e43fec7表单的业务对象 H3.DataModel.BizObject aBo = new H3.DataModel.BizObject(this.Engine, aSchema, this.Request.UserContext.UserId); //设置业务对象的创建人为当前登录人 aBo["F0000006"] = masterBo["Signinperson"]; //加班开始时间 aBo["F0000002"] = swo; //加班结束时间 aBo["F0000003"] = Checkinperiod; //审批人 aBo["F0000005"] = "b1da064e-be77-4a1b-89a7-4b6abc4da1f3"; //加班时长 TimeSpan otTime = Checkinperiod - swo; aBo["F0000004"] = otTime.TotalHours; //设置业务对象数据为生效状态 // aBo.Status = H3.DataModel.BizObjectStatus.Effective; //设置流程id string instanceId = System.Guid.NewGuid().ToString(); if(string.IsNullOrEmpty(aBo.WorkflowInstanceId)) aBo.WorkflowInstanceId = instanceId; //将业务对象创建到数据库中,即创建到表名为i_D000001Account的表中 aBo.Create(); //激活流程 H3.Workflow.Instance.WorkflowInstance wfInstance = this.Engine.WorkflowInstanceManager.GetWorkflowInstance(aBo.WorkflowInstanceId); if(wfInstance == null) { //启动流程 string workItemID = string.Empty; string errorMsg = string.Empty; H3.Workflow.Template.WorkflowTemplate wfTemp = this.Engine.WorkflowTemplateManager.GetDefaultWorkflow(aBo.Schema.SchemaCode); this.Engine.Interactor.OriginateInstance(this.Request.UserContext.UserId, aBo.Schema.SchemaCode, wfTemp.WorkflowVersion, aBo.ObjectId, aBo.WorkflowInstanceId, H3.Workflow.WorkItem.AccessMethod.Web, true, string.Empty, true, out workItemID, out errorMsg); }//第七个参数 false/true 为是否提交流程操作 } else { response.Errors.Add("加班起始时间小于加班结束时间,请检查调整后再提交。"); } } } } base.OnSubmit(actionName, postValue, response); } //工作日和周末加班的方法 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; } }
前端代码
// 表单插件代码 var _this = this; $.extend( $.JForm, { // 加载事件 OnLoad: function() { // _this.Checkinperiod.BindChange("onChange",function(data){ // var dtNow=_this.Checkinperiod.GetValue(); // _this.Checkintype.SetValue(); // }) judgeTime(); _this.Checkinperiod.BindChange( "OnChange", function( da ) { judgeTime(); }) }, // 按钮事件 OnLoadActions: function( actions ) { }, // 提交校验 OnValidate: function( actionControl ) { return true; }, // 提交前事件 BeforeSubmit: function( action, postValue ) { }, // 提交后事件 AfterSubmit: function( action, responseValue ) { } }); 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( "下班打卡" ); } } }) }
加班申请表单