示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string projectId = Request["projectId"];
                if (string.IsNullOrWhiteSpace(projectId))
                {
                    Javascript.Alert("您未指定要查看的项目!", Page);
                    Javascript.RefreshParentWindowReload(Page);
                }
                else
                {
                    DalOperationAboutProject dalProject = new DalOperationAboutProject();

                    Project project = dalProject.GetProject(int.Parse(projectId));
                    if (project == null)
                    {
                        Javascript.Alert("您查看的项目不存在!", Page);
                        Javascript.RefreshParentWindowReload(Page);
                    }
                    else {

                        UserCookiesInfo userCookiesInfo = BllOperationAboutUser.GetUserCookiesInfo();
                        string cookieUserNo = userCookiesInfo.userNo;

                        if (project.userNo == cookieUserNo || isAuth(cookieUserNo))
                        {

                            this.literal_ViewProjectName.Text = project.name;
                            this.literal_UserName.Text = project.userName;

                            DalOperationAboutProjectCategory dalProCate = new DalOperationAboutProjectCategory();
                            List<ProjectCategory> categoryList = dalProCate.GetProjectCategoryPathById(project.category.id);
                            string categoryPath = "";
                            bool hasPrefix = false;
                            foreach (ProjectCategory category in categoryList)
                            {
                                categoryPath += ((hasPrefix ? " -> " : "") + category.name);
                                hasPrefix = true;
                            }

                            this.literal_ViewProjectCategory.Text = categoryPath;

                            this.literal_CreatedTime.Text = project.createdTime.ToString();
                            this.literal_ProjectMemo.Text = project.memo;
                        }
                        else {
                            Javascript.Alert("您无权查看此页面!", Page);
                            Javascript.RefreshParentWindowReload(Page);
                        }
                    }
                }

            }
        }
示例#2
0
        public void ProcessRequest(HttpContext context)
        {
            string projectName = context.Request["pname"].Trim();
            string userName = context.Request["uname"].Trim();
            string rootCategoryId = context.Request["rc"].Trim();
            string subCategoryId = context.Request["sc"].Trim();
            string thirdCategoryId = context.Request["tc"].Trim();

            HSSFWorkbook workbook = new HSSFWorkbook();

            HSSFSheet projectSheet = workbook.CreateSheet("项目汇总");

            List<ProjectCategory> queryCategoryList = new List<ProjectCategory>();

            DalOperationAboutProject dalProject = new DalOperationAboutProject();
            DalOperationAboutProjectCategory dalProCate = new DalOperationAboutProjectCategory();

            if (!(string.IsNullOrWhiteSpace(thirdCategoryId) || "0" == thirdCategoryId.Trim()))
            {
                queryCategoryList.Add(dalProCate.GetProjectCategoryById(int.Parse(thirdCategoryId.Trim())));
            }
            else if (!(string.IsNullOrWhiteSpace(subCategoryId) || "0" == subCategoryId.Trim()))
            {
                queryCategoryList.AddRange(dalProCate.GetAllLastProjectCategoryByParentId(int.Parse(subCategoryId.Trim())));
            }
            else if (!(string.IsNullOrWhiteSpace(rootCategoryId) || "0" == rootCategoryId.Trim()))
            {

                queryCategoryList.AddRange(dalProCate.GetAllLastProjectCategoryByParentId(int.Parse(rootCategoryId.Trim())));
            }

            string categoryIds = null;

            if (queryCategoryList.Count != 0)
            {
                List<int> categoryIdList = new List<int>();
                foreach (ProjectCategory category in queryCategoryList)
                {
                    categoryIdList.Add(category.id);
                }

                categoryIds = string.Join(",", categoryIdList.ToArray());
            }

            List<Project> projectList;
            if (string.IsNullOrWhiteSpace(projectName) && string.IsNullOrWhiteSpace(userName) && string.IsNullOrWhiteSpace(categoryIds))
            {
                projectList = dalProject.GetAllProjects();
            }
            else
            {
                projectList = dalProject.GetPrjects(categoryIds, userName.Trim(), projectName.Trim());
            }

            SetProjectSheet(projectSheet, projectList);

            string fileName = "项目汇总";

            System.IO.FileStream file = new System.IO.FileStream(HttpContext.Current.Server.MapPath(fileName + ".xls"), System.IO.FileMode.Create);
            workbook.Write(file);
            file.Dispose();

            ////插入值
            FileInfo DownloadFile = new FileInfo(context.Server.MapPath(fileName + ".xls"));

            context.Response.Clear();
            context.Response.ClearHeaders();
            context.Response.Buffer = false;
            Encoding code = Encoding.GetEncoding("gb2312");
            context.Response.ContentEncoding = Encoding.UTF8;
            context.Response.HeaderEncoding = code;//这句很重要
            context.Response.ContentType = "application/octet-stream";
            context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls");
            context.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
            context.Response.WriteFile(DownloadFile.FullName);

            if (File.Exists(context.Server.MapPath(fileName + ".xls")))
            {
                File.Delete(context.Server.MapPath(fileName + ".xls"));
            }
            context.Response.Flush();
        }