Пример #1
0
        public ResultModel SynchronousStatus(UserModel user, IModel model)
        {
            ResultModel result = new ResultModel();

            try
            {
                result = this.GetDataSource(user, model);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WorkFlow.Model.DataSource source = result.ReturnValue as NFMT.WorkFlow.Model.DataSource;
                if (source == null || source.SourceId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "工作流无对应任务可撤返";
                    return result;
                }

                source.Status = StatusEnum.已录入;

                result = this.Invalid(user, source);
                if (result.ResultStatus != 0)
                    return result;

                DAL.TaskDAL taskDAL = new TaskDAL();
                result = taskDAL.GetTaskByDataSourceId(user, source.SourceId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WorkFlow.Model.Task task = result.ReturnValue as NFMT.WorkFlow.Model.Task;

                task.Status = StatusEnum.已录入;
                result = taskDAL.Invalid(user, task);
                if (result.ResultStatus != 0)
                    return result;

            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            return result;
        }
Пример #2
0
        /// <summary>
        /// 请求回调,若通过,则判断该任务的所有附件是否都被审核。
        /// </summary>
        /// <param name="user"></param>
        /// <param name="source">数据源对象</param>
        /// <param name="isPass">是否通过。true表示通过;false表示不通过</param>
        /// <returns></returns>
        public ResultModel RequestCallBackUrl(UserModel user, DataSource source, bool isPass)
        {
            ResultModel result = new ResultModel();

            string msg = string.Empty;
            string callBackUrl = string.Empty;

            //设置URL
            if (isPass)
            {
                #region 若通过,则判断该任务的所有附件是否都被审核。

                TaskDAL taskDAL = new TaskDAL();
                result = taskDAL.GetTaskByDataSourceId(user, source.SourceId);
                if (result.ResultStatus != 0)
                    return result;

                Task task = result.ReturnValue as Task;
                if (task == null || task.TaskId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "获取任务失败";
                    return result;
                }

                //获取任务附件
                TaskAttachDAL taskAttachDAL = new TaskAttachDAL();
                result = taskAttachDAL.GetTaskAttachByTaskId(user, task.TaskId);
                if (result.ResultStatus != 0)
                    return result;

                List<TaskAttach> taskAttachs = result.ReturnValue as List<TaskAttach>;
                if (taskAttachs != null && taskAttachs.Any())
                {
                    //若存在任务附件,则判断是否全部被审核
                    result = taskAttachDAL.JudgeAllAttachsAudited(user, task.TaskId);
                    if (result.ResultStatus != 0)
                        return result;
                }

                #endregion

                msg = "审核通过";
                if (!string.IsNullOrEmpty(source.SuccessUrl))
                    callBackUrl = string.Format("{0}{1}", DefaultValue.NfmtSiteName, source.SuccessUrl);
                else
                    callBackUrl = "";
            }
            else
            {
                msg = "审核拒绝";
                if (!string.IsNullOrEmpty(source.RefusalUrl))
                    callBackUrl = string.Format("{0}{1}", DefaultValue.NfmtSiteName, source.RefusalUrl);
                else
                    callBackUrl = "";
            }

            //create post data
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string jsonData = serializer.Serialize(source);

            //create cookie
            CookieCollection col = new CookieCollection();

            if (HttpContext.Current.Request.Cookies != null)//判断条件后改为key=MK的cookie判断
            {
                for (int i = 0; i < HttpContext.Current.Request.Cookies.Count; i++)//each (System.Web.HttpCookie c in System.Web.HttpContext.Current.Request.Cookies)
                {
                    HttpCookie c = HttpContext.Current.Request.Cookies[i];
                    if (c.Domain == DefaultValue.Domain)
                    {
                        Cookie cookie = new Cookie();
                        cookie.Domain = c.Domain;
                        cookie.Expires = c.Expires;
                        cookie.Name = c.Name;
                        cookie.Path = c.Path;
                        cookie.Secure = c.Secure;
                        cookie.Value = c.Value;
                        cookie.HttpOnly = c.HttpOnly;

                        col.Add(cookie);
                    }
                }
            }
            else
            {
                //手动创建cookie
                //验证登录
            }
            CookieContainer container = new CookieContainer();
            container.Add(col);

            string resource = string.Format("source={0}&ispass={1}", jsonData, isPass.ToString());
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(callBackUrl);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            //request.ContentLength = Encoding.UTF8.GetByteCount(resource);
            request.CookieContainer = container;

            Stream requestStream = request.GetRequestStream();
            //System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(requestStream, Encoding.GetEncoding("utf-8"));
            StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.GetEncoding("GBK"));
            streamWriter.Write(resource);
            streamWriter.Close();

            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException ex)
            {
                response = (HttpWebResponse)ex.Response;
            }
            response.Cookies = container.GetCookies(response.ResponseUri);
            Stream responseStream = response.GetResponseStream();
            if (responseStream != null)
            {
                StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
                string retString = streamReader.ReadToEnd();
                streamReader.Close();
                responseStream.Close();

                result = serializer.Deserialize<ResultModel>(retString);
            }

            if (result.ResultStatus == 0)
            {
                //操作成功
                result.Message = string.Format("{0}成功", msg);
                result.ResultStatus = 0;
            }
            else
            {
                //操作失败
                result.ResultStatus = -1;
                result.Message = string.Format("{0}失败", msg);
            }

            return result;
        }