Esempio n. 1
0
        public void GetExistFileNotFinishCategory()
        {
            string returnMsg = string.Empty;
            int    errorCode = 0;

            string[] parametersRequired = { "projectId" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> resultPar = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null, Req_Date = DateTime.Now
                };
                GenerateJson(resultPar);
                return;
            }
            FileCategoryBLL fcBll       = new FileCategoryBLL();
            string          notFinished = fcBll.GetExistFileNotFinishCategory(context, out errorCode);

            string        message        = ErrorCode.GetCodeMessage(errorCode);
            List <string> lstNotFinished = new List <string>();

            lstNotFinished.Add(notFinished);
            JsonResult <string> result = new JsonResult <string> {
                Code = errorCode, Message = message, Rows = 0, Result = lstNotFinished, Req_Date = DateTime.Now
            };

            GenerateJson(result);
            return;
        }
Esempio n. 2
0
        /// <summary>
        /// 发送提醒
        /// </summary>
        public void SendDingtalkMessage()
        {
            string returnMsg = string.Empty;
            int    errorCode = 0;

            // 校验参数
            string[] parametersRequired = { "categoryId", "taskRemindId" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(result);
                return;
            }

            string          taskRemindId = context.Request["taskRemindId"];
            FileCategoryBLL fcBll        = new FileCategoryBLL();
            bool            isSuccess    = new TaskRemindingBLL().SetRemind(taskRemindId);

            errorCode = isSuccess ? 0 : 1;

            string message = ErrorCode.GetCodeMessage(errorCode);
            JsonResult <string> result2 = new JsonResult <string> {
                Code = errorCode, Message = message, Rows = 0, Result = null
            };

            GenerateJson(result2);
            return;
        }
Esempio n. 3
0
        public void AddFileCategory()
        {
            string returnMsg = string.Empty;
            int    errorCode = 0;

            string[] parametersRequired = { "projectId", "categoryId", "description", "expiredate" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null, Req_Date = DateTime.Now
                };
                GenerateJson(result);
                return;
            }
            FileCategoryBLL fcBll = new FileCategoryBLL();

            if (fcBll.AddFileCategory(context, out errorCode))
            {
                string message             = ErrorCode.GetCodeMessage(errorCode);
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = message, Rows = 0, Result = null, Req_Date = DateTime.Now
                };
                GenerateJson(result);
                return;
            }
            else
            {
                string message             = ErrorCode.GetCodeMessage(errorCode);
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = message, Rows = 0, Result = null, Req_Date = DateTime.Now
                };
                GenerateJson(result);
                return;
            }
        }
        private void PreviewFile()
        {
            string fileHistoryId = Request["fileHistoryId"];

            try
            {
                int    errorCode              = 0;
                string actPath                = string.Empty;
                string taskRootFolder         = string.Empty;
                string taskFolderWithoutEmpNo = string.Empty;
                // 根据 ID 获取到 fileHistory 对象
                FileHistory fileHistory        = new FileHistoryBLL().GetModel(fileHistoryId);
                DataTable   dtPrjIdAndCategory = new FileCategoryBLL().GetProjectIdByFileHistoryId(fileHistoryId).Tables[0];
                string      projectId          = Convert.ToString(dtPrjIdAndCategory.Rows[0]["PROJECTID"]);
                string      category           = Convert.ToString(dtPrjIdAndCategory.Rows[0]["category"]);
                string      folderName         = Convert.ToString(dtPrjIdAndCategory.Rows[0]["folderName"]);
                bool        flag             = new FileCategoryBLL().GetFilePathByProjectId(projectId, category, folderName, false, out actPath, out taskRootFolder, out taskFolderWithoutEmpNo, out errorCode);
                string      physicalFileName = Path.Combine(actPath, fileHistory.FILENAME);
                if (File.Exists(physicalFileName))
                {
                    string extName = Path.GetExtension(physicalFileName).ToLower();
                    switch (extName)
                    {
                    case ".pdf":
                        PreviewPdf(physicalFileName);
                        break;

                    case ".txt":
                        PreviewText(physicalFileName);
                        break;

                    case ".jpg":
                    case ".png":
                    case ".bmp":
                    case ".jpeg":
                    case ".gif":
                        PreviewImage(physicalFileName);
                        break;

                    default:
                        return;
                    }
                }
                Response.Write("<h3>文件不存在!</h3>");
                Response.End();
            }
            catch (Exception ex)
            {
                LogHelper.WriteLine($"文件{fileHistoryId}预览出错" + ex.Message);
                Response.End();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 获取 fileCategory 列表
        /// </summary>
        public void GetCategories()
        {
            string returnMsg = string.Empty;
            int    errorCode = 0;

            // 校验参数
            string[] parametersRequired = { "projectId" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(result);
                return;
            }

            FileCategoryBLL     fcBll      = new FileCategoryBLL();
            List <FileCategory> categories = fcBll.GetCategories(context, out errorCode);

            // 获取到结果
            if (categories != null && categories.Count() > 0)
            {
                List <CategoryTabs> categoryTabs = new List <CategoryTabs>();
                foreach (var item in categories)
                {
                    CategoryTabs tab = new CategoryTabs();
                    tab.Id          = item.ID;
                    tab.title       = item.TITLE;
                    tab.description = item.DESCRIPTION;
                    tab.expiredate  = DateTimeHelper.ConvertDateTimeInt(item.EXPIREDATE ?? DateTime.MinValue);
                    categoryTabs.Add(tab);
                }
                string message = ErrorCode.GetCodeMessage(errorCode);
                JsonResult <CategoryTabs> result = new JsonResult <CategoryTabs> {
                    Code = errorCode, Message = message, Rows = categoryTabs.Count, Result = categoryTabs
                };
                GenerateJson(result);
                return;
            }
            // 结果为空
            else
            {
                string message             = ErrorCode.GetCodeMessage(errorCode);
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = message, Rows = 0, Result = null
                };
                GenerateJson(result);
                return;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 根据选择的tal获取回复tab列表
        /// </summary>
        public void GetReplyToTab()
        {
            string returnMsg = string.Empty;
            int    errorCode = 0;

            // 校验参数
            string[] parametersRequired = { "projectId", "categoryId" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(result);
                return;
            }
            // 获取列表
            FileCategoryBLL fcBll          = new FileCategoryBLL();
            DataTable       fileCategories = fcBll.GetReplyToTab(context, out errorCode).Tables[0];

            if (fileCategories != null && fileCategories.Rows.Count > 0)
            {
                List <SubTabs> subTabs = new List <SubTabs>();
                for (int i = 0; i < fileCategories.Rows.Count; i++)
                {
                    SubTabs sub = new SubTabs();
                    sub.Id = fileCategories.Rows[i]["ID"].ToString();
                    //sub.hasParent = fileCategories.Rows[i]["hasParent"].ToString() == "1";
                    sub.categoryId = fileCategories.Rows[i]["categoryId"].ToString();
                    sub.Title      = fileCategories.Rows[i]["title"].ToString();
                    subTabs.Add(sub);
                }
                string message = ErrorCode.GetCodeMessage(errorCode);
                JsonResult <SubTabs> result = new JsonResult <SubTabs> {
                    Code = errorCode, Message = message, Rows = subTabs.Count(), Result = subTabs
                };
                GenerateJson(result);
                return;
            }
            else
            {
                string message             = ErrorCode.GetCodeMessage(errorCode);
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = message, Rows = 0, Result = null
                };
                GenerateJson(result);
                return;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 判断是否提醒过
        /// </summary>
        public void GetIsRemind()
        {
            string returnMsg = string.Empty;
            int    errorCode = 0;

            // 校验参数
            string[] parametersRequired = { "categoryId" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(result);
                return;
            }

            string          taskRemindId = string.Empty;
            bool            isReminded   = false;
            FileCategoryBLL fcBll        = new FileCategoryBLL();
            DataSet         dsIsRemind   = fcBll.GetIsRemindCategoriesId(context, out errorCode);

            if (dsIsRemind != null && dsIsRemind.Tables.Count > 0 && dsIsRemind.Tables[0].Rows.Count > 0)
            {
                if ((string)dsIsRemind.Tables[0].Rows[0]["ISREMINDED"] == "1")
                {
                    isReminded = true;
                    errorCode  = 7001;
                }
            }
            string           message          = ErrorCode.GetCodeMessage(errorCode);
            TaskRemindEntity taskRemindEntity = new TaskRemindEntity {
                Id = taskRemindId, IsRemind = isReminded
            };
            List <TaskRemindEntity> taskRemindEntities = new List <TaskRemindEntity>();

            taskRemindEntities.Add(taskRemindEntity);
            JsonResult <TaskRemindEntity> result2 = new JsonResult <TaskRemindEntity> {
                Code = errorCode, Message = message, Rows = 0, Result = taskRemindEntities
            };

            GenerateJson(result2);
            return;
        }
Esempio n. 8
0
        /// <summary>
        /// 合并文件
        /// </summary>
        /// <param name="taskid"></param>
        /// <param name="projectId">项目ID</param>
        /// <param name="title">文件保存的直接父目录名,如修改1、修改1完成</param>
        /// <param name="filename">文件名</param>
        /// <param name="errorCode">错误码</param>
        /// <returns>是否成功</returns>
        private bool MergeSplitFile(string taskid, string projectId, string category, string title, string filename, out string physicalFileName, out int errorCode)
        {
            string actPath = string.Empty;

            physicalFileName = string.Empty;
            string taskRootFolder         = string.Empty;
            string taskFolderWithoutEmpNo = string.Empty;
            bool   flag = new FileCategoryBLL().GetFilePathByProjectId(projectId, category, title, false, out actPath, out taskRootFolder, out taskFolderWithoutEmpNo, out errorCode);

            if (Directory.Exists(actPath))
            {
                string actFileName = Path.Combine(actPath, filename);
                // 2018-06-23,需求,如果上传同名文件,则将之前的文件删除
                if (File.Exists(actFileName))
                {
                    File.Delete(actFileName);
                }
                //if (File.Exists(actFileName))
                //{
                //    errorCode = 6007;
                //    return false;
                //}
                physicalFileName = actFileName;
                DirectoryInfo savePathInfo  = new DirectoryInfo(fileUploadTempFolder);
                var           allSplitFiles = savePathInfo.EnumerateFiles().Where(file => file.Name.StartsWith(filename) && file.Name.Contains(taskid)).OrderBy(file => file.Name.Length).ThenBy(file => file.Name);
                using (FileStream fileStream = File.Create(actFileName, 10 * 1024 * 1024))
                {
                    foreach (var file in allSplitFiles)
                    {
                        using (FileStream splitFile = File.Open(file.FullName, FileMode.Open))
                        {
                            splitFile.CopyTo(fileStream);
                        }
                        file.Delete();
                    }
                }
                return(true);
            }
            errorCode = 6501;
            return(false);
        }
Esempio n. 9
0
        public void PreviewFile()
        {
            string returnMsg = string.Empty;
            int    errorCode = 0;

            // 校验参数
            string[] parametersRequired = { "fileHistoryId" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> resultPra = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(resultPra);
                return;
            }

            string actPath                = string.Empty;
            string taskRootFolder         = string.Empty;
            string taskFolderWithoutEmpNo = string.Empty;

            try
            {
                string fileHistoryId = context.Request["fileHistoryId"];
                string previewFolder = ConfigurationManager.AppSettings["filePreviewFolder"].ToString();
                // 根据 ID 获取到 fileHistory 对象
                FileHistory fileHistory        = new FileHistoryBLL().GetModel(fileHistoryId);
                DataTable   dtPrjIdAndCategory = new FileCategoryBLL().GetProjectIdByFileHistoryId(fileHistoryId).Tables[0];
                string      projectId          = Convert.ToString(dtPrjIdAndCategory.Rows[0]["PROJECTID"]);
                string      category           = Convert.ToString(dtPrjIdAndCategory.Rows[0]["category"]);
                string      folderName         = Convert.ToString(dtPrjIdAndCategory.Rows[0]["folderName"]);
                bool        flag             = new FileCategoryBLL().GetFilePathByProjectId(projectId, category, folderName, false, out actPath, out taskRootFolder, out taskFolderWithoutEmpNo, out errorCode);
                string      physicalFileName = Path.Combine(actPath, fileHistory.FILENAME);
                if (File.Exists(physicalFileName))
                {
                    System.Web.HttpServerUtility server = System.Web.HttpContext.Current.Server;
                    string previewHtmlFile = Path.Combine(previewFolder, fileHistory.ID + ".html");
                    LogHelper.WriteLine("previewHtmlFile Path: " + previewHtmlFile);
                    if (!File.Exists(previewHtmlFile))
                    {
                        string extName = Path.GetExtension(physicalFileName);
                        switch (extName)
                        {
                        case ".doc":
                        case ".docx":
                            //case ".rtf":
                            Office2HtmlHelper.Word2Html(physicalFileName, previewFolder, fileHistory.ID);
                            break;

                        case ".xls":
                        case ".xlsx":
                            Office2HtmlHelper.Excel2Html(physicalFileName, previewFolder, fileHistory.ID);
                            break;

                        default:
                            return;
                        }
                    }

                    List <PreviewResult> lstPre = new List <PreviewResult>();
                    if (File.Exists(previewHtmlFile))
                    {
                        string htmlFile = string.Format("/FilePreview/{0}.html", fileHistory.ID);

                        PreviewResult pre = new PreviewResult();
                        pre.previewUrl = htmlFile;
                        lstPre.Add(pre);
                    }
                    else
                    {
                        errorCode = 1;
                        returnMsg = "文件未能成功生成!";
                    }
                    JsonResult <PreviewResult> resultPre = new JsonResult <PreviewResult> {
                        Code = errorCode, Message = returnMsg, Rows = 0, Result = lstPre
                    };
                    GenerateJson(resultPre);
                    return;
                }
                errorCode = 6001;
                returnMsg = ErrorCode.GetCodeMessage(errorCode);
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(result);
                return;
            }
            catch (Exception ex)
            {
                errorCode = 1;
                LogHelper.WriteLine("预览生成出错:" + ex.Message + ex.StackTrace);
            }
        }
Esempio n. 10
0
        public void DownloadFile()
        {
            string returnMsg = string.Empty;
            int    errorCode = 0;

            // 校验参数
            string[] parametersRequired = { "fileHistoryId" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> resultPra = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(resultPra);
                return;
            }

            string actPath                = string.Empty;
            string taskRootFolder         = string.Empty;
            string taskFolderWithoutEmpNo = string.Empty;
            string fileHistoryId          = context.Request["fileHistoryId"];
            // 根据 ID 获取到 fileHistory 对象
            FileHistory fileHistory        = new FileHistoryBLL().GetModel(fileHistoryId);
            DataTable   dtPrjIdAndCategory = new FileCategoryBLL().GetProjectIdByFileHistoryId(fileHistoryId).Tables[0];
            string      projectId          = Convert.ToString(dtPrjIdAndCategory.Rows[0]["PROJECTID"]);
            string      category           = Convert.ToString(dtPrjIdAndCategory.Rows[0]["category"]);
            string      folderName         = Convert.ToString(dtPrjIdAndCategory.Rows[0]["folderName"]);
            bool        flag             = new FileCategoryBLL().GetFilePathByProjectId(projectId, category, folderName, false, out actPath, out taskRootFolder, out taskFolderWithoutEmpNo, out errorCode);
            string      physicalFileName = Path.Combine(actPath, fileHistory.FILENAME);

            if (File.Exists(physicalFileName))
            {
                string           userId           = UserProfile.GetInstance()?.ID;
                string           operateTypeName  = "下载";
                int              operateTypeKey   = new ConfigureBLL().GetConfig(ConfigTypeName.文件操作类型.ToString()).AsEnumerable().Where(item => item["configValue"].ToString() == operateTypeName).Select(item => Convert.ToInt32(item["configKey"])).FirstOrDefault();
                FileOperationLog fileOperationLog = new FileOperationLog();
                fileOperationLog.ID             = Guid.NewGuid().ToString();
                fileOperationLog.PROJECTID      = projectId;
                fileOperationLog.EMPLOYEEID     = userId;
                fileOperationLog.FILENAME       = fileHistory.FILENAME;
                fileOperationLog.OPERATETYPE    = operateTypeKey;
                fileOperationLog.OPERATEDATE    = DateTime.Now;
                fileOperationLog.OPERATECONTENT = operateTypeName + fileHistory.FILENAME;
                fileOperationLog.OPERATEUSER    = userId;
                new FileOperationLogBLL().Add(fileOperationLog);

                System.IO.Stream iStream = null;
                // Buffer to read 10K bytes in chunk:
                byte[] buffer = new Byte[10000];
                // Length of the file:
                int length;
                // Total bytes to read.
                long dataToRead;
                // Identify the file to download including its path.
                string filepath = physicalFileName;
                // Identify the file name.
                string filename = System.IO.Path.GetFileName(filepath);
                try
                {
                    // Open the file.
                    iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
                                                       System.IO.FileAccess.Read, System.IO.FileShare.Read);
                    // Total bytes to read.
                    dataToRead = iStream.Length;
                    context.Response.Clear();
                    context.Response.ClearHeaders();
                    context.Response.ClearContent();
                    context.Response.ContentType = "text/plain"; // Set the file type
                    context.Response.AddHeader("Content-Length", dataToRead.ToString());
                    context.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + "");

                    // Read the bytes.
                    while (dataToRead > 0)
                    {
                        // Verify that the client is connected.
                        if (context.Response.IsClientConnected)
                        {
                            // Read the data in buffer.
                            length = iStream.Read(buffer, 0, 10000);

                            // Write the data to the current output stream.
                            context.Response.OutputStream.Write(buffer, 0, length);

                            // Flush the data to the HTML output.
                            context.Response.Flush();

                            buffer     = new Byte[10000];
                            dataToRead = dataToRead - length;
                        }
                        else
                        {
                            // Prevent infinite loop if user disconnects
                            dataToRead = -1;
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Trap the error, if any.
                    context.Response.Write("Error : " + ex.Message);
                }
                finally
                {
                    if (iStream != null)
                    {
                        //Close the file.
                        iStream.Close();
                    }
                    context.Response.End();
                }
            }
            errorCode = 6001;
            returnMsg = ErrorCode.GetCodeMessage(errorCode);
            JsonResult <string> result = new JsonResult <string> {
                Code = errorCode, Message = returnMsg, Rows = 0, Result = null
            };

            GenerateJson(result);
            return;
        }
Esempio n. 11
0
        public void DeleteFile()
        {
            string returnMsg = string.Empty;
            int    errorCode = 0;

            // 校验参数
            string[] parametersRequired = { "fileHistoryId" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(result);
                return;
            }

            string fileHistoryId = context.Request["fileHistoryId"];
            // 根据 ID 获取到 fileHistory 对象
            FileHistory fileHistory = new FileHistoryBLL().GetModel(fileHistoryId);

            if (fileHistoryId != null)
            {
                fileHistory.ISDELETED = true;
                bool delFlag = new FileHistoryBLL().Update(fileHistory);
                // 逻辑删除成功
                if (delFlag)
                {
                    string    actPath                = string.Empty;
                    string    taskRootFolder         = string.Empty;
                    string    deletedFolder          = ConfigurationManager.AppSettings["fileDeletedFolder"].ToString();
                    string    taskFolderWithoutEmpNo = string.Empty;
                    DataTable dtPrjIdAndCategory     = new FileCategoryBLL().GetProjectIdByFileHistoryId(fileHistoryId).Tables[0];
                    string    projectId              = Convert.ToString(dtPrjIdAndCategory.Rows[0]["PROJECTID"]);
                    string    category               = Convert.ToString(dtPrjIdAndCategory.Rows[0]["category"]);
                    string    folderName             = Convert.ToString(dtPrjIdAndCategory.Rows[0]["folderName"]);
                    bool      flag             = new FileCategoryBLL().GetFilePathByProjectId(projectId, category, folderName, false, out actPath, out taskRootFolder, out taskFolderWithoutEmpNo, out errorCode);
                    string    physicalFileName = Path.Combine(actPath, fileHistory.FILENAME);
                    string    timeStr          = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string    destFileName     = Path.Combine(deletedFolder, timeStr + fileHistory.FILENAME);
                    if (File.Exists(physicalFileName))
                    {
                        try
                        {
                            // 如果目标位置文件已存在,则先将其删除
                            if (File.Exists(destFileName))
                            {
                                File.Delete(destFileName);
                            }
                            // 移动文件到删除暂存目录
                            File.Move(physicalFileName, destFileName);
                        }
                        catch (IOException ioEx)
                        {
                            errorCode = 1;
                            returnMsg = ioEx.Message;
                            LogHelper.WriteLine("文件删除失败:" + ioEx.Message);
                        }
                        finally
                        {
                            if (File.Exists(physicalFileName))
                            {
                                fileHistory.ISDELETED = false;
                                new FileHistoryBLL().Update(fileHistory);
                                errorCode = 1;
                            }
                            else
                            {
                                // 记录操作日志
                                string           operateTypeName  = "删除";
                                int              operateTypeKey   = new ConfigureBLL().GetConfig(ConfigTypeName.文件操作类型.ToString()).AsEnumerable().Where(item => item["configValue"].ToString() == operateTypeName).Select(item => Convert.ToInt32(item["configKey"])).FirstOrDefault();
                                FileOperationLog fileOperationLog = new FileOperationLog();
                                fileOperationLog.ID             = Guid.NewGuid().ToString();
                                fileOperationLog.PROJECTID      = projectId;
                                fileOperationLog.EMPLOYEEID     = UserProfile.GetInstance()?.ID;
                                fileOperationLog.FILENAME       = fileHistory.FILENAME;
                                fileOperationLog.OPERATETYPE    = operateTypeKey;
                                fileOperationLog.OPERATEDATE    = DateTime.Now;
                                fileOperationLog.OPERATECONTENT = operateTypeName + fileHistory.FILENAME;
                                fileOperationLog.OPERATEUSER    = UserProfile.GetInstance()?.ID;
                                new FileOperationLogBLL().Add(fileOperationLog);
                            }
                        }
                    }
                }
                else
                {
                    errorCode = 1;
                }
                JsonResult <string> result = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(result);
                return;
            }
            JsonResult <string> resultFinal = new JsonResult <string> {
                Code = errorCode, Message = returnMsg, Rows = 0, Result = null
            };

            GenerateJson(resultFinal);
            return;
        }
Esempio n. 12
0
        public void UploadSuccess()
        {
            string returnMsg        = string.Empty;
            int    errorCode        = 0;
            string projectId        = string.Empty;
            string category         = string.Empty;
            string folder           = string.Empty;
            string userId           = string.Empty;
            string physicalFileName = string.Empty;

            // 校验参数
            string[] parametersRequired = { "parentId", "description", "taskid", "filename" };
            if (!CheckParamsRequired(parametersRequired, out errorCode, out returnMsg))
            {
                JsonResult <string> resultChkPar = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(resultChkPar);
                return;
            }
            string       taskid       = context.Request["taskid"].ToString();
            string       filename     = context.Request["filename"].ToString();
            string       parentId     = Convert.ToString(context.Request["parentId"]);
            string       description  = Convert.ToString(context.Request["description"]);
            FileCategory fileCategory = new FileCategoryBLL().GetModel(parentId);

            if (fileCategory != null)
            {
                projectId = fileCategory.PROJECTID;
                folder    = fileCategory.FOLDERNAME;
                category  = fileCategory.CATEGORY;
                bool flag = MergeSplitFile(taskid, projectId, category, folder, filename, out physicalFileName, out errorCode);
                if (flag)
                {
                    userId = UserProfile.GetInstance()?.ID;
                    string fileNameRelativeToTaskFolder = Path.Combine(folder, filename);
                    bool   addFileHisFlag = new FileHistoryBLL().AddFileHistory(parentId, filename, fileNameRelativeToTaskFolder, description, userId);
                    if (addFileHisFlag)
                    {
                        string           operateTypeName  = "上传";
                        int              operateTypeKey   = new ConfigureBLL().GetConfig(ConfigTypeName.文件操作类型.ToString()).AsEnumerable().Where(item => item["configValue"].ToString() == operateTypeName).Select(item => Convert.ToInt32(item["configKey"])).FirstOrDefault();
                        FileOperationLog fileOperationLog = new FileOperationLog();
                        fileOperationLog.ID             = Guid.NewGuid().ToString();
                        fileOperationLog.PROJECTID      = projectId;
                        fileOperationLog.EMPLOYEEID     = userId;
                        fileOperationLog.FILENAME       = filename;
                        fileOperationLog.OPERATETYPE    = operateTypeKey;
                        fileOperationLog.OPERATEDATE    = DateTime.Now;
                        fileOperationLog.OPERATECONTENT = operateTypeName + filename;
                        fileOperationLog.OPERATEUSER    = userId;
                        new FileOperationLogBLL().Add(fileOperationLog);
                        JsonResult <string> resultOprLog = new JsonResult <string> {
                            Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                        };
                        GenerateJson(resultOprLog);
                        return;
                    }
                    // 添加失败时,需删除已上传的文件
                    else
                    {
                        if (File.Exists(physicalFileName))
                        {
                            File.Delete(physicalFileName);
                        }
                        JsonResult <string> resultAddDb2 = new JsonResult <string> {
                            Code = errorCode, Message = "数据库记录添加失败", Rows = 0, Result = null
                        };
                        GenerateJson(resultAddDb2);
                        return;
                    }
                }
                returnMsg = ErrorCode.GetCodeMessage(errorCode);
                JsonResult <string> resultAddDb = new JsonResult <string> {
                    Code = errorCode, Message = returnMsg, Rows = 0, Result = null
                };
                GenerateJson(resultAddDb);
                return;
            }
            JsonResult <string> result = new JsonResult <string> {
                Code = errorCode, Message = "未找到 projectId 对应的记录", Rows = 0, Result = null
            };

            GenerateJson(result);
            return;
        }
Esempio n. 13
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(ddlCanTransferEmp.SelectedValue))
            {
                ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "alert('请选择需要转移到的员工!');", true);
                return;
            }
            try
            {
                if (Convert.ToDecimal(txtProportion.Text.Trim()) > 100)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "alert('比例不能超过100%!');", true);
                    return;
                }
                if (Convert.ToDecimal(txtAmount.Text.Trim()) > Convert.ToDecimal(hidAmount.Value))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "alert('不能超过原始金额!');", true);
                    return;
                }
            }
            catch (Exception ex0)
            {
                ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "alert('数值不正确!');", true);
                return;
            }
            // 声明变量
            EmployeeAccountBLL eaBll = new EmployeeAccountBLL();
            // 任务ID
            string prjID = Request.QueryString["prjID"].ToString();
            // 当前分部领导 empId
            string parentEmployeeID = Convert.ToString(Request.QueryString["parentEmployeeID"]);
            // 需要转移对象的 empId
            string employeeID = ddlCanTransferEmp.SelectedValue;

            // 移动目录
            Employee empParent       = empBll.GetModel(parentEmployeeID);
            string   parentEmpNo     = empParent.EMPLOYEENO;
            Employee empToTransfer   = empBll.GetModel(employeeID);
            string   transferToEmpNo = empToTransfer.EMPLOYEENO;

            FileCategoryBLL fcBll                  = new FileCategoryBLL();
            int             errCode                = 0;
            string          returnFolderName       = string.Empty;
            string          taskRootFolder         = string.Empty;
            string          taskFolderWithoutEmpNo = string.Empty;

            fcBll.GetFilePathByProjectId(prjID, string.Empty, string.Empty, false, out returnFolderName, out taskRootFolder, out taskFolderWithoutEmpNo, out errCode);
            string sourceDirectory   = string.Format(taskFolderWithoutEmpNo, parentEmpNo);
            string destinctDirectory = string.Format(taskFolderWithoutEmpNo, transferToEmpNo);

            try
            {
                Directory.Move(sourceDirectory, destinctDirectory);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLine("|" + sourceDirectory + "|" + destinctDirectory);
                LogHelper.WriteLine(ex.Message + ex.StackTrace);
                ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "alert('目录移动失败!');", true);
                return;
            }

            // 更新部门领导账户,按照配置比例计算出金额后累加到分部领导账户
            decimal           proportion        = 0;
            ProjectProportion projectProportion = new ProjectProportionBLL().GetModelList(" projectId = '" + prjID + "'").FirstOrDefault();

            if (projectProportion != null)
            {
                proportion = projectProportion.PROPORTION ?? 0m;
            }
            else
            {
                EmployeeProportion empProportion = new EmployeeProportionBLL().GetModelList(" AND employeeId = '" + parentEmployeeID + "'").FirstOrDefault();
                proportion = empProportion.PROPORTION ?? 0m;
            }
            decimal         amountToLeader = Convert.ToDecimal(Request.QueryString["amount"]);
            EmployeeAccount empAcctParent  = new EmployeeAccount();

            empAcctParent                = eaBll.GetModelList(" employeeId = '" + parentEmployeeID + "'").FirstOrDefault();
            empAcctParent.AMOUNT        += (amountToLeader * proportion);
            empAcctParent.LASTUPDATEDATE = DateTime.Now;
            eaBll.Update(empAcctParent);

            // 添加一条交易记录
            TransactionDetails transactionDetails = new TransactionDetails();

            transactionDetails.ID = Guid.NewGuid().ToString();
            transactionDetails.TRANSACTIONAMOUNT      = amountToLeader * proportion;
            transactionDetails.TRANSACTIONDESCRIPTION = "分部领导提成";
            transactionDetails.TRANSACTIONPROPORTION  = proportion;
            transactionDetails.TRANSACTIONTYPE        = 6;
            transactionDetails.TRANSACTIONDATE        = DateTime.Now;
            transactionDetails.PLANDATE   = DateTimeHelper.GetFirstDateOfCurrentMonth();
            transactionDetails.EMPLOYEEID = parentEmployeeID;
            transactionDetails.PROJECTID  = prjID;
            transactionDetails.ISDELETED  = false;
            tdBll.Add(transactionDetails);

            //// 转移到的员工  先计入一条状态为已删除的数据,后续待任务完成时再调整:需要待任务完成后,再计入账户
            transactionDetails    = new TransactionDetails();
            transactionDetails.ID = Guid.NewGuid().ToString();
            transactionDetails.TRANSACTIONAMOUNT      = Convert.ToDecimal(txtAmount.Text.Trim());
            transactionDetails.TRANSACTIONDESCRIPTION = "项目提成(暂存)";
            transactionDetails.TRANSACTIONTYPE        = 7;
            transactionDetails.TRANSACTIONDATE        = DateTime.Now;
            transactionDetails.PLANDATE   = DateTimeHelper.GetFirstDateOfCurrentMonth();
            transactionDetails.EMPLOYEEID = employeeID;
            transactionDetails.PROJECTID  = prjID;
            transactionDetails.ISDELETED  = true;
            tdBll.Add(transactionDetails);

            //EmployeeAccount empAcctTransferTo = new EmployeeAccount();
            //empAcctTransferTo = eaBll.GetModelList(" employeeID = '" + employeeID + "'").FirstOrDefault();
            //empAcctTransferTo.AMOUNT += Convert.ToDecimal(txtAmount.Text.Trim());
            //empAcctTransferTo.LASTUPDATEDATE = DateTime.Now;
            //eaBll.Update(empAcctTransferTo);

            // 更新任务完成人
            ProjectSharing ps = new ProjectSharing();

            ps = psBll.GetModelList(" projectId = '" + prjID + "' AND FInishedperson = '" + parentEmployeeID + "'").FirstOrDefault();
            ps.FINISHEDPERSON = employeeID;
            if (psBll.Update(ps))
            {
                ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "alert('转移成功!');window.top.location.href='/employeeHome.aspx';", true);
                return;
            }

            ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "alert('更新完成人失败!');window.top.location.href='/employeeHome.aspx';", true);
            return;
        }
Esempio n. 14
0
        ///// <summary>
        ///// 页码跳转
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //protected void btnGoPage_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        int pageindex = int.Parse(tb_pageindex.Text);
        //        AspNetPager1.CurrentPageIndex = pageindex;
        //    }
        //    catch (FormatException)
        //    {
        //        lbl_error.Text = "输入的页索引格式不正确";
        //    }
        //}
        #endregion

        #region Repeat Databound,计算提成金额、任务剩余时间和修改剩余时间
        protected void gvProject_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                #region 设置任务状态样式
                Label lblTaskStatus = e.Row.FindControl("lblTaskStatus") as Label;
                if (lblTaskStatus != null && !string.IsNullOrEmpty(lblTaskStatus.Text.Trim()))
                {
                    if (lblTaskStatus.Text.Trim() == "暂停")
                    {
                        lblTaskStatus.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");
                    }
                }
                #endregion

                #region 计算提成金额
                #region 预计提成
                string  prjId      = gvProject.DataKeys[e.Row.RowIndex].Values[0].ToString();
                decimal proportion = 0m;
                // 先看此项目是否单独设置了提成
                ProjectProportion projectProportion = lstPrjProportion?.Where(item => item.PROJECTID == prjId).FirstOrDefault();  // new ProjectProportionBLL().GetModelList(" projectId = '" + prjId + "'").FirstOrDefault();
                // 如果设置了单独提成,则采用单独设置的比例
                if (projectProportion != null)
                {
                    proportion = projectProportion.PROPORTION ?? 0m;
                }
                // 如果未设置,则采用默认提成
                else if (empProportion != null)
                {
                    proportion = empProportion?.PROPORTION ?? 0m;
                }
                Label       lblExpectAmount = e.Row.FindControl("lblExpectAmount") as Label;
                HiddenField hidOrderAmount  = e.Row.FindControl("hidOrderAmount") as HiddenField;
                decimal     orderAmount     = Convert.ToDecimal(hidOrderAmount.Value);
                //Project prj = new ProjectBLL().GetModel(prjId);
                lblExpectAmount.Text = (orderAmount * Convert.ToDecimal(proportion)).ToString();
                //2019-03-26,未转正期间的任务隐藏预计提成
                Project project = new ProjectBLL().GetModel(prjId);
                if (project.CREATEDATE != null && toRegularDate != null)
                {
                    if (project.CREATEDATE <= toRegularDate || toRegularDate == Convert.ToDateTime("2000/1/1 00:00:00"))
                    {
                        lblExpectAmount.Text = "--";
                    }
                }
                #endregion

                #region 实际提成
                //decimal tcje = new TransactionDetailsBLL().GetModelList(" AND employeeId = '" + Convert.ToString(EmployeeID ?? string.Empty) + "' AND TRANSACTIONTYPE = 7 AND PROJECTID = '" + prjId + "' ").Sum(item => item.TRANSACTIONAMOUNT) ?? 0m;
                Label lblProportionAmount = e.Row.FindControl("lblProportionAmount") as Label;
                //lblProportionAmount.Text = tcje.ToString();
                if (lstTcje != null && lstTcje.Count() > 0)
                {
                    decimal transactionAmount = lstTcje.Where(item => item.PROJECTID == prjId && item.EMPLOYEEID == EmployeeID).Sum(item => item.TRANSACTIONAMOUNT) ?? 0m;
                    lblProportionAmount.Text = transactionAmount.ToString();
                }
                else
                {
                    lblProportionAmount.Text = "0";
                }
                #endregion
                #endregion

                #region 计算任务剩余时间
                bool  isFinished    = Convert.ToInt32(gvProject.DataKeys[e.Row.RowIndex].Values[1]) == 1;
                Label lblTimeRemain = e.Row.FindControl("lblTimeRemain") as Label;
                //未完成的,才显示剩余时间
                if (lblTimeRemain != null && !isFinished)
                {
                    HiddenField hidExpireDate = e.Row.FindControl("hidExpireDate") as HiddenField;
                    DateTime    dtExpire      = Convert.ToDateTime(hidExpireDate.Value);
                    if (DateTime.Now < dtExpire)
                    {
                        TimeSpan ts = dtExpire - DateTime.Now;

                        //设置提醒label文本
                        lblTimeRemain.Text = string.Format("{0}小时", Math.Floor(ts.TotalHours));
                        if (ts.TotalHours <= 3)
                        {
                            lblTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");//不足3小时,红色
                            lblTimeRemain.Font.Bold = true;
                        }
                        else if (ts.TotalHours <= 6)
                        {
                            lblTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF8800");//不足6小时,橙色
                            lblTimeRemain.Font.Bold = true;
                        }
                        else if (ts.TotalHours <= 12)
                        {
                            lblTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#EEEE00");//不足12小时,黄色
                            lblTimeRemain.Font.Bold = true;
                        }
                        else if (ts.TotalHours <= 24)
                        {
                            lblTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF77FF");//不足24小时,洋红色
                        }
                        else if (ts.TotalHours <= 48)
                        {
                            lblTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#57C600");//48小时以上,酸橙色(浅绿)
                        }
                        else
                        {
                            lblTimeRemain.Text = "&gt;2天";
                        }
                    }
                    else if (dtExpire < DateTime.Now)
                    {
                        TimeSpan ts = DateTime.Now - dtExpire;
                        lblTimeRemain.Text      = string.Format("逾期{0}", Common.TransformTimeSpan(ts));
                        lblTimeRemain.ForeColor = System.Drawing.Color.Red;
                    }
                }
                #endregion

                #region 计算修改剩余时间
                string    projectId = gvProject.DataKeys[e.Row.RowIndex].Values[0].ToString();
                Label     lblModifyTaskTimeRemain = e.Row.FindControl("lblModifyTaskTimeRemain") as Label;
                DataTable dt = new FileCategoryBLL().GetExpireDateByProjectId(projectId).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Button btnSetModifyTasksFinished = e.Row.FindControl("btnSetModifyTasksFinished") as Button;
                    btnSetModifyTasksFinished.Visible = true;
                    string folderName = Convert.ToString(dt.Rows[0]["folderName"]);
                    btnSetModifyTasksFinished.CommandArgument = projectId + "|" + folderName;
                    if (folderName.Contains("修改"))
                    {
                        string strExpireDate = Convert.ToString(dt.Rows[0]["expireDate"]);

                        DateTime dtExpire = Convert.ToDateTime(strExpireDate);
                        if (DateTime.Now < dtExpire)
                        {
                            TimeSpan ts = dtExpire - DateTime.Now;
                            //设置提醒label文本
                            lblModifyTaskTimeRemain.Text = string.Format("{0}剩余{1}小时", folderName, Math.Floor(ts.TotalHours));
                            if (ts.TotalHours <= 3)
                            {
                                lblModifyTaskTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF0000");//不足3小时,红色
                                lblModifyTaskTimeRemain.Font.Bold = true;
                            }
                            else if (ts.TotalHours <= 6)
                            {
                                lblModifyTaskTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF8800");//不足6小时,橙色
                                lblModifyTaskTimeRemain.Font.Bold = true;
                            }
                            else if (ts.TotalHours <= 12)
                            {
                                lblModifyTaskTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#EEEE00");//不足12小时,黄色
                                lblModifyTaskTimeRemain.Font.Bold = true;
                            }
                            else if (ts.TotalHours <= 24)
                            {
                                lblModifyTaskTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#FF77FF");//不足24小时,洋红色
                            }
                            else if (ts.TotalHours <= 48)
                            {
                                lblModifyTaskTimeRemain.ForeColor = System.Drawing.ColorTranslator.FromHtml("#57C600");//48小时以上,酸橙色(浅绿)
                            }
                            else
                            {
                                lblModifyTaskTimeRemain.Text = string.Format("{0}剩余&gt;2天", folderName);
                            }
                        }
                        else if (dtExpire < DateTime.Now)
                        {
                            TimeSpan ts = DateTime.Now - dtExpire;
                            lblModifyTaskTimeRemain.Text      = string.Format("{0}逾期{1}", folderName, Common.TransformTimeSpan(ts));
                            lblModifyTaskTimeRemain.ForeColor = System.Drawing.Color.Red;
                        }
                    }
                }
                #endregion
            }
        }