Esempio n. 1
0
        public void ExportCheckRecord()
        {
            var page    = Panasia.Core.App.AppConfig.Current.GetPage("P01045");
            var action  = page.Config.Actions["ExportQuery"];
            var context = new WebContext
            {
                Controller  = this,
                Request     = Request.Params,
                Page        = page,
                Files       = Request.Files,
                ActionValue = SysService.GetCurrentUserPageActionValue(page.PageID)
            };

            /*导出命名方法测试*/
            #region
            context.Execute(action);
            StringBuilder sb = new StringBuilder();
            sb.Append("<style type=\"text/css\">");
            sb.Append("<!--");
            sb.Append(".text");
            sb.Append("{mso-style-parent:style0;");
            sb.Append("font-size:10.0pt;");
            sb.Append("font-family:\"Arial Unicode MS\", sans-serif;");
            sb.Append("mso-font-charset:0;");
            sb.Append(@"mso-number-format:\@;");
            sb.Append("text-align:center;");
            sb.Append("border:.5pt solid black;");
            sb.Append("white-space:normal;}");
            sb.Append("-->");
            sb.Append("</style>");
            sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
            sb.Append("<tr align=\"Center\" style=\"font-weight:bold;\">");
            sb.Append("<td align=\"Center\" style=\"font-weight:bold;\" ColumnSpan =\"3\">测试测试</td>");
            sb.Append("</tr>");
            sb.Append("<tr align=\"Center\" style=\"font-weight:bold;\">");
            sb.Append("<td align=\"Center\" style=\"font-weight:bold;\" ColumnSpan =\"3\">日期:2014-10-15</td>");
            sb.Append("</tr>");
            sb.Append("<tr align=\"Center\" style=\"font-weight:bold;\">");
            sb.Append("<td>部门</td><td>姓名</td><td>入职日期</td><td>离职日期</td><td>出勤天数</td><td>实际出勤天数</td><td>带薪假天数</td><td>迟到次数</td>");
            sb.Append("<td>早退次数</td><td>病假天数</td><td>事假天数</td><td>旷工天数</td><td>缺勤天数</td><td>满勤天数</td><td>异常出勤明细</td>");//td显示应该是工具配置,对应哪个字段
            sb.Append("</tr>");

            var queryResult = context.Results["导出查询"] as CommandResult;
            //var f = queryResult.GetFieldValue<string>("data");
            //var n = queryResult.GetFieldNames();
            //var v = queryResult.GetNameValues();
            //var pv = queryResult.GetPathValue("导出查询");
            //var items  = queryResult.GetValue("Items");
            dynamic prov = queryResult.GetPropertyValue("Items");//和GetValue返回数据一样
            if (prov != null)
            {
                //Assembly tempAssembly = Assembly.LoadFrom(@"D:\code\PA\Panasia.Gemini\Documents\Dll\Panasia.Core.Commands.dll");
                //object o = tempAssembly.CreateInstance("RowEntity");
                //Type t = tempAssembly.GetType();
                foreach (var item in prov)
                {
                    sb.Append("<tr align=\"Center\">");
                    sb.Append("<td>" + item["DeptName"] + "</td>");//工具取字段名
                    sb.Append("<td>" + item["UserName"] + "</td>");
                    sb.Append("<td>" + item["HireDate"] + "</td>");
                    sb.Append("<td>" + item["Terminate"] + "</td>");
                    sb.Append("<td>" + item["AttendanceDays"] + "</td>");
                    sb.Append("<td>" + item["RealAttendanceDays"] + "</td>");
                    sb.Append("<td>" + item["PaidHolidays"] + "</td>");
                    sb.Append("<td>" + item["LaterTimes "] + "</td>");
                    sb.Append("<td>" + item["LeaveEarlyTimes"] + "</td>");
                    sb.Append("<td>" + item["SickDays"] + "</td>");
                    sb.Append("<td>" + item["LeaveDays"] + "</td>");
                    sb.Append("<td>" + item["AbsenteeismDays"] + "</td>");
                    sb.Append("<td>" + item["AbsenceDays"] + "</td>");
                    sb.Append("<td>" + item["FullDays"] + "</td>");
                    sb.Append("<td>" + item["Remark"] + "</td>");
                    sb.Append("</tr>");
                }
            }
            #endregion
            #region
            //var result = context.Execute(action);
            ////以上代码应该调用工具配置和PageController生成的结果,下面处理结果存入表单
            //var demo = result.ToJson().ToString();
            //int index1 = demo.IndexOf("[");
            //int index2 = demo.IndexOf("]");
            //demo = demo.Substring(index1, index2);
            //var index3 = demo.LastIndexOf("]") - 1;
            //demo = demo.Substring(1, index3);
            //demo = demo.Replace("\\r\\n", "").Replace("\\", "");
            //demo = demo.Replace("},", "}|");
            //string[] ss = demo.Split('|');
            //for (int i = 0; i < ss.Length;i++ )
            //{
            //    dynamic data = JsonConvert.DeserializeObject(ss[i]);
            //    if(data != null)
            //    {
            //        sb.Append("<tr align=\"Center\">");
            //        sb.Append("<td>" + data.DeptName +"</td>");
            //        sb.Append("<td>" + data.UserName +"</td>");
            //        sb.Append("<td>" + data.HireDate +"</td>");
            //        sb.Append("<td>" + data.Terminate + "</td>");
            //        sb.Append("<td>" + data.AttendanceDays +"</td>");
            //        sb.Append("<td>" + data.RealAttendanceDays +"</td>");
            //        sb.Append("<td>" + data.PaidHolidays +"</td>");
            //        sb.Append("<td>" + data.LaterTimes +"</td>");
            //        sb.Append("<td>" + data.LeaveEarlyTimes +"</td>");
            //        sb.Append("<td>" + data.SickDays +"</td>");
            //        sb.Append("<td>" + data.LeaveDays +"</td>");
            //        sb.Append("<td>" + data.AbsenteeismDays +"</td>");
            //        sb.Append("<td>" + data.AbsenceDays + "</td>");
            //        sb.Append("<td>" + data.FullDays + "</td>");
            //        sb.Append("<td>" + data.Remark + "</td>");
            //        sb.Append("</tr>");
            //    }
            //}
            #endregion
            sb.Append("</table>");
            HttpResponseBase response = HttpContext.Response;
            response.Clear();
            response.ContentType = "application/ms-excel";
            if (HttpContext.Request.Browser.Type.StartsWith("Inter"))
            {
                response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("考勤月报表.xls", Encoding.GetEncoding("UTF-8")));
            }
            response.AppendHeader("Content-Disposition", "attachment;filename=" + "考勤月报表.xls");
            response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
            response.AddHeader("Pragma", "public");
            response.Write(sb.ToString());
            response.End();
            HttpContext.ApplicationInstance.CompleteRequest();
        }
Esempio n. 2
0
        public ActionResult Index(string pageID, string actionName)
        {
            var page = Panasia.Core.App.AppConfig.Current.GetPage(pageID);

            if (page == null || page.Config == null)
            {
                var error = Messages.System_PageNotFound;
                this.Log(string.Format("Receive Request\tPage:{0},Action:{1}\tError:{2}", pageID, actionName, error));
                throw new Exception(error);
            }
            if (!page.IsNetAllow())
            {
                throw new Exception(string.Format(
                                        LangTexts.Current.GetLangText("1003", "对不起,因网络受限,您不能使用功能[{0}],谢谢理解!"),
                                        page.Title));
            }
#if DEBUG
            var reloadPage = Request["reloadPage"];
            if (!string.IsNullOrEmpty(reloadPage))
            {
                page.ReloadConfig();
            }

            var reloadSql = Request["reloadSql"];
            if (!string.IsNullOrEmpty(reloadSql))
            {
                SqlData.ReloadCurrent();
            }
#endif
            dynamic mPage = page.Config;
            try
            {
                if (mPage.IsRedirect)
                {
                    return(RedirectToAction(string.IsNullOrEmpty(actionName) ? mPage.DefaultAction : actionName, mPage.Controller));
                }
            }
            catch
            {
                //如果出错,那么就不是MvcPage
            }

            var action = page.Config.Actions[actionName];
            if (action == null)
            {
                var error = string.Format(Messages.System_ActionNotFound, actionName);
                this.Log(string.Format("Receive Request\tPage:{0},Action:{1}\tError:{2}", pageID, actionName, error));
                throw new Exception(error);
            }

            var pageActionValue = SysService.GetCurrentUserPageActionValue(page.PageID);
            if (pageActionValue == 0)
            {
                return(RedirectToAction("TimeOut", "Home"));
            }
            if (pageActionValue == 0 || ((pageActionValue & action.ActionValue) != action.ActionValue))
            {
                var error = Messages.System_ActionNotAllowed;
                this.Log(string.Format("Receive Request\tPage:{0},Action:{1}\tError:{2}", pageID, actionName, error));
                throw new Exception(error);
            }

            var context = new WebContext
            {
                Controller  = this,
                Request     = Request.Params,
                User        = User,
                Page        = page,
                Files       = Request.Files,
                ActionValue = SysService.GetCurrentUserPageActionValue(page.PageID)
            };

            string actionTitle = string.Format("{0}-{1}", page.Title, action.Title);
            try
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("{");
                foreach (var key in Request.Form.AllKeys)
                {
                    sb.AppendFormat("{0}:{1};", key, Request.Form[key]);
                }
                foreach (var key in Request.QueryString.AllKeys)
                {
                    sb.AppendFormat("{0}:{1};", key, Request.QueryString[key]);
                }
                sb.Append("}");

                this.Log(string.Format("Receive Request\tPage:{0},Action:{1},Parameters:{2}", pageID, actionName, sb.ToString()));

                UserLogService.AddLog(actionTitle, Request.RawUrl, sb.ToString());
                var result = context.Execute(action);

                string eventName = string.Format("{0}/{1}", page.PageID, action.Name);
                ThreadPool.QueueUserWorkItem((o) =>
                {
                    AppConfig.Current.EventActions.HandleEvents(eventName, context);
                });

                this.Log(string.Format("End Request\tPage:{0},Action:{1}", pageID, actionName));
                return(result);
            }
            catch (Exception ex)
            {
                UserLogService.AddLog(actionTitle, Request.RawUrl, ex.Message);
                this.Log(string.Format("End Request\tPage:{0},Action:{1} \tError:{2}", pageID, actionName, ex.Message));
                throw;
            }
        }