Esempio n. 1
0
        /// <summary>
        /// 导出文件附件
        /// </summary>
        /// <param name="wherestr">搜索条件</param>
        /// <returns>附件信息</returns>
        public ActionResult ExportFile(int pcode = 0, string name = "", string code = "")
        {
            try
            {
                string filename = HttpUtility.UrlEncode(string.Format("导出报表_组织机构管理_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss")), Encoding.UTF8);
                string path     = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");
                string where = "1=1";
                List <object> param = new List <object>();
                if (pcode > 0)
                {
                    where += " AND P_CODE=?";
                    param.Add(pcode);
                }
                if (string.IsNullOrWhiteSpace(name) == false)
                {
                    where += " AND NAME LIKE '%" + name.Replace('\'', ' ') + "%'";
                }
                if (string.IsNullOrWhiteSpace(code) == false)
                {
                    where += " AND DEPT_CODE=? ";
                    param.Add(code);
                }
                var dt = BF_DEPARTMENT.Instance.GetTableFields("NAME,DEPT_CODE,DEPT_LEVEL,P_CODE,DEPT_FLAG,REMARK,CREATE_TIME,UPDATE_TIME", where, param);
                if (dt == null)
                {
                    return(ShowAlert("导出数据到Excel出现错误:未查询出数据"));
                }
                dt.Columns.Remove("ID");
                dt.Columns["NAME"].Caption        = "部门名称";
                dt.Columns["DEPT_CODE"].Caption   = "部门编码";
                dt.Columns["DEPT_LEVEL"].Caption  = "部门层级";
                dt.Columns["P_CODE"].Caption      = "上级部门编码";
                dt.Columns["DEPT_FLAG"].Caption   = "部门标志";
                dt.Columns["REMARK"].Caption      = "部门说明";
                dt.Columns["CREATE_TIME"].Caption = "创建时间";
                dt.Columns["UPDATE_TIME"].Caption = "最后更新时间";

                Library.Export.ExcelFile export = new Library.Export.ExcelFile(path);
                string fullName = export.ToExcel(dt);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.Clear();//清除缓冲区所有内容
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
                System.Web.HttpContext.Current.Response.WriteFile(fullName);
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.End();
                //删除文件
                export.Delete(fullName);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "导出默认报表[DB]到Excel出错:" + ex.ToString());
                return(ShowAlert("导出数据到Excel出现未知错误:" + ex.Message));
            }
            return(ShowAlert("导出成功"));
        }
Esempio n. 2
0
        public string ExecuteSelectSQL(int dbID, string sql, int pageSize = 10, int pageIndex = 1, bool isExecuteRowsCount = false, string psd = "")
        {
            if (sql.Trim().ToUpper().StartsWith("SELECT "))
            {
                int rowsCount = isExecuteRowsCount ? 0 : -1;
                try
                {
                    DataTable dt = BF_DATABASE.Instance.ExecuteSelectSQL(dbID, sql, null, ref rowsCount, pageSize, pageIndex);
                    return(ToJsonString(dt, rowsCount));
                }
                catch (Exception ex)
                {
                    BLog.Write(BLog.LogLevel.WARN, "在数据库" + dbID + "中执行SQL查询语句:\r\n" + sql + "\r\n出错:" + ex.ToString());
                    return(ToJsonString(new DataTable(), 0, 1, "查询失败:" + ex.Message));
                }
            }
            else
            {
                JsonResultData result = new JsonResultData();
                try
                {
                    int i = BF_DATABASE.Instance.ExecuteSQL(dbID, psd, sql, null);
                    result.IsSuccess = true;
                    result.Message   = string.Format("执行SQL语句成功,影响了【{0}】条记录", i);
                }
                catch (Exception ex)
                {
                    BLog.Write(BLog.LogLevel.WARN, "在数据库" + dbID + "中执行SQL语句:\r\n" + sql + "\r\n出错:" + ex.ToString());
                    result.Message = string.Format("执行SQL语句失败:" + ex.Message);
                }

                return(JsonConvert.SerializeObject(result));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 在调用Action方法前,验证访问权限
        /// </summary>
        /// <param name="context"></param>
        protected override void OnActionExecuting(ActionExecutingContext context)
        {
            ViewBag.Title = MvcApplication.SystemName + context.Controller.GetType().ToString();

            string controllerName = context.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower();
            string actionName     = context.ActionDescriptor.ActionName.ToLower();
            //不带参数的路径
            string path = path = "/" + context.RequestContext.HttpContext.Request.AppRelativeCurrentExecutionFilePath.ToLower().Trim(new char[] { '~', '/' });
            //BLog.Write(BLog.LogLevel.DEBUG, "path:" + path);
            string rawUrl = context.HttpContext.Request.RawUrl;

            if (Request.ApplicationPath != "/" && ApplicationPath != Request.ApplicationPath)
            {
                ApplicationPath = Request.ApplicationPath;
            }

            ///  /home/login4a  提供给4A的‘单点登录地址’
            ///  /home/login  登录地址
            ///  /AfUser/UpdateAppAcctSoap  提供给4A的‘帐号变更接口’
            if (path == "/aferror/index" ||
                path == "/home/login" ||
                path == "/home/securitycode" ||
                path.ToLower() == "/home/login4a" ||
                path.ToLower() == "/AfUser/UpdateAppAcctSoap".ToLower())
            {
                return;
            }

            if (SystemSession.UserID < 1)
            {
                context.Result = Redirect("~/Home/Login");
                return;
            }

            try
            {
                //验证访问权限
                CheckPermission(path, rawUrl.ToLower());
            }
            catch (Exception ex)
            {
                context.Result = Content("<script>alert('没有权限访问页面:" + rawUrl + "');</script>");// Redirect("~/AfError/Index?message=" + ex.Message + "&url=" + Server.UrlEncode(rawUrl));
                BLog.Write(BLog.LogLevel.WARN, "用户:" + SystemSession.UserName + "访问了无权限的URL:" + HttpUtility.HtmlEncode(rawUrl));
                return;
            }

            //记录通用日志
            try
            {
                string srcIP   = context.HttpContext.Request.UserHostAddress;
                int    srcPort = context.HttpContext.Request.Url.Port;

                string content = "请求方式:" + context.HttpContext.Request.RequestType;
                BF_OP_LOG.Instance.AddLog(BLog.LogLevel.INFO, true, srcIP, srcPort, controllerName, actionName, rawUrl, content);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "记录操作日志出错:" + ex.ToString());
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 启动一个节点任务(会自动添加一个新的任务到表BF_ST_TASK)
        /// </summary>
        /// <param name="nodeID">节点ID</param>
        /// <param name="referenceDate">基准日期</param>
        /// <param name="beginDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="parameters">手动参数</param>
        /// <param name="message">返回信息</param>
        /// <returns>是否执行成功</returns>
        public bool Start(int nodeID, DateTime referenceDate, DateTime beginDate, DateTime endDate, string parameters, ref string message)
        {
            try
            {
                Entity ne = GetEntityByKey <Entity>(nodeID);
                if (ne == null)
                {
                    message = "未找到节点【" + nodeID + "】";
                    return(false);
                }
                if (ne.RUN_STATUS == (short)Enums.RunStatus.运行)
                {
                    message = "在执行任务【" + ne.LAST_TASK_ID + "】,无法启动新任务";
                    return(false);
                }
                int i = BF_ST_TASK.Instance.AddNodeTask(nodeID, true, referenceDate, beginDate, endDate, parameters, "手动添加节点任务");
                if (i == 1)
                {
                    message = "已经创建新的节点任务,请稍后刷新查看运行情况";
                    return(true);
                }
                message = "创建节点任务失败";
            }
            catch (Exception ex)
            {
                message = "创建节点任务出错,详见日志";
                BLog.Write(BLog.LogLevel.WARN, "创建节点【" + nodeID + "】任务出错:" + ex.ToString());
            }

            return(false);
        }
Esempio n. 5
0
        /// <summary>
        /// 停止
        /// </summary>
        public static void Stop()
        {
            IsRun = false;

            try
            {
                BLog.Write(BLog.LogLevel.INFO, "程序即将停止。");
                foreach (var kvp in _dicTaskers)
                {
                    kvp.Value.Stop();
                }
                _dicTaskers.Clear();
                _bw.CancelAsync();
                _bw.Dispose();

                //停止手动任务线程
                Task.Hand.Stop();

                //停止节点扫描
                Task.Scanner.Stop();

                BLog.Write(BLog.LogLevel.INFO, "程序已经停止。");
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.ERROR, "程序停止失败。" + ex.ToString());
            }

            Thread.Sleep(1001);
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Show(int id)
        {
            if (id < 1)
            {
                return(ShowAlert("请选择正确的报表"));
            }

            try
            {
                BF_CHART_REPORT.Entity entity = BF_CHART_REPORT.Instance.GetEntityByKey <BF_CHART_REPORT.Entity>(id);
                if (entity == null)
                {
                    return(ShowAlert("报表不存在"));
                }
                if (entity.IS_ENABLE != 1)
                {
                    return(ShowAlert("报表已被禁用"));
                }
                ViewBag.DB_ID       = entity.DB_ID;
                ViewBag.SQL_CODE    = Base.Encrypt.BAES.Encrypt(entity.SQL_CODE);
                ViewBag.CHART_CODE  = Base.Encrypt.BAES.Encrypt(entity.CHART_CODE);
                ViewBag.TOP_CODE    = entity.TOP_CODE;
                ViewBag.BOTTOM_CODE = entity.BOTTOM_CODE;
                return(View());
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "查询报表[" + id + "]出现未知错误:" + ex.Message);
                return(ShowAlert("查询报表出现未知错误:" + ex.Message));
            }
        }
Esempio n. 7
0
        public JsonResult Import(int id, string date, HttpPostedFileBase file)
        {
            JsonResultData result = new JsonResultData();

            try
            {
                string   fileName      = Path.GetFileName(file.FileName);
                string   fileExtension = Path.GetExtension(fileName).ToLower();
                DateTime baseDate      = DateTime.Today;
                if (string.IsNullOrWhiteSpace(date) == false)
                {
                    DateTime.TryParse(date, out baseDate);
                }

                if (fileExtension != ".xlsx")
                {
                    result.Message = "上传的文件格式错误,只能上传后缀为.xlsx的Excel文件";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                BF_IMPORT.Entity entity = BF_IMPORT.Instance.GetEntityByKey <BF_IMPORT.Entity>(id);
                if (entity == null)
                {
                    result.Message = "未找到配置" + id;
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                string path = System.Web.HttpContext.Current.Server.MapPath("~/tmp/up/");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                string saveName = DateTime.Now.ToString("yyyyMMdd_HHmmss_") + SystemSession.UserID + "_" + fileName;

                file.SaveAs(path + saveName);
                string message = string.Empty;
                Dictionary <int, string> errorList = new Dictionary <int, string>();
                int n = BF_IMPORT.ImportDataFile(entity, path + saveName, baseDate, out message, out errorList);
                if (n < 1)
                {
                    BLog.Write(BLog.LogLevel.WARN, "外导数据【" + id + "】失败:" + message);
                }
                result.IsSuccess = n > 0;
                result.Message   = message;
                result.Result    = "";
                if (errorList != null && errorList.Count > 0)
                {
                    result.Result = string.Join("\r\n", errorList);
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = ex.Message;
                BLog.Write(BLog.LogLevel.WARN, "外导数据【" + id + "】出错:" + ex.ToString());
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
        /// <summary>
        /// 判断菜单层级是否小于3级
        /// </summary>
        /// <param name="isActiveOnly">是否仅查询有效的菜单</param>
        /// <returns></returns>
        public bool IsSetMenus(int pid)
        {
            if (pid <= 0)
            {
                return(true);
            }

            try
            {
                string where = "id=(select pid from BF_MENU where id=?)";
                DataRow row = Instance.GetRowFields("pid", where, pid);
                if (row == null || row["pid"] == null || string.IsNullOrWhiteSpace(row["pid"].ToString()) || Convert.ToInt32(row["pid"]) <= 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.ERROR, "判断菜单层级时程序出现异常,请联系管理员。异常:" + ex.ToString());
                return(false);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 导出文件附件
        /// </summary>
        /// <param name="wherestr">搜索条件</param>
        /// <returns>附件信息</returns>
        public ActionResult ExportFile(int pid = 0, string name = "", string url = "")
        {
            try
            {
                string filename = HttpUtility.UrlEncode(string.Format("导出报表_菜单管理_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss")), Encoding.UTF8);
                string path     = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");
                string where = "1=1";
                List <object> param = new List <object>();
                if (pid > 0)
                {
                    where += " AND PID=?";
                    param.Add(pid);
                }
                if (string.IsNullOrWhiteSpace(name) == false)
                {
                    where += " AND NAME LIKE '%" + name.Replace('\'', ' ') + "%'";
                }
                if (string.IsNullOrWhiteSpace(url) == false)
                {
                    where += " AND URL LIKE '%" + url.Replace('\'', ' ') + "%'";
                }

                var dt = BF_MENU.Instance.GetTableFields("PID,NAME,URL,IS_ENABLE,IS_SHOW_NAV,CREATE_TIME,UPDATE_TIME", where, param);
                if (dt == null)
                {
                    return(ShowAlert("导出数据到Excel出现错误:未查询出数据"));
                }

                dt.Columns["PID"].Caption         = "上级菜单";
                dt.Columns["NAME"].Caption        = "菜单名称";
                dt.Columns["URL"].Caption         = "菜单URL地址";
                dt.Columns["IS_ENABLE"].Caption   = "启用状态";
                dt.Columns["IS_SHOW_NAV"].Caption = "导航显示";
                dt.Columns["CREATE_TIME"].Caption = "创建时间";
                dt.Columns["UPDATE_TIME"].Caption = "最后更新时间";


                Library.Export.ExcelFile export = new Library.Export.ExcelFile(path);
                string fullName = export.ToExcel(dt);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.Clear();//清除缓冲区所有内容
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
                System.Web.HttpContext.Current.Response.WriteFile(fullName);
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.End();
                //删除文件
                export.Delete(fullName);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "导出默认报表[DB]到Excel出错:" + ex.ToString());
                return(ShowAlert("导出数据到Excel出现未知错误:" + ex.Message));
            }
            return(ShowAlert("导出成功!"));
        }
Esempio n. 10
0
        /// <summary>
        /// 获得指定表的下一个序列值
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="isBeginPre"></param>
        /// <param name="fix"></param>
        /// <returns></returns>
        public int GetNextValueFromSeqDef(string tableName, bool isBeginPre = true, string fix = "SQ_")
        {
            string seq = "";

            try
            {
                if (isBeginPre)
                {
                    seq = fix + tableName;
                }
                else
                {
                    seq = tableName + fix;
                }
                using (Base.DBHelper.BDBHelper dbHelper = new Base.DBHelper.BDBHelper())
                {
                    return(dbHelper.GetNextValueFromSeq(seq));
                }
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.ERROR, string.Format(@"获得序列[{0}]失败:{1}", seq, ex.Message));
            }
            return(0);
        }
Esempio n. 11
0
        /// <summary>
        /// 导出文件附件
        /// </summary>
        /// <param name="wherestr">搜索条件</param>
        /// <returns>附件信息</returns>
        public ActionResult ExportFile(string name = "", string ip = "", int type = 0)
        {
            try
            {
                string filename = HttpUtility.UrlEncode(string.Format("导出报表_数据库管理_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss")), Encoding.UTF8);
                string path     = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");
                string where = "1=1";
                if (string.IsNullOrWhiteSpace(name) == false)
                {
                    where += " AND NAME LIKE '%" + name.Replace('\'', ' ') + "%'";
                }
                if (string.IsNullOrWhiteSpace(ip) == false)
                {
                    where += " AND IP LIKE '%" + ip.Replace('\'', ' ') + "%'";
                }
                if (type > 0)
                {
                    where += " AND DB_TYPE=" + type;
                }

                var dt = BF_DATABASE.Instance.GetTableFields("NAME,DB_TYPE,IP,PORT,USER_NAME,DB_NAME,REMARK,UPDATE_TIME", where);
                if (dt == null)
                {
                    return(ShowAlert("导出数据到Excel出现错误:未查询出数据"));
                }

                dt.Columns["NAME"].Caption        = "数据库名称";
                dt.Columns["DB_TYPE"].Caption     = "数据库类型";
                dt.Columns["IP"].Caption          = "IP地址";
                dt.Columns["PORT"].Caption        = "端口号";
                dt.Columns["USER_NAME"].Caption   = "用户名";
                dt.Columns["DB_NAME"].Caption     = "实例名";
                dt.Columns["REMARK"].Caption      = "备注";
                dt.Columns["UPDATE_TIME"].Caption = "最后更新时间";


                Library.Export.ExcelFile export = new Library.Export.ExcelFile(path);
                string fullName = export.ToExcel(dt);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.Clear();//清除缓冲区所有内容
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
                System.Web.HttpContext.Current.Response.WriteFile(fullName);
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.End();
                //删除文件
                export.Delete(fullName);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "导出默认报表[DB]到Excel出错:" + ex.ToString());
                return(ShowAlert("导出数据到Excel出现未知错误:" + ex.Message));
            }
            return(ShowAlert("导出成功"));
        }
Esempio n. 12
0
        /// <summary>
        /// 将数据导出到EXCEL文件
        /// </summary>
        /// <param name="fileName">显示文件名</param>
        /// <param name="table">数据</param>
        /// <returns></returns>
        protected ActionResult ExportExcel(string fileName, DataTable table)
        {
            if (table == null)
            {
                return(ShowAlert("未查到数据"));
            }

            if (table.Rows.Count < 1)
            {
                return(ShowAlert("报表查无数据,将不生成文件"));
            }

            string path = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");

            string fullName = string.Empty;

            if (Directory.Exists(path) == false)
            {
                Directory.CreateDirectory(path);
            }
            if (table.Rows.Count > 100000)
            {
                BLog.Write(BLog.LogLevel.DEBUG, "由于数据超过10万行,报表将导出为.csv");
                fileName = fileName.Replace(".xlsx", ".csv");
                fullName = path + DateTime.Now.ToString("yyyyMMddHHmmss") + ".csv";
                using (FileStream fs = new FileStream(fullName, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
                {
                    using (StreamWriter sw = new StreamWriter(fs, new System.Text.UTF8Encoding(true)))
                    {
                        foreach (DataColumn col in table.Columns)
                        {
                            sw.Write("\"" + col.Caption + "\",");
                        }
                        sw.WriteLine();

                        foreach (DataRow dr in table.Rows)
                        {
                            foreach (DataColumn col in table.Columns)
                            {
                                sw.Write("\"" + Convert.ToString(dr[col]) + "\",");
                            }
                            sw.WriteLine();
                            sw.Flush();
                        }
                    }
                }
            }
            else
            {
                ExcelFile export = new ExcelFile(path);
                fullName = export.ToExcel(table);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
            }

            return(ExportFile(fullName, fileName, true));
        }
Esempio n. 13
0
        public JsonResult Edit(SR_TOPIC_TASK.Entity ent, FormCollection collection)
        {
            JsonResultData result = new JsonResultData();

            try
            {
                //throw new Exception("抛出错误");
                #region 00.数据校验(暂未实现)

                #endregion

                #region 01.保存任务
                #region 时间范围赋值
                var beginEndData = collection["beginEndData"]; //时间范围
                if (!string.IsNullOrWhiteSpace(beginEndData))  //日期区间
                {
                    string[] dataArr = Regex.Split(beginEndData.Trim(), " - ", RegexOptions.IgnoreCase);
                    if (string.IsNullOrWhiteSpace(dataArr[0]) == false)//开始日期
                    {
                        ent.BEGIN_TIME = Convert.ToDateTime(dataArr[0]);
                    }
                    if (string.IsNullOrWhiteSpace(dataArr[1]) == false)//结束日期
                    {
                        ent.END_TIME = Convert.ToDateTime(dataArr[1]);
                    }
                }
                #endregion

                ent.UPDATE_TIME = DateTime.Now;
                ent.UPDATE_UID  = SystemSession.UserID;
                if (ent.ID == 0)
                {
                    var entId = SR_TOPIC_TASK.Instance.GetNextValueFromSeqDef();
                    ent.CREATE_TIME = DateTime.Now;
                    ent.CREATE_UID  = SystemSession.UserID;
                    ent.ID          = entId;
                    SR_TOPIC_TASK.Instance.Add(ent);
                }
                else
                {
                    SR_TOPIC_TASK.Instance.UpdateByKey(ent, ent.ID);
                }
                #endregion


                result.IsSuccess = true;
                result.Message   = string.Format(@"中期检查任务下达成功!");
            }
            catch (Exception ex)
            {
                string err = string.Format(@"中期检查任务下达失败:{0}", ex.Message);
                result.IsSuccess = false;
                result.Message   = err;
                BLog.Write(BLog.LogLevel.ERROR, err);
                WriteOperationLog(BLog.LogLevel.ERROR, false, Modular, "中期检查任务下达", "", err);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 14
0
        /// <summary>
        /// 导出文件附件
        /// </summary>
        /// <param name="wherestr">搜索条件</param>
        /// <returns>附件信息</returns>
        public ActionResult ExportFile(string content = "")
        {
            try
            {
                string filename = HttpUtility.UrlEncode(string.Format("导出报表_操作日志_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss")), Encoding.UTF8);
                string path     = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");

                List <object> param = new List <object>();
                #region 添加参数
                string where = "1=1";

                if (string.IsNullOrWhiteSpace(content) == false)
                {
                    where += " and content LIKE '%" + content.Replace('\'', ' ') + "%'";
                }
                #endregion

                var dt = BLL.FW.BF_OP_LOG.Instance.GetTableFields("LOG_TIME,LOG_LEVEL,IS_SUCCESS,SRC_IP,SRC_PORT,USER_NAME,CONTROLLER,ACTION,REQ_URL,CONTENT,DETAIL", where, param);
                if (dt == null)
                {
                    return(ShowAlert("导出数据到Excel出现错误:未查询出数据"));
                }
                dt.Columns["LOG_TIME"].Caption   = "日志时间";
                dt.Columns["LOG_LEVEL"].Caption  = "等级";
                dt.Columns["IS_SUCCESS"].Caption = "成功";
                dt.Columns["SRC_IP"].Caption     = "源IP";
                dt.Columns["SRC_PORT"].Caption   = "源端口";
                dt.Columns["USER_NAME"].Caption  = "登录名";
                dt.Columns["CONTROLLER"].Caption = "控制器名称";
                dt.Columns["ACTION"].Caption     = "ACTION名称";
                dt.Columns["REQ_URL"].Caption    = "请求URL地址";
                dt.Columns["CONTENT"].Caption    = "请求内容";
                dt.Columns["DETAIL"].Caption     = "源IP";

                Library.Export.ExcelFile export = new Library.Export.ExcelFile(path);
                string fullName = export.ToExcel(dt);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.Clear();//清除缓冲区所有内容
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
                System.Web.HttpContext.Current.Response.WriteFile(fullName);
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.End();
                //删除文件
                export.Delete(fullName);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "导出默认报表[DB]到Excel出错:" + ex.ToString());
                return(ShowAlert("导出数据到Excel出现未知错误:" + ex.Message));
            }
            return(ShowAlert("导出成功"));
        }
Esempio n. 15
0
        public JsonResult Edit(SR_TOPIC_DETAIL.Entity entity, FormCollection collection)
        {
            JsonResultData result = new JsonResultData();
            int            i      = 0;

            try
            {
                if (entity.TOPIC_ID <= 0)
                {
                    result.Message = "未找到课题";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                entity.UPDATE_UID  = SystemSession.UserID;
                entity.UPDATE_TIME = DateTime.Now;

                if (entity.ID == 0)
                {
                    int entityId = SR_TOPIC_DETAIL.Instance.GetNextValueFromSeqDef();
                    entity.ID          = entityId;
                    entity.CREATE_UID  = SystemSession.UserID;
                    entity.CREATE_TIME = DateTime.Now;
                    i = SR_TOPIC_DETAIL.Instance.Add(entity, true);
                }
                else
                {
                    i = SR_TOPIC_DETAIL.Instance.UpdateByKey(entity, entity.ID);//修改
                }

                if (i < 1)
                {
                    result.Message = "出现了未知错误";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                #region 保存合作单位信息
                string companys = collection["Companys"];
                int    delCount = 0, addCount = 0, updateCount = 0;
                SR_TOPIC_DETAIL_COMPANY.Instance.SaveCompanys(entity.ID, companys, out addCount, out updateCount, out delCount);
                #endregion

                result.IsSuccess = true;
                result.Message   = string.Format("保存成功!\r\n合作单位:新增【{0}】,修改【{1}】,删除【{2}】", addCount, updateCount, delCount);
                WriteOperationLog(BLog.LogLevel.INFO, true, Modular, (entity.ID > 0 ? "修改" : "添加"), "", (entity.ID > 0 ? "修改" : "添加") + "ID为" + entity.ID + "的信息成功!");
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = ex.Message;
                BLog.Write(BLog.LogLevel.WARN, "保存出错:" + ex.ToString());

                WriteOperationLog(BLog.LogLevel.ERROR, true, Modular, (entity.ID > 0 ? "修改" : "添加"), "", (entity.ID > 0 ? "修改" : "添加") + "ID为" + entity.ID + "的配置失败:" + ex.Message);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 16
0
        public JsonResult Edit(BF_FORM.Entity entity)
        {
            JsonResultData result = new JsonResultData();
            int            i      = 0;

            try
            {
                if (entity.ID < 0)
                {
                    result.Message = "配置项不存在,不可编辑";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                entity.UPDATE_UID  = SystemSession.UserID;
                entity.UPDATE_TIME = DateTime.Now;
                if (entity.ID == 0)
                {
                    entity.IS_ENABLE   = 1;
                    entity.CREATE_UID  = SystemSession.UserID;
                    entity.CREATE_TIME = DateTime.Now;
                    i = BF_FORM.Instance.Add(entity);
                }
                else
                {
                    Dictionary <string, object> dic = new Dictionary <string, object>();
                    dic.Add("NAME", entity.NAME);
                    dic.Add("DB_ID", entity.DB_ID);
                    dic.Add("TABLE_NAME", entity.TABLE_NAME);
                    dic.Add("CREATE_TABLE_MODE", entity.CREATE_TABLE_MODE);
                    dic.Add("IS_ALLOW_DELETE", entity.IS_ALLOW_DELETE);
                    dic.Add("FIELDS", entity.FIELDS);
                    dic.Add("REMARK", entity.REMARK);
                    dic.Add("JS_CODE", entity.JS_CODE);
                    dic.Add("UPDATE_UID", entity.UPDATE_UID);
                    dic.Add("UPDATE_TIME", entity.UPDATE_TIME);
                    i = BF_FORM.Instance.UpdateByKey(dic, entity.ID);
                }

                if (i < 1)
                {
                    result.Message = "出现了未知错误";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                result.IsSuccess = true;
                result.Message   = "保存成功";
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = ex.Message;
                BLog.Write(BLog.LogLevel.WARN, "编辑导入配置出错:" + ex.ToString());
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 17
0
        /// <summary>
        /// 导出文件附件
        /// </summary>
        /// <param name="wherestr">搜索条件</param>
        /// <returns>附件信息</returns>
        public ActionResult ExportFile(string name = "")
        {
            try
            {
                string filename = HttpUtility.UrlEncode(string.Format("导出报表_图形报表_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss")), Encoding.UTF8);
                string path     = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");

                #region 添加参数
                string        orderByField = "CR.ID";
                string        orderByType  = "DESC";
                List <object> param        = new List <object>();
                string where = "1=1";
                if (string.IsNullOrWhiteSpace(name) == false)
                {
                    where += " and CR.NAME LIKE '%" + name.Replace('\'', ' ') + "%'";
                }
                #endregion
                int       count = 0;
                DataTable dt    = BF_CHART_REPORT.Instance.GetDataTable(0, 0, ref count, name, orderByField, orderByType);
                if (dt == null)
                {
                    return(ShowAlert("导出数据到Excel出现错误:未查询出数据"));
                }
                dt.Columns.Remove("ID");
                dt.Columns["NAME"].Caption        = "名称";
                dt.Columns["DBNAME"].Caption      = "数据库名称";
                dt.Columns["CHART_TYPE"].Caption  = "类别";
                dt.Columns["SHOWEXPORT"].Caption  = "导出";
                dt.Columns["SHOWDEBUG"].Caption   = "调试";
                dt.Columns["SQL_CODE"].Caption    = "SQL";
                dt.Columns["IS_ENABLE"].Caption   = "启用";
                dt.Columns["UPDATE_TIME"].Caption = "更新时间";

                Library.Export.ExcelFile export = new Library.Export.ExcelFile(path);
                string fullName = export.ToExcel(dt);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.Clear();//清除缓冲区所有内容
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
                System.Web.HttpContext.Current.Response.WriteFile(fullName);
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.End();
                //删除文件
                export.Delete(fullName);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "导出默认报表[DB]到Excel出错:" + ex.ToString());
                return(ShowAlert("导出数据到Excel出现未知错误:" + ex.Message));
            }
            return(ShowAlert("导出成功"));
        }
Esempio n. 18
0
        /// <summary>
        /// 添加脚本流节点配置的实例(后期执行脚本流时,按此配置顺序执行相应节点)
        /// </summary>
        /// <param name="scriptID">脚本流ID</param>
        /// <param name="scriptCaseID">脚本流实例ID</param>
        /// <returns></returns>
        public List <long> AddReturnNodeIDList(long scriptID, long scriptCaseID)
        {
            IList <EM_SCRIPT_REF_NODE.Entity> refList = EM_SCRIPT_REF_NODE.Instance.GetNodeListByScriptID(scriptID);
            //用于去重
            Dictionary <long, byte> dic = new Dictionary <long, byte>();

            if (refList != null && refList.Count > 0)
            {
                using (BDBHelper dbHelper = new BDBHelper())
                {
                    //开始事务
                    dbHelper.BeginTrans();
                    foreach (EM_SCRIPT_REF_NODE.Entity refEntity in refList)
                    {
                        try
                        {
                            Entity entity = new Entity();
                            if (Main.KeyFieldIsUseSequence)
                            {
                                entity.ID = GetNextValueFromSeq();
                            }
                            entity.SCRIPT_ID      = scriptID;
                            entity.SCRIPT_CASE_ID = scriptCaseID;
                            entity.PARENT_NODE_ID = refEntity.PARENT_NODE_ID;
                            entity.CURR_NODE_ID   = refEntity.CURR_NODE_ID;
                            entity.REMARK         = refEntity.REMARK;

                            int i = Add(entity);
                            if (i < 0)
                            {
                                dbHelper.RollbackTrans();
                                dic.Clear();
                                break;
                            }
                            if (dic.ContainsKey(entity.CURR_NODE_ID) == false)
                            {
                                dic.Add(entity.CURR_NODE_ID, 1);
                            }
                        }
                        catch (Exception ex)
                        {
                            BLog.Write(BLog.LogLevel.ERROR, "添加脚本流节点配置的实例出错\t" + ex.ToString());
                            //出错回滚
                            dbHelper.RollbackTrans();
                            return(new List <long>());
                        }
                    }
                    //提交事务
                    dbHelper.CommitTrans();
                    dbHelper.Close();
                }
            }

            return(dic.Keys.ToList <long>());
        }
Esempio n. 19
0
        protected override bool Execute(DateTime runTime)
        {
            if (FormMain.IsRun == false)
            {
                BLog.Write(BLog.LogLevel.INFO, string.Format("主程序已经停止,任务【{0}】将不会继续执行任务。", ID));
                return(false);
            }

            BLog.Write(BLog.LogLevel.DEBUG, string.Format("任务【{0}】执行中……。", ID));
            return(true);
        }
Esempio n. 20
0
        /// <summary>
        /// 导出文件附件
        /// </summary>
        /// <param name="wherestr">搜索条件</param>
        /// <returns>附件信息</returns>
        public ActionResult ExportFile(int pid = 0, string name = "")
        {
            try
            {
                string filename = HttpUtility.UrlEncode(string.Format("导出报表_脚本类型_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss")), Encoding.UTF8);
                string path     = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");
                string where = "1=1";
                List <object> param = new List <object>();
                if (pid > 0)
                {
                    where += " AND PID=?";
                    param.Add(pid);
                }
                if (string.IsNullOrWhiteSpace(name) == false)
                {
                    where += " AND NAME LIKE '%" + name.Replace('\'', ' ') + "%'";
                }
                int count = 0;
                var dt    = BF_ST_TYPE.Instance.GetDataTable(0, 0, ref count, pid, name, "st.ID", "asc");
                if (dt == null)
                {
                    return(ShowAlert("导出数据到Excel出现错误:未查询出数据"));
                }
                dt.Columns["NAME"].Caption        = "类型名称";
                dt.Columns["PNAME"].Caption       = "上层类型";
                dt.Columns["REMARK"].Caption      = "备注";
                dt.Columns["CREATENAME"].Caption  = "创建者";
                dt.Columns["CREATE_TIME"].Caption = "创建时间";
                dt.Columns["UPDATENAME"].Caption  = "最后更新者";
                dt.Columns["UPDATE_TIME"].Caption = "最后更新时间";

                Library.Export.ExcelFile export = new Library.Export.ExcelFile(path);
                string fullName = export.ToExcel(dt);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.Clear();//清除缓冲区所有内容
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
                System.Web.HttpContext.Current.Response.WriteFile(fullName);
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.End();
                //删除文件
                export.Delete(fullName);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "导出默认报表[DB]到Excel出错:" + ex.ToString());
                return(ShowAlert("导出数据到Excel出现未知错误:" + ex.Message));
            }
            return(ShowAlert("导出成功"));
        }
Esempio n. 21
0
 public string GetTableList(int dbID, bool isImport = false)
 {
     try
     {
         List <string> list = BF_DATABASE.Instance.GetTableList(dbID, isImport);
         return(SerializeObject(list));
     }
     catch (Exception ex)
     {
         BLog.Write(BLog.LogLevel.WARN, "获取数据库" + dbID + "中的表名列表出错:" + ex.ToString());
         return("");
     }
 }
Esempio n. 22
0
 public string GetAllTableList(int dbID)
 {
     try
     {
         List <string> list = BF_DATABASE.Instance.GetAllTableList(dbID);
         return(SerializeObject(list));
     }
     catch (Exception ex)
     {
         BLog.Write(BLog.LogLevel.WARN, "获取表列表出错:" + ex.ToString());
         return("");
     }
 }
Esempio n. 23
0
 public string GetFieldsList(int dbID, string tableName)
 {
     try
     {
         List <BF_FIELD.Entity> list = BF_DATABASE.Instance.GetFieldsList(dbID, tableName);
         return(SerializeObject(list));
     }
     catch (Exception ex)
     {
         BLog.Write(BLog.LogLevel.WARN, "获取数据库" + dbID + "中表" + tableName + "的字段列表出错:" + ex.ToString());
         return("");
     }
 }
Esempio n. 24
0
        /// <summary>
        /// 导出文件附件
        /// </summary>
        /// <param name="wherestr">搜索条件</param>
        /// <returns>附件信息</returns>
        public ActionResult ExportFile(string enName = "", string cnName = "")
        {
            try
            {
                string filename = HttpUtility.UrlEncode(string.Format("导出报表_字段显示配置_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss")), Encoding.UTF8);
                string path     = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");
                string where = "1=1";
                if (string.IsNullOrWhiteSpace(enName) == false)
                {
                    where += " AND EN_NAME LIKE '%" + enName.Replace('\'', ' ') + "%'";
                }
                if (string.IsNullOrWhiteSpace(cnName) == false)
                {
                    where += " AND CN_NAME LIKE '%" + cnName.Replace('\'', ' ') + "%'";
                }

                var dt = BF_FIELD.Instance.GetTableFields("EN_NAME,CN_NAME,FIELD_DATA_TYPE,IS_REQUISITE,IS_SHOW,SHOW_WIDTH", where);
                if (dt == null)
                {
                    return(ShowAlert("导出数据到Excel出现错误:未查询出数据"));
                }
                dt.Columns["EN_NAME"].Caption         = "字段英文名";
                dt.Columns["CN_NAME"].Caption         = "字段中文名";
                dt.Columns["FIELD_DATA_TYPE"].Caption = "IP字段类型";
                dt.Columns["IS_REQUISITE"].Caption    = "是否必须";
                dt.Columns["IS_SHOW"].Caption         = "是否显示";
                dt.Columns["SHOW_WIDTH"].Caption      = "显示宽度";

                Library.Export.ExcelFile export = new Library.Export.ExcelFile(path);
                string fullName = export.ToExcel(dt);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.Clear();//清除缓冲区所有内容
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
                System.Web.HttpContext.Current.Response.WriteFile(fullName);
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.End();
                //删除文件
                export.Delete(fullName);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "导出默认报表[DB]到Excel出错:" + ex.ToString());
                return(ShowAlert("导出数据到Excel出现未知错误:" + ex.Message));
            }
            return(ShowAlert("导出成功"));
        }
Esempio n. 25
0
        public JsonResult Edit(BF_DATABASE.Entity entity)
        {
            JsonResultData result = new JsonResultData();
            int            i      = 0;

            try
            {
                CheckInput(entity);

                if (entity.ID < 0)
                {
                    result.Message = "数据库不存在,不可编辑";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                //对密码进行aes加密
                string password = CS.Base.Encrypt.BAES.Encrypt(entity.PASSWORD);
                entity.PASSWORD    = password;
                entity.UPDATE_UID  = SystemSession.UserID;
                entity.UPDATE_TIME = DateTime.Now;
                if (entity.ID == 0)
                {
                    entity.CREATE_UID  = SystemSession.UserID;
                    entity.CREATE_TIME = DateTime.Now;
                    i = BF_DATABASE.Instance.Add(entity);
                }
                else
                {
                    BF_DATABASE.Entity oldEntity = BF_DATABASE.Instance.GetEntityByKey <BF_DATABASE.Entity>(entity.ID);
                    entity.CREATE_UID  = oldEntity.CREATE_UID;
                    entity.CREATE_TIME = oldEntity.CREATE_TIME;
                    i = BF_DATABASE.Instance.UpdateByKey <BF_DATABASE.Entity>(entity, entity.ID);
                }

                if (i < 1)
                {
                    result.Message = "出现了未知错误";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }

                result.IsSuccess = true;
                result.Message   = "保存成功";
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = ex.Message;
                BLog.Write(BLog.LogLevel.WARN, "编辑数据库配置出错:" + ex.ToString());
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 26
0
        public ActionResult DeleteFile(int id, string rowkey, string yyyymmdd = "", string filename = "")
        {
            if (string.IsNullOrWhiteSpace(filename))
            {
                return(ShowAlert("文件名不可为空"));
            }
            string tableName = string.Empty;

            JsonResultData result = new JsonResultData();

            try
            {
                //验证
                BF_FILE.Entity entity = BF_FILE.Instance.CheckUpload(id, rowkey, yyyymmdd, out tableName);
                if (entity.IS_ALLOW_DELETE != 1)
                {
                    result.Message = entity.NAME + "的附件不可删除,若要删除,请联系管理员修改相应配置。";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                string path     = string.Format("{0}/{1}/{2}", AttachmentPath, tableName, rowkey);
                string fullName = path + "/" + filename;
                if (System.IO.File.Exists(fullName) == false)
                {
                    result.Message = "文件不存在";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                FileInfo fi    = new FileInfo(fullName);
                string   name  = fi.Name;
                int      index = name.IndexOf('_');
                string   user  = index > 20 ? name.Substring(20, (index - 20)) : "";
                if (user != SystemSession.UserName)
                {
                    result.Message = "不可以删除他人上传的附件,若要强制删除,请联系管理员。";
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
                fi.Delete();
                result.IsSuccess = true;
                result.Message   = "删除文件成功";
                WriteOperationLog(BLog.LogLevel.INFO, true, Modular, "删除附件", "", "删除表:" + tableName + " 的附件", "文件名:" + filename);
            }
            catch (Exception ex)
            {
                result.IsSuccess = false;
                result.Message   = ex.Message;
                BLog.Write(BLog.LogLevel.WARN, "删除附件【" + id + "】的文件【" + filename + "】出错:" + ex.ToString());
                WriteOperationLog(BLog.LogLevel.WARN, false, Modular, "删除附件", "", "删除表:" + tableName + " 的附件失败", "文件名:" + filename);
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 27
0
 /// <summary>
 /// 停止
 /// </summary>
 public static void Stop()
 {
     try
     {
         BLog.Write(BLog.LogLevel.INFO, "节点扫描线程即将停止。");
         _bw.CancelAsync();
         _bw.Dispose();
         BLog.Write(BLog.LogLevel.INFO, "节点扫描线程已经停止。");
     }
     catch (Exception ex)
     {
         BLog.Write(BLog.LogLevel.ERROR, "节点扫描线程停止失败。" + ex.ToString());
     }
 }
Esempio n. 28
0
        /// <summary>
        /// 导出文件附件
        /// </summary>
        /// <param name="wherestr">搜索条件</param>
        /// <returns>附件信息</returns>
        public ActionResult ExportFile(string message = "", int TaskId = 0)
        {
            try
            {
                string filename = HttpUtility.UrlEncode(string.Format("导出报表_任务日志_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss")), Encoding.UTF8);
                string path     = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");

                List <object> param = new List <object>();
                #region 添加参数
                string where = "TASK_ID=?";
                param.Add(TaskId);

                if (string.IsNullOrWhiteSpace(message) == false)
                {
                    where += " and message LIKE '%" + message.Replace('\'', ' ') + "%'";
                }
                #endregion

                var dt = BLL.FW.BF_ST_TASK_LOG.Instance.GetTableFields("LOG_TIME,LOG_LEVEL,MESSAGE", where, param);
                if (dt == null)
                {
                    return(ShowAlert("导出数据到Excel出现错误:未查询出数据"));
                }
                dt.Columns["LOG_TIME"].Caption  = "日志时间";
                dt.Columns["LOG_LEVEL"].Caption = "等级";
                dt.Columns["MESSAGE"].Caption   = "日志内容";

                Library.Export.ExcelFile export = new Library.Export.ExcelFile(path);
                string fullName = export.ToExcel(dt);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.Clear();//清除缓冲区所有内容
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
                System.Web.HttpContext.Current.Response.WriteFile(fullName);
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.End();
                //删除文件
                export.Delete(fullName);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "导出默认报表[DB]到Excel出错:" + ex.ToString());
                return(ShowAlert("导出数据到Excel出现未知错误:" + ex.Message));
            }
            return(ShowAlert("导出成功"));
        }
Esempio n. 29
0
        /// <summary>
        /// 导出文件附件
        /// </summary>
        /// <param name="wherestr">搜索条件</param>
        /// <returns>附件信息</returns>
        public ActionResult ExportFile(string daterange = "", string flowName = "", string nodeName = "", string param = "", string statusId = "", string successId = "")
        {
            try
            {
                string filename = HttpUtility.UrlEncode(string.Format("导出报表_脚本任务_{0}.xlsx", DateTime.Now.ToString("yyyyMMddHHmmss")), Encoding.UTF8);
                string path     = System.Web.HttpContext.Current.Server.MapPath("~/tmp/");

                int count = 0;
                var dt    = BF_ST_TASK.Instance.GetDataTable(0, 0, ref count, daterange, flowName, nodeName, param, statusId, successId);
                if (dt == null)
                {
                    return(ShowAlert("导出数据到Excel出现错误:未查询出数据"));
                }
                dt.Columns.Remove("ID");
                dt.Columns["FLOWNAME"].Caption       = "流程名称";
                dt.Columns["NODENAME"].Caption       = "节点名称";
                dt.Columns["IS_MANUAL"].Caption      = "手动启动";
                dt.Columns["REFERENCE_DATE"].Caption = "基准日期";
                dt.Columns["RETRY_TIMES"].Caption    = "重试次数";
                dt.Columns["RUN_STATUS"].Caption     = "运行状态";
                dt.Columns["IS_SUCCESS"].Caption     = "是否成功";
                dt.Columns["START_TIME"].Caption     = "开始时间";
                dt.Columns["FINISH_TIME"].Caption    = "结束时间";
                dt.Columns["CREATE_TIME"].Caption    = "创建时间";
                dt.Columns["REMARK"].Caption         = "备注";

                Library.Export.ExcelFile export = new Library.Export.ExcelFile(path);
                string fullName = export.ToExcel(dt);
                if (string.IsNullOrWhiteSpace(fullName) == true)
                {
                    return(ShowAlert("未生成Excel文件"));
                }
                System.Web.HttpContext.Current.Response.Buffer = true;
                System.Web.HttpContext.Current.Response.Clear();//清除缓冲区所有内容
                System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
                System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
                System.Web.HttpContext.Current.Response.WriteFile(fullName);
                System.Web.HttpContext.Current.Response.Flush();
                System.Web.HttpContext.Current.Response.End();
                //删除文件
                export.Delete(fullName);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "导出默认报表[DB]到Excel出错:" + ex.ToString());
                return(ShowAlert("导出数据到Excel出现未知错误:" + ex.Message));
            }
            return(ShowAlert("导出成功"));
        }
Esempio n. 30
0
        /// <summary>
        /// 写操作日志
        /// </summary>
        /// <param name="level">日志等级</param>
        /// <param name="isSuccess">是否成功</param>
        /// <param name="modular">功能模块</param>
        /// <param name="operation">操作</param>
        /// <param name="url">请求的URL</param>
        /// <param name="content">日志内容</param>
        /// <param name="detail">操作详情</param>
        public void WriteOperationLog(BLog.LogLevel level, bool isSuccess, string modular, string operation, string url, string content, string detail = "")
        {
            try
            {
                string srcIP   = GetClientIP();
                int    srcPort = 0;
                //BF_OP_LOG.Instance.AddLog(BLog.LogLevel.WARN, isSuccess, srcIP, srcPort, modular, operation, url, content, detail);

                BF_OP_LOG.Instance.AddLog(BLog.LogLevel.WARN, isSuccess, srcIP, srcPort, modular, operation, url, content, detail);
            }
            catch (Exception ex)
            {
                BLog.Write(BLog.LogLevel.WARN, "记录操作日志出错:" + ex.ToString());
            }
        }