/// <summary>
        /// 解析公式
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="relTaskId"></param>
        /// <param name="formulaParam"></param>
        /// <returns></returns>
        public string PatchAnalysisFormula(int taskId, string formulaParam)
        {
            try
            {
                var strOperate = "";
                if (!String.IsNullOrEmpty(formulaParam))
                {
                    //var desTask = dataOp.FindOneByKeyVal("XH_DesignManage_Task", "taskId", taskId.ToString());
                    var desTask = taskList.Where(c => c.Int("taskId") == taskId).FirstOrDefault();
                    if (desTask != null)
                    {
                        var formulaObj = new FormulaObject(formulaParam.ToUpper());
                        formulaObj.taskList = taskList;
                        formulaObj.ConvertExp();
                        double   value        = formulaObj.CalcValue();
                        DateTime tempDateTime = formulaObj.date.HasValue ? formulaObj.date.Value : new DateTime(1900, 1, 1);
                        tempDateTime = tempDateTime.AddDays(value);
                        switch (formulaObj.OperDateType.ToLower())
                        {
                        case "s":
                            // dataOp.Update("XH_DesignManage_Task", "db.XH_DesignManage_Task.findOne({'taskId':'" + taskId + "'})", "curStartData=" + tempDateTime.ToString("yyyy-MM-dd"));
                            desTask.Set("curStartData", tempDateTime.ToString("yyyy-MM-dd"));
                            var updateValueBson = new BsonDocument();
                            updateValueBson.Add("curStartData", tempDateTime.ToString("yyyy-MM-dd"));
                            var udpateStartDate = new StorageData()
                            {
                                Document = updateValueBson, Type = StorageType.Update, Name = "XH_DesignManage_Task", Query = Query.EQ("taskId", taskId.ToString())
                            };
                            updateBsonStorage.Add(udpateStartDate);
                            break;

                        case "e":
                            //  dataOp.Update("XH_DesignManage_Task", "db.XH_DesignManage_Task.findOne({'taskId':'" + taskId + "'})", "curEndData=" + tempDateTime.ToString("yyyy-MM-dd"));
                            desTask.Set("curEndData", tempDateTime.ToString("yyyy-MM-dd"));
                            var updateBson = new BsonDocument();
                            updateBson.Add("curEndData", tempDateTime.ToString("yyyy-MM-dd"));
                            var udpateEndDate = new StorageData()
                            {
                                Document = updateBson, Type = StorageType.Update, Name = "XH_DesignManage_Task", Query = Query.EQ("taskId", taskId.ToString())
                            };
                            updateBsonStorage.Add(udpateEndDate);
                            break;
                        }
                        strOperate = formulaObj.OperDateType;
                    }
                }
                return(strOperate);
            }
            catch (Exception ex)
            {
                return("");
            }
        }
Beispiel #2
0
        /// <summary>
        /// 递归检测循环
        /// </summary>
        /// <param name="strOperate"></param>
        /// <param name="strOperateList"></param>
        private void CheckClosedLoop(string strOperate, ref List <string> strOperateList)
        {
            List <BsonDocument> formulaList = dataOp.FindAll("XH_DesignManage_TaskFormula").Where(t => t.String("relTaskId").Contains(strOperate)).ToList();

            foreach (var formula in formulaList)
            {
                if (!String.IsNullOrEmpty(formula.String("formulaParam")))
                {
                    FormulaObject formulaObj = new FormulaObject(formula.String("formulaParam"));
                    formulaObj.ConvertExp();
                    if (!String.IsNullOrEmpty(formulaObj.OperDateType) && formulaObj.TaskId != 0)
                    {
                        strOperateList.Add(formulaObj.OperDateType + formulaObj.TaskId);
                        CheckClosedLoop(formulaObj.OperDateType.ToString() + formulaObj.TaskId + ",", ref strOperateList);
                    }
                }
            }
        }
        /// <summary>
        /// 解析公式
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="relTaskId"></param>
        /// <param name="formulaParam"></param>
        /// <returns></returns>
        public string AnalysisFormula(int taskId, string formulaParam)
        {
            try
            {
                var strOperate = "";
                if (!String.IsNullOrEmpty(formulaParam))
                {
                    var desTask = dataOp.FindOneByKeyVal("XH_DesignManage_Task", "taskId", taskId.ToString());

                    if (desTask != null)
                    {
                        var formulaObj = new FormulaObject(formulaParam.ToUpper());
                        formulaObj.ConvertExp();
                        double   value        = formulaObj.CalcValue();
                        DateTime tempDateTime = formulaObj.date.HasValue ? formulaObj.date.Value : new DateTime(1900, 1, 1);
                        tempDateTime = tempDateTime.AddDays(value);
                        switch (formulaObj.OperDateType.ToLower())
                        {
                        case "s":
                            dataOp.Update("XH_DesignManage_Task", "db.XH_DesignManage_Task.findOne({'taskId':'" + taskId + "'})", "curStartData=" + tempDateTime.ToString("yyyy-MM-dd"));
                            break;

                        case "e":
                            dataOp.Update("XH_DesignManage_Task", "db.XH_DesignManage_Task.findOne({'taskId':'" + taskId + "'})", "curEndData=" + tempDateTime.ToString("yyyy-MM-dd"));
                            break;
                        }
                        strOperate = formulaObj.OperDateType;
                    }
                }
                return(strOperate);
            }
            catch (Exception ex)
            {
                return("");
            }
        }