private bool LoadMyInfo(bool bShowSuccessfulPopup = false)
        {
            //加载数据
            UserInfo_API_Get uiToGet;

            try
            {
                uiToGet = WebApiClientHelper.DoJsonRequest <UserInfo_API_Get>(GlobalData.GetResUri(string.Format("usersinfo/{0}", GlobalData.CurrentUserName)), EnuHttpMethod.Get);
            }
            catch (ClientException ex)
            {
                Commands.ShowPopupAlert.Execute(new ShowPopupAlertParam {
                    AlertMessage = ex.Message, AlertType = EnuPopupAlertType.Error
                }, this);
                return(false);
            }

            UserInfo_VM ui_vm = Mapper.Map <UserInfo_VM>(uiToGet);

            ui_vm.ModelType           = EnuModelType.View;
            gridMyInfoTab.DataContext = ui_vm;

            if (bShowSuccessfulPopup)
            {
                Commands.ShowPopupAlert.Execute(new ShowPopupAlertParam {
                    AlertMessage = "刷新我的信息成功.", AlertType = EnuPopupAlertType.Info
                }, this);
            }

            return(true);
        }
        private void buttonOK_Click(object sender, RoutedEventArgs e)
        {
            ChangePassword_VM vm = DataContext as ChangePassword_VM;

            if (vm != null)
            {
                if (vm.IsModelValid())
                {
                    Password_API_Put objectToPut = new Password_API_Put();
                    objectToPut.Password = WebApiClientHelper.MakeConfidentialMessage(vm.ConfirmPwd);
                    try
                    {
                        WebApiClientHelper.DoJsonRequest <Password_API_Put>(
                            GlobalData.GetResUri(string.Format("password/{0}", GlobalData.CurrentUserName)),
                            EnuHttpMethod.Put,
                            objToSend: objectToPut);
                    }
                    catch (ClientException ex)
                    {
                        vm.SetExtraError(ex.Message);
                        return;
                    }

                    WebApiClientHelper.Password = vm.ConfirmPwd;
                    DialogResult = true;
                    Close();
                }
            }
        }
        private void btnUploadAvatar_Click(object sender, RoutedEventArgs e)
        {
            string avatar = _OpenFileDialog("选择头像", "jpg文件(*.jpg)|*.jpg");

            if (!string.IsNullOrEmpty(avatar))
            {
                using (FileStream fs = File.Open(avatar, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    try
                    {
                        WebApiClientHelper.DoStreamRequest(
                            GlobalData.GetResUri(string.Format("avatars/{0}", GlobalData.CurrentUserName)),
                            EnuHttpMethod.Put, fs);
                    }
                    catch (ClientException ex)
                    {
                        Commands.ShowPopupAlert.Execute(new ShowPopupAlertParam {
                            AlertMessage = ex.Message, AlertType = EnuPopupAlertType.Error
                        }, this);
                        return;
                    }
                }

                //设置头像(需要重新打开文件流并将它转为MemoryStream)
                using (FileStream fs = File.Open(avatar, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    if (fs.Length > 0)
                    {
                        byte[] memory = new byte[fs.Length];
                        fs.Read(memory, 0, (int)fs.Length);
                        SetAvatarImage(new MemoryStream(memory));
                    }
                }
            }
        }
        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            UserInfo_VM ui_vm = gridMyInfoTab.DataContext as UserInfo_VM;

            if (ui_vm != null)
            {
                if (ui_vm.IsModelValid())
                {
                    try
                    {
                        UserInfo_API_Put userput = Mapper.Map <UserInfo_VM, UserInfo_API_Put>(ui_vm);
                        WebApiClientHelper.DoJsonRequest <UserInfo_API_Put>(GlobalData.GetResUri(string.Format("usersinfo/{0}", ui_vm.UserName)), EnuHttpMethod.Put, objToSend: userput, tick: ui_vm.UpdateTicks);
                    }
                    catch (ClientException ex)
                    {
                        ui_vm.SetExtraError(ex.Message); //这是Popup以外的另一种异常显示方式
                        return;
                    }

                    LoadMyInfo();

                    Commands.ShowPopupAlert.Execute(new ShowPopupAlertParam {
                        AlertMessage = "修改信息成功.", AlertType = EnuPopupAlertType.Info
                    }, this);

                    Commands.GoToViewMode.Execute(null, this);
                }
            }
        }
Exemple #5
0
        public void Execute(IJobExecutionContext context)
        {
            FormToPDFTaskRepository repo = new FormToPDFTaskRepository();

            repo.AddTask();

            var taskId        = "";
            var jobDataTaskId = context.Trigger.JobDataMap["taskId"];

            if (jobDataTaskId != null)
            {
                taskId = jobDataTaskId.ToString();
            }

            FormToPDFTask task = repo.GetTask(taskId);

            try
            {
                while (task != null)
                {
                    repo.BeginTask(task.ID);
                    var    uri        = FormToWordApiUrl + string.Format("FormToWordAPI/{0}?TmplCode={1}", task.FormID, task.TempCode);
                    byte[] wordBuffer = WebApiClientHelper.DoFileRequest(uri);
                    byte[] pdfBuffer  = FileConverter.Word2JPG(wordBuffer);
                    var    length     = "0KB";
                    if (pdfBuffer.Length < 1000)
                    {
                        length = pdfBuffer.Length + "B";
                    }
                    else if (pdfBuffer.Length >= 1000 && pdfBuffer.Length < 1000000)
                    {
                        length = pdfBuffer.Length / 1000 + "KB";
                    }
                    else
                    {
                        length = pdfBuffer.Length / 1000000 + "M";
                    }

                    string pdfFileID = FileStoreHelper.SaveFile(pdfBuffer, task.FormID + ".jpg");
                    repo.EndTask(task.ID, pdfFileID + "_" + length);

                    task = repo.GetTask();
                }
            }
            catch (Exception ex)
            {
                repo.Log(task.ID, ex.Message);
            }
        }
 private void btnClearAvatar_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBoxResult.OK == MessageBox.Show("要删除头像吗?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question))
     {
         try
         {
             WebApiClientHelper.DoJsonRequest <int>(GlobalData.GetResUri(string.Format("avatars/{0}", GlobalData.CurrentUserName)),
                                                    EnuHttpMethod.Delete);
         }
         catch (ClientException ex)
         {
             Commands.ShowPopupAlert.Execute(new ShowPopupAlertParam {
                 AlertMessage = ex.Message, AlertType = EnuPopupAlertType.Error
             }, this);
             return;
         }
         SetAvatarImage(null);
     }
 }
        private void RetrieveMyAvatar()
        {
            Stream stm;

            try
            {
                stm = WebApiClientHelper.DoStreamRequest(GlobalData.GetResUri(string.Format("avatars/{0}", GlobalData.CurrentUserName)), EnuHttpMethod.Get);
            }
            catch (ClientException) //忽略获取失败的错误
            {
                return;
            }

            if (stm == null)
            {
                imgAvatar.Source = null;
                return;
            }

            SetAvatarImage(stm);
        }
Exemple #8
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            string   pwd     = Md5.MD5TwiceEncode("123456");
            Login_VM vmLogin = DataContext as Login_VM;

            if (vmLogin == null)
            {
                return;
            }

            if (vmLogin.IsModelValid())
            {
                WebApiClientHelper.UserName = vmLogin.UserName;
                WebApiClientHelper.Password = vmLogin.Password;
                UserInfo_API_Get userInfo;
                try
                {
                    userInfo = WebApiClientHelper.DoJsonRequest <UserInfo_API_Get>(GlobalData.GetResUri("entrance"), EnuHttpMethod.Get);
                }
                catch (ClientException ex)
                {
                    vmLogin.SetExtraError(ex.Message);
                    return;
                }

                //验证成功,记录用户信息
                GlobalData.CurrentUserName = userInfo.UserName;
                GlobalData.CurrentDispName = userInfo.RealName;
                GlobalData.CurrentRole     = userInfo.Role;

                //转入主窗口
                MainWindow main = new MainWindow();
                Application.Current.MainWindow = main;
                Close();
                main.Show();
            }
        }
        private bool LoadAllUsersInfo(bool bShowSuccessfulPopup = false)
        {
            //加载数据
            IEnumerable <UserInfo_API_Get> uisToGet;

            try
            {
                uisToGet =
                    WebApiClientHelper.DoJsonRequest <IEnumerable <UserInfo_API_Get> >(GlobalData.GetResUri("usersinfo"),
                                                                                       EnuHttpMethod.Get);
            }
            catch (ClientException ex)
            {
                Commands.ShowPopupAlert.Execute(new ShowPopupAlertParam {
                    AlertMessage = ex.Message, AlertType = EnuPopupAlertType.Error
                }, this);
                return(false);
            }

            IEnumerable <UserInfo_VM> uis_vm = Mapper.Map <IEnumerable <UserInfo_VM> >(uisToGet);

            foreach (var ui in uis_vm)
            {
                ui.ModelType = EnuModelType.View;
            }
            gridAllUsersInfoTab.DataContext = uis_vm;

            if (bShowSuccessfulPopup)
            {
                Commands.ShowPopupAlert.Execute(new ShowPopupAlertParam {
                    AlertMessage = "刷新所有用户信息成功.", AlertType = EnuPopupAlertType.Info
                }, this);
            }

            return(true);
        }
Exemple #10
0
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                FormToPDFTaskRepository repo = new FormToPDFTaskRepository();
                repo.AddTask();

                var taskId        = "";
                var jobDataTaskId = context.Trigger.JobDataMap["taskId"];
                if (jobDataTaskId != null)
                {
                    taskId = jobDataTaskId.ToString();
                }

                FormToPDFTask task = repo.GetTask(taskId);

                while (task != null)
                {
                    try
                    {
                        repo.BeginTask(task.ID);
                        var    uri        = FormToWordApiUrl + string.Format("FormToWordAPI/{0}?TmplCode={1}", task.FormID, task.TempCode);
                        byte[] wordBuffer = WebApiClientHelper.DoFileRequest(uri);

                        StringBuilder fileNames = new StringBuilder();

                        //1. 转pdf
                        byte[] pdfFile = FileConverter.Word2PDF(wordBuffer);
                        int    j       = 0;
                        var    length  = "0KB";
                        if (pdfFile.Length < 1000)
                        {
                            length = pdfFile.Length + "B";
                        }
                        else if (pdfFile.Length >= 1000 && pdfFile.Length < 1000000)
                        {
                            length = pdfFile.Length / 1000 + "KB";
                        }
                        else
                        {
                            length = pdfFile.Length / 1000000 + "M";
                        }

                        var src = string.IsNullOrEmpty(ConfigurationManager.AppSettings["Src"]) ? "" : ConfigurationManager.AppSettings["Src"];

                        string pdfFileID = FileStoreHelper.SaveFile(pdfFile, task.FormID + ".pdf", src, true);

                        //2.转jpg
                        List <byte[]> results = FileConverter.Word2JPG(wordBuffer);
                        foreach (var item in results)
                        {
                            int p = 0;
                            length = "0KB";
                            if (item.Length < 1000)
                            {
                                length = item.Length + "B";
                            }
                            else if (item.Length >= 1000 && item.Length < 1000000)
                            {
                                length = item.Length / 1000 + "KB";
                            }
                            else
                            {
                                length = item.Length / 1000000 + "M";
                            }

                            string fileID = FileStoreHelper.SaveFile(item, task.FormID + "_" + (p++).ToString() + ".jpg", src, true);

                            fileNames.Append(fileID);
                            fileNames.Append("_");
                            fileNames.Append(length);
                            fileNames.Append(",");
                        }
                        repo.EndTask(task.ID, pdfFileID, fileNames.ToString().TrimEnd(','));

                        task = repo.GetTask();
                    }
                    catch (Exception ex)
                    {
                        repo.Log(task.ID, ex.Message);
                        LogWriter.Error("[出错记录]:" + task.ID + " [错误信息]:" + ex.Message);
                        continue;
                    }
                }
            }
            catch (Exception e)
            {
                LogWriter.Error(e.Message);
            }
            finally
            {
                //防止和浏览转图程序关闭进程冲突,不能在转图浏览服务器上同时部署
                CloseExit();
                System.Environment.Exit(0);
            }
        }
Exemple #11
0
        public void Execute(IJobExecutionContext context)
        {
            var flowEntities = FormulaHelper.GetEntities <WorkflowEntities>();

            #region 设定自动发送时间

            var taskExecList = flowEntities.S_WF_InsTaskExec.Where(c => c.ExecTime == null && c.TimeoutAutoPass == null).ToList();
            foreach (var taskExec in taskExecList)
            {
                int timeout = 0;
                var step    = taskExec.S_WF_InsTask.S_WF_InsDefStep;
                if (step.TimeoutAutoPass != null)
                {
                    timeout = (int)step.TimeoutAutoPass;
                }
                //TimeoutAutoPass 为负数时 轮巡直接自动通过
                if (timeout == 0)
                {
                    taskExec.TimeoutAutoPass       = DateTime.MaxValue;
                    taskExec.TimeoutAutoPassResult = "无设定";
                    continue;
                }
                var calendarService = FormulaHelper.GetService <ICalendarService>();
                taskExec.TimeoutAutoPass = calendarService.GetTimeoutTime((DateTime)taskExec.CreateTime, timeout);
            }
            flowEntities.SaveChanges();

            #endregion

            #region 超时自动执行任务

            taskExecList = flowEntities.S_WF_InsTaskExec.Where(c => c.ExecTime == null && string.IsNullOrEmpty(c.TimeoutAutoPassResult) && DateTime.Now > c.TimeoutAutoPass).ToList();
            string FlowApiUrl = System.Configuration.ConfigurationManager.AppSettings["FlowApiUrl"];
            if (FlowApiUrl.EndsWith("/"))
            {
                FlowApiUrl = FlowApiUrl.TrimEnd('/');
            }

            foreach (var taskExec in taskExecList)
            {
                try
                {
                    var    agentUser = FormulaHelper.GetUserInfoByID(taskExec.ExecUserID);
                    FlowFO flowFO    = new FlowFO();
                    //flowFO.AutoExecTask(taskExec.ID, "自动通过");

                    var routingList = flowFO.AutoExecGetRoutingList(taskExec.ID);
                    if (routingList.Count == 0)
                    {
                        continue;
                    }
                    var routing = routingList[0];
                    if (routing.Type == Workflow.Logic.RoutingType.Branch.ToString())
                    {
                        continue;
                    }

                    var    formInstanceID = taskExec.S_WF_InsFlow.FormInstanceID;
                    var    param          = flowFO.GetRoutingParams(routing, taskExec, formInstanceID);
                    string nextUserIDs    = param.userIDs;

                    var uri = string.Format("{0}/FlowTaskAPI/SubmitForm?id={1}&FormInstanceID={2}&TaskExecID={3}&NextExecUserIDs={4}&Comment={5}&ExecUserID={6}&UserAccount={7}&IsMobileRequest=6",
                                            FlowApiUrl, routingList[0].ID, formInstanceID, taskExec.ID, nextUserIDs, "自动通过", taskExec.TaskUserID, agentUser.Code);
                    var str = WebApiClientHelper.DoJsonRequest(uri, EnuHttpMethod.Post, new { FormDic = "{ID:\"" + formInstanceID + "\"}", FlowCode = "" });

                    //5.3平台FlowTaskAPI
                    //var uri = string.Format("{0}/FlowTaskAPI/0/Submit?id={1}&FormInstanceID={2}&TaskExecID={3}&NextExecUserIDs={4}&Comment={5}&ExecUserID={6}&UserAccount={7}",
                    //    FlowApiUrl, routingList[0].ID, formInstanceID, taskExec.ID, nextUserIDs, "自动通过", taskExec.TaskUserID, agentUser.Code);
                    //var str = WebApiClientHelper.DoJsonRequest(uri, EnuHttpMethod.Get);

                    if (str.ToLower() == "true")
                    {
                        taskExec.TimeoutAutoPassResult = "Success";
                        flowEntities.SaveChanges();
                    }
                    else
                    {
                        throw new Exception("FlowTaskAPI报错");
                    }
                }
                catch (Exception e)
                {
                    SQLHelper sqlHelper = SQLHelper.CreateSqlHelper(ConnEnum.WorkFlow);
                    string    sql       = "update S_WF_InsTaskExec set TimeoutAutoPassResult='{0}' where ID='{1}'";
                    string    str       = e.Message ?? "";
                    if (str.Length > 500)
                    {
                        str = str.Substring(0, 500);
                    }
                    sql = string.Format(sql, str, taskExec.ID);
                    sqlHelper.ExecuteNonQuery(sql); //记录错误
                }
            }

            #endregion
        }