public bool HandleResult( IResult result, IFormatInfo outputFormat, HttpRequestBase request, HttpResponseBase response )
        {
            response.AddHeader("Accept-Ranges", "bytes");

            Range range;
            if ( !TryGetRequestedRange( request, out range ) )
            {
                return false;
            }

            if (!ValidateIfRangeHeader(request, result))
            {
                return false;
            }

            var offset = range.Start ?? 0;
            var end = range.End.HasValue ? range.End.Value : result.ContentLength - 1;
            var length = end - offset + 1;

            response.AddHeader( "Content-Range", "bytes " + offset + "-" + end + "/" + result.ContentLength );
            response.StatusCode = 206;

            result.Serve( response, offset, length );
            return true;
        }
예제 #2
0
        public static ActionResult GetFile(HttpResponseBase Response, HttpRequestBase Request, HttpServerUtilityBase Server,
            string filePath, string fileName, string contentType, string userFileName)
        {
            byte[] value;
            using (FileStream stream = System.IO.File.Open(filePath, FileMode.Open))
            {
                value = new byte[stream.Length];
                stream.Read(value, 0, (int)stream.Length);
            }
            //const string userFileName = "MissionOrder.pdf";
            //const string contentType = "application/pdf";
            Response.Clear();
            if (Request.Browser.Browser == "IE")
            {
                string attachment = String.Format("attachment; filename=\"{0}\"", Server.UrlPathEncode(userFileName));
                Response.AddHeader("Content-Disposition", attachment);
            }
            else
                Response.AddHeader("Content-Disposition", "attachment; filename=\"" + userFileName + "\"");

            Response.ContentType = contentType;
            Response.Charset = "utf-8";
            Response.HeaderEncoding = Encoding.UTF8;
            Response.ContentEncoding = Encoding.UTF8;
            Response.BinaryWrite(value);
            Response.End();
            return null;
        }
예제 #3
0
 public static void OutputExcel(HttpResponseBase response, string filename, ExcelPackage pck)
 {
     pck.SaveAs(response.OutputStream);
     response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
     response.AddHeader("content-disposition", "attachment;  filename=" + filename + ".xlsx");
     response.AddHeader("Content-Length", pck.Stream.Length.ToString());
 }
예제 #4
0
파일: GZip.cs 프로젝트: sempf/Dev
        public static void setGZipCompression_forAjaxRequests(HttpRequestBase request, HttpResponseBase response)
        {
            //based on code from http://geekswithblogs.net/rashid/archive/2007/09/15/Compress-Asp.net-Ajax-Web-Service-Response---Save-Bandwidth.aspx
            if (TMConfig.Current.TMSetup.EnableGZipForWebServices.isFalse())
                return;
            try
            {
                if (request.ContentType.lower().starts(new List<string> {"text/xml", "application/json"}))
                {
                    string acceptEncoding = request.Headers["Accept-Encoding"];

                    if (!string.IsNullOrEmpty(acceptEncoding))
                    {
                        acceptEncoding = acceptEncoding.ToLower(CultureInfo.InvariantCulture);

                        if (acceptEncoding.Contains("gzip"))
                        {
                            response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
                            response.AddHeader("Content-encoding", "gzip");
                        }
                        else if (acceptEncoding.Contains("deflate"))
                        {
                            response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
                            response.AddHeader("Content-encoding", "deflate");
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                ex.log("in enableGZipCompression_forAjaxRequests");
            }
        }
        private void HandleAjaxRequest(NotifyEntry entry, HttpResponseBase response)
        {
            if (entry == null)
                return;

            response.AddHeader("X-Message-Type", entry.Type.ToString().ToLower());
            response.AddHeader("X-Message", entry.Message.Text);
        }
예제 #6
0
        public static void UpdateNoCacheForResponse(HttpResponseBase response)
        {
            response.Buffer = false;
            response.BufferOutput = false;

            response.AddHeader("Expires", "Fri, 01 Jan 1980 00:00:00 GMT");
            response.AddHeader("Pragma", "no-cache");
            response.AddHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
        }
예제 #7
0
 private void CreateFileResponse(HttpResponseBase response, AttachmentDO attachment)
 {
     var fileData = attachment.Bytes;
     
     response.ContentType = "application/octet-stream";
     response.AddHeader("Content-Disposition", "filename=\"" + attachment.OriginalName + "\"");
     response.AddHeader("Content-Length", fileData.LongLength.ToString());
     response.AddHeader("Content-Type", attachment.Type + "; name=\"" + attachment.OriginalName + "\";");
     //Write the data
     response.BinaryWrite(fileData);
 }
		protected HttpResponseBase PrepareResponse(HttpResponseBase response)
		{
			response.ContentType = ContentType;

			if (FileName.HasValue())
			{
				response.AddHeader("Content-Disposition", "attachment; filename=\"{0}\"".FormatCurrent(SanitizeFileName(FileName)));
			}

			response.AddHeader("Content-Type", ContentType);

			return response;
		}
 private IHttpHandler Redirect(HttpResponseBase response, string url)
 {
     response.AddHeader("Location", url);
     response.StatusCode = 301;
     response.End();
     return null;
 }
예제 #10
0
        protected override void WriteFile(HttpResponseBase response)
        {
            response.AddHeader("content-disposition", $"attachment;  filename={FileName}.xlsx");

            var generator = _settings.CreateGenerator();
            GenerateExcelFile(generator, response.OutputStream);
        }
예제 #11
0
        /// <summary>
        /// Copies the full binary contents of the given blob to the given HTTP response.
        /// </summary>
        private static void CopyContents(CloudBlob blob, HttpResponseBase response, long offset = 0)
        {
            blob.FetchAttributes();

            response.BufferOutput = false;
            response.AddHeader("Content-Length", blob.Attributes.Properties.Length.ToString());
            response.Flush();

            using (var reader = blob.OpenRead())
            {
                reader.Seek(offset, System.IO.SeekOrigin.Begin);

                byte[] buffer = new byte[1024 * 4]; // 4KB buffer
                while (reader.CanRead)
                {
                    int numBytes = reader.Read(buffer, 0, buffer.Length);

                    if (numBytes <= 0)
                        break;

                    response.BinaryWrite(buffer);
                    response.Flush();
                }
            }
        }
예제 #12
0
        public void SendMessages(HttpResponseBase response, HttpRequestBase request, IEnumerable<Message> messages)
        {
            if ( !String.IsNullOrEmpty( CometHttpHandler.AllowOrigin ) && request.Headers["Origin"]!=null ) {
            if ( CometHttpHandler.IsOriginAllowed( new Uri( request.Headers["Origin"] ) ) ) {
              response.AddHeader( "Access-Control-Allow-Origin", request.Headers["Origin"] );
              response.AddHeader( "Access-Control-Allow-Methods", "POST, GET, OPTIONS" );
              response.AddHeader( "Access-Control-Max-Age", ( 24 * 60 * 60 ).ToString() );
              if ( request.Headers["Access-Control-Request-Headers"] != null ) {
                response.AddHeader( "Access-Control-Allow-Headers", request.Headers["Access-Control-Request-Headers"] );
              }
            }
              }

              response.ContentType = "text/json";
            response.Write(MessageConverter.ToJson(messages));
        }
예제 #13
0
 public static bool IsFileFromCache(FileInfo info, HttpRequestBase request, HttpResponseBase response)
 {
     DateTime updated = info.LastWriteTimeUtc;
     string filename = info.Name;
     DateTime modifyDate;
     if (!DateTime.TryParse(request.Headers["If-Modified-Since"], out modifyDate))
     {
         modifyDate = DateTime.UtcNow;
     }
     string eTag = GetFileETag(filename, updated);            
     if (!IsFileModified(updated, eTag, request))
     {
         response.StatusCode = (int)System.Net.HttpStatusCode.NotModified;
         response.StatusDescription = "Not Modified";
         response.AddHeader("Content-Length", "0");
         response.Cache.SetCacheability(HttpCacheability.Public);
         response.Cache.SetLastModified(updated);
         response.Cache.SetETag(eTag);
         return true;
     }
     else
     {
         response.Cache.SetAllowResponseInBrowserHistory(true);
         response.Cache.SetCacheability(HttpCacheability.Public);
         response.Cache.SetLastModified(updated);
         response.Cache.SetETag(eTag);
         return false;
     }
 }
예제 #14
0
        protected override void WriteFile(HttpResponseBase response)
        {
            response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", FileDownloadName));
            byte[] fileContents = Convert.FromBase64String(_base64);

            response.BinaryWrite(fileContents);
            response.End();
        }
예제 #15
0
 public void FileDownload(HttpResponseBase response,string filePah)
 {
     if(!IsExists(filePah)) {
         throw new Exception("�ļ�������");
     }
     var fileInfo = new FileInfo(filePah);
     response.Clear();
     response.ClearContent();
     response.ClearHeaders();
     response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name,System.Text.Encoding.UTF8));
     response.AddHeader("Content-Length", fileInfo.Length.ToString());
     //response.AddHeader("Content-Transfer-Encoding", "binary");
     response.ContentType = "application/vnd.ms-excel;charset=UTF-8";
     response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
     response.WriteFile(fileInfo.FullName);
     response.Flush();
     response.End();
 }
예제 #16
0
		public void WriteToHttpResponse(HttpResponseBase httpResponse)
		{
			httpResponse.Clear();
			httpResponse.ContentType = "application/zip";
			httpResponse.AddHeader("Content-Disposition", "attachment;filename=remoting-package.zip");

			WriteToStream(httpResponse.OutputStream);

			httpResponse.End();
		}
 public static void ExportCsv(ExportEventArgs options, HttpResponseBase response)
 {
     response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}.csv", options.Title));
     response.ContentType = "application/csv";
     if (CultureInfo.CurrentUICulture.Name != "en-US")
     {
         response.ContentEncoding = Encoding.Unicode;
     }
     response.Write(options.Document);
 }
예제 #18
0
 public static void DiplomProjectToWord(string fileName, DiplomProject work, HttpResponseBase response)
 {
     response.Clear();
     response.Charset = "ru-ru";
     response.HeaderEncoding = Encoding.UTF8;
     response.ContentEncoding = Encoding.UTF8;
     response.ContentType = "application/vnd.ms-word";
     response.AddHeader("Content-Disposition", "attachment; filename=" + fileName + ".doc");
     CreateDoc(work, response);
     response.Flush();
     response.End();
 }
예제 #19
0
 /// <summary>
 /// Append header to response
 /// </summary>
 /// <remarks>
 /// Seems like appendheader only works with IIS 7
 /// </remarks>
 /// <param name="response"></param>
 /// <param name="httpResponseHeader"></param>
 /// <param name="headerValue"></param>
 public void AppendHeader(HttpResponseBase response, string httpResponseHeader, string headerValue)
 {
     switch (WebServerType)
     {
         case WebServerType.IIS7:
             response.AppendHeader(httpResponseHeader, headerValue);
             break;
         default:
             response.AddHeader(httpResponseHeader, headerValue);
             break;
     }
 }
예제 #20
0
        private void PrepareResponse(HttpResponseBase response, string downloadTokenValue, string zipFilename)
        {
            response.ContentType = "application/zip";

            if (string.IsNullOrEmpty(downloadTokenValue) == false)
            {
                //downloadTokenValue will have been provided in the form submit via the hidden input field
                response.AppendCookie(new HttpCookie("fileDownloadToken", downloadTokenValue));
            }

            response.AddHeader("content-disposition",
                               string.Format("attachment; filename={0}.zip", zipFilename));
        }
예제 #21
0
        private void SetHttpResponse(HttpResponseBase httpResponse, string fileNameWithoutExtension, ExcelPackage package)
        {
            httpResponse.ClearContent();
            httpResponse.Buffer = true;

            //Write it back to the client
            httpResponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            httpResponse.AddHeader("content-disposition", string.Format("attachment;  filename={0}.xlsx", fileNameWithoutExtension));
            httpResponse.BinaryWrite(package.GetAsByteArray());

            httpResponse.Flush();
            httpResponse.End();
        }
        public bool HandleResult(IResult result, IFormatInfo outputFormat, HttpRequestBase request, HttpResponseBase response)
        {
            response.Cache.VaryByHeaders["Accept-Encoding"] = true;

            if (!outputFormat.AllowCompression)
            {
                return false;
            }

            ICompression compression;
            if (!TryGetCompressionFromRequest(request, out compression))
            {
                return false;
            }

            response.Filter = compression.Compress(response.Filter);
            response.AddHeader("Content-Encoding", compression.ContentEncoding);
            return false;
        }
예제 #23
0
        public static void DumpXls(HttpResponseBase response, DataTable table, string fileName)
        {
            var grid = new GridView();
            grid.DataSource = table;
            grid.DataBind();

            response.ClearContent();
            response.Buffer = true;
            response.AddHeader("content-disposition", string.Format("attachment; filename={0}.xls", fileName));
            response.ContentType = "application/ms-excel";

            response.Charset = "";
            var sw = new StringWriter();
            var htw = new HtmlTextWriter(sw);

            grid.RenderControl(htw);

            response.Output.Write(sw.ToString());
            response.Flush();
            response.End();
        }
예제 #24
0
        private bool ValidateEntityTag(HttpRequestBase request, HttpResponseBase response)
        {
            string matchHeader = GetHeader(request, "If-Match");
            if (!String.IsNullOrEmpty(matchHeader) && matchHeader != "*")
            {
                string[] entitiesTags = matchHeader.Split(_commaSplitArray);
                int entitieTagIndex;
                for (entitieTagIndex = 0; entitieTagIndex < entitiesTags.Length; entitieTagIndex++)
                {
                    if (EntityTag == entitiesTags[entitieTagIndex])
                        break;
                }

                if (entitieTagIndex >= entitiesTags.Length)
                {
                    response.StatusCode = 412;
                    return false;
                }
            }

            string noneMatchHeader = GetHeader(request, "If-None-Match");
            if (!String.IsNullOrEmpty(noneMatchHeader))
            {
                if (noneMatchHeader == "*")
                {
                    response.StatusCode = 412;
                    return false;
                }

                string[] entitiesTags = noneMatchHeader.Split(_commaSplitArray);
                foreach (string entityTag in entitiesTags)
                {
                    if (EntityTag == entityTag)
                    {
                        response.AddHeader("ETag", String.Format("\"{0}\"", entityTag));
                        response.StatusCode = 304;
                        return false;
                    }
                }
            }

            return true;
        }
        private static void ProcessRequestInternal(
            HttpResponseBase response,
            string decryptedString,
            VirtualFileReader fileReader) {

            if (String.IsNullOrEmpty(decryptedString)) {
                Throw404();
            }
            bool zip;
            bool singleAssemblyReference;
            // See GetScriptResourceUrl comment below for first character meanings.
            switch (decryptedString[0]) {
                case 'Z':
                case 'z':
                    singleAssemblyReference = true;
                    zip = true;
                    break;
                case 'U':
                case 'u':
                    singleAssemblyReference = true;
                    zip = false;
                    break;
                case 'Q':
                case 'q':
                    singleAssemblyReference = false;
                    zip = true;
                    break;
                case 'R':
                case 'r':
                    singleAssemblyReference = false;
                    zip = false;
                    break;
                case 'T':
                    OutputEmptyPage(response, decryptedString.Substring(1));
                    return;
                default:
                    Throw404();
                    return;
            }

            decryptedString = decryptedString.Substring(1);
            if (String.IsNullOrEmpty(decryptedString)) {
                Throw404();
            }
            string[] decryptedData = decryptedString.Split('|');

            if (singleAssemblyReference) {
                // expected: <assembly>|<resource>|<culture>[|#|<hash>]
                if (decryptedData.Length != 3 && decryptedData.Length != 5) {
                    // The decrypted data must have 3 parts plus an optional 2 part hash code separated by pipes.
                    Throw404();
                }
            }
            else {
                // expected: <assembly1>|<resource1a>,<culture1a>,<resource1b>,<culture1b>,...|<assembly2>|<resource2a>,<culture2a>,<resource2b>,<culture2b>,...|#|<hash>
                if (decryptedData.Length % 2 != 0) {
                    // The decrypted data must have an even number of parts separated by pipes.
                    Throw404();
                }
            }

            StringBuilder script = new StringBuilder();

            string firstContentType = null;

            if (singleAssemblyReference) {
                // single assembly reference, format is
                // <assembly>|<resource>|<culture>
                string assemblyName = decryptedData[0];
                string resourceName = decryptedData[1];
                string cultureName = decryptedData[2];

                Assembly assembly = GetAssembly(assemblyName);
                if (assembly == null) {
                    Throw404();
                }

                script.Append(ScriptResourceAttribute.GetScriptFromWebResourceInternal(
                    assembly,
                    resourceName,
                    String.IsNullOrEmpty(cultureName) ? CultureInfo.InvariantCulture : new CultureInfo(cultureName),
                    zip,
                    out firstContentType
                ));
            }
            else {
                // composite script reference, format is:
                // <assembly1>|<resource1a>,<culture1a>,<resource1b>,<culture1b>,...|<assembly2>|<resource2a>,<culture2a>,<resource2b>,<culture2b>,...
                // Assembly is empty for path based scripts, and their resource/culture list is <path1>,<path2>,...
                
                // If an assembly starts with "#", the segment is ignored (expected that this includes a hash to ensure
                // url uniqueness when resources are changed). Also, for forward compatibility '#' segments may contain
                // other data. 

                bool needsNewline = false;

                for (int i = 0; i < decryptedData.Length; i += 2) {
                    string assemblyName = decryptedData[i];
                    bool hasAssembly = !String.IsNullOrEmpty(assemblyName);
                    if (hasAssembly && assemblyName[0] == '#') {
                        // hash segments are ignored, it contains a hash code for url uniqueness
                        continue;
                    }
                    Debug.Assert(!String.IsNullOrEmpty(decryptedData[i + 1]));
                    string[] resourcesAndCultures = decryptedData[i + 1].Split(',');

                    if (resourcesAndCultures.Length == 0) {
                        Throw404();
                    }

                    Assembly assembly = hasAssembly ? GetAssembly(assemblyName) : null;

                    if (assembly == null) {
                        // The scripts are path-based
                        if (firstContentType == null) {
                            firstContentType = "text/javascript";
                        }
                        for (int j = 0; j < resourcesAndCultures.Length; j++) {
                            Encoding encoding;
                            // DevDiv Bugs 197242
                            // path will either be absolute, as in "/app/foo/bar.js" or app relative, as in "~/foo/bar.js"
                            // ToAbsolute() ensures it is in the form /app/foo/bar.js
                            // This conversion was not done when the url was created to conserve url length.
                            string path = _bypassVirtualPathResolution ?
                                resourcesAndCultures[j] :
                                VirtualPathUtility.ToAbsolute(resourcesAndCultures[j]);
                            string fileContents = fileReader(path, out encoding);

                            if (needsNewline) {
                                // Output an additional newline between resources but not for the last one
                                script.Append('\n');
                            }
                            needsNewline = true;

                            script.Append(fileContents);
                        }
                    }
                    else {
                        Debug.Assert(resourcesAndCultures.Length % 2 == 0, "The list of resource names and cultures must have an even number of parts separated by commas.");

                        for (int j = 0; j < resourcesAndCultures.Length; j += 2) {
                            try {
                                string contentType;
                                string resourceName = resourcesAndCultures[j];
                                string cultureName = resourcesAndCultures[j + 1];

                                if (needsNewline) {
                                    // Output an additional newline between resources but not for the last one
                                    script.Append('\n');
                                }
                                needsNewline = true;

                                script.Append(ScriptResourceAttribute.GetScriptFromWebResourceInternal(
                                    assembly,
                                    resourceName,
                                    String.IsNullOrEmpty(cultureName) ? CultureInfo.InvariantCulture : new CultureInfo(cultureName),
                                    zip,
                                    out contentType
                                ));

                                if (firstContentType == null) {
                                    firstContentType = contentType;
                                }
                            }
                            catch (MissingManifestResourceException ex) {
                                throw Create404(ex);
                            }
                            catch (HttpException ex) {
                                throw Create404(ex);
                            }
                        }
                    }
                }
            }

            if (ScriptingScriptResourceHandlerSection.ApplicationSettings.EnableCaching) {
                PrepareResponseCache(response);
            }
            else {
                PrepareResponseNoCache(response);
            }

            response.ContentType = firstContentType;

            if (zip) {
                using (MemoryStream zipped = new MemoryStream()) {
                    using (Stream outputStream = new GZipStream(zipped, CompressionMode.Compress)) {
                        // The choice of an encoding matters little here.
                        // Input streams being of potentially different encodings, UTF-8 is the better
                        // choice as it's the natural encoding for JavaScript.
                        using (StreamWriter writer = new StreamWriter(outputStream, Encoding.UTF8)) {
                            writer.Write(script.ToString());
                        }
                    }
                    byte[] zippedBytes = zipped.ToArray();
                    response.AddHeader("Content-encoding", "gzip");
                    response.OutputStream.Write(zippedBytes, 0, zippedBytes.Length);
                }
            }
            else {
                // Bug DevDiv #175061, we don't want to force any encoding here and let the default
                // encoding apply no matter what the incoming scripts might have been encoded with.
                response.Write(script.ToString());
            }
        }
예제 #26
0
        public static void Export(HttpResponseBase Response, string strStudentId)
        {
            HallTicketDataAccess dataaccess = new HallTicketDataAccess();
            DataTable dt = dataaccess.GetHallTickets(strStudentId);
            Response.AddHeader("Content-Disposition", "attachment; filename=" + "PrintHalltickets.doc");
            Response.Write("<html " + "xmlns:o='urn:schemas-microsoft-com:office:office' " + "xmlns:w='urn:schemas-microsoft-com:office:word'" + "xmlns='http://www.w3.org/TR/REC-html40'>" + "<head><title>Time</title>");
            Response.Write("<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">");
            Response.Write("<meta name=ProgId content=Word.Document>");
            Response.Write("<meta name=Generator content=\"Microsoft Word 9\">");
            Response.Write("<meta name=Originator content=\"Microsoft Word 9\">");

            Response.Write("<!--[if gte mso 9]>" + "<xml>" + "<w:WordDocument>" + "<w:View>Print</w:View>" + "<w:Zoom>90</w:Zoom>" + "<w:DoNotOptimizeForBrowser/>" + "</w:WordDocument>" + "</xml>" + "<![endif]-->");
            Response.Write("<style> @page" + "{size:8.5in 11.0in; mso-first-footer:ff1; mso-footer: f1;" + " margin:0.2in 0.2in 0.2in 0.2in ; " + " mso-header-margin:.1in; " + " mso-footer-margin:.1in; mso-paper-source:0;}" + " div.Section1" + " {page:Section1;}" + "p.MsoFooter, li.MsoFooter, div.MsoFooter{margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:center 3.0in right 6.0in; font-size:12.0pt; font-family:'Verdana';}" + "p.MsoHeader, li.MsoHeader, div.MsoHeader {margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; tab-stops:center 3.0in right 6.0in; font-size:12.0pt; font-family:'Verdana';}" + "table#hrdftrtbl { margin:0in 0in 0in 0.1in; }" + "-->" + "</style>" + "</head>");
            Response.Write("<body lang=EN-US style='tab-interval:.5in'>");

            Response.Write("<table stle=\"width: 8.5in;\">");
            foreach (DataRow dr in dt.Rows)
            {
                Response.Write("<tr>");
                Response.Write("<td colspan=2 style=\"height: 0.25in;\">");
                Response.Write("</td>");
                Response.Write("</tr>");

                Response.Write("<tr>");
                Response.Write("<td colspan=2 align=\"center\">Exam Name</td>");
                Response.Write("</tr>");
                Response.Write("<tr>");
                Response.Write("<td colspan=2 style=\"height: 0.25in;\">");
                Response.Write("</td>");
                Response.Write("</tr>");
                Response.Write("<tr>");
                Response.Write("<td>" + GetSideHeader("Hall Ticket Number"));
                Response.Write("</td>");
                Response.Write("<td>" + dr["HallTicketNo"].ToString());
                Response.Write("</td>");
                Response.Write("</tr>");
                Response.Write("<tr>");
                Response.Write("<td>" + GetSideHeader("Student Name"));
                Response.Write("</td>");
                Response.Write("<td>" + dr["Name"].ToString());
                Response.Write("</td>");
                Response.Write("</tr>");
                Response.Write("<tr>");
                Response.Write("<td>" + GetSideHeader("Father's Name"));
                Response.Write("</td>");
                Response.Write("<td>" + dr["FatherName"].ToString());
                Response.Write("</td>");
                Response.Write("</tr>");
                Response.Write("<tr>");
                Response.Write("<td>" + GetSideHeader("School Name"));
                Response.Write("</td>");
                Response.Write("<td>" + dr["SchoolName"].ToString());
                Response.Write("</td>");
                Response.Write("</tr>");
                Response.Write("<tr>");
                Response.Write("<td>" + GetSideHeader("Course Code"));
                Response.Write("</td>");
                Response.Write("<td>" + dr["CourseCode"].ToString());
                Response.Write("</td>");
                Response.Write("</tr>");
                Response.Write("<tr>");
                Response.Write("<td>" + GetSideHeader("Exam Schedule"));
                Response.Write("</td>");
                Response.Write("<td>" + dr["ExamSchedule"].ToString());
                Response.Write("</td>");
                Response.Write("</tr>");
                Response.Write("<tr>");
                Response.Write("<td>" + GetSideHeader("Exam Center Address"));
                Response.Write("</td>");
                Response.Write("<td>" + dr["ExamCenterAddress"].ToString());
                Response.Write("</td>");
                Response.Write("</tr>");

            }
            Response.Write("</table>");

            Response.Write("</body></head>");
            Response.Write("</html>");
            Response.Flush();
        }
예제 #27
0
            internal void 导出供应商手机号(Dictionary<string,string> dics,HttpResponseBase rs)
            {
                var wb = CreateWorkbook(_excelVer);

                //设置分类样式
                var font = wb.CreateFont();
                font.FontName = "宋体";
                font.FontHeightInPoints = 16;
                font.Color = (short)FontColor.Red;
                ICellStyle style = wb.CreateCellStyle();
                style.VerticalAlignment = VerticalAlignment.Center;
                style.SetFont(font);
                style.Alignment = HorizontalAlignment.Center;

                IMongoQuery query = null;
                if (dics["审核状态"] != "-1")
                    query = query.And(Query<供应商>.Where(o => (int)o.审核数据.审核状态 == int.Parse(dics["审核状态"])));
                if (dics["认证级别"] != "0")
                    query = query.And(Query<供应商>.Where(o => (int)o.供应商用户信息.认证级别 == int.Parse(dics["认证级别"])));
                if (dics["所属行业"] != "请选择")
                    query = query.And(Query<供应商>.Where(o => o.企业基本信息.所属行业.Contains(dics["所属行业"])));
                if (dics["协议应急普通"] != "请选择")
                {
                    if (dics["协议应急普通"] == "普通供应商")
                        query = query.And(Query<供应商>.Where(o => o.供应商用户信息.普通供应商));
                    if (dics["协议应急普通"] == "协议供应商")
                        query = query.And(Query<供应商>.Where(o => o.供应商用户信息.协议供应商));
                    if (dics["协议应急普通"] == "应急供应商")
                        query = query.And(Query<供应商>.Where(o => o.供应商用户信息.应急供应商));
                }
                if (dics["省"] != "")
                {
                    query = query.And(Query<供应商>.Where(o => o.所属地域.省份 == dics["省"]));
                    if (dics["市"] != "")
                    {
                        query = query.And(Query<供应商>.Where(o => o.所属地域.城市 == dics["市"]));
                        if (dics["县"] != "")
                        {
                            query = query.And(Query<供应商>.Where(o => o.所属地域.区县 == dics["县"]));
                        }
                    }
                }
                //if (dics["短信服务"] != "0")
                //{
                //    var 供应商服务记录 = 供应商服务记录管理.查询供应商服务记录(0, 0, null, false, SortBy<供应商服务记录>.Ascending(o => o.基本数据.修改时间));
                //    var A2广告位置服务记录 = 供应商服务记录.Where(o => o.已开通的服务.Exists(p => p.所申请项目名 == "企业推广服务A2位置" && p.签订时间 < now && p.结束时间 > now));
                //}

                var ws = wb.CreateSheet("Sheet1");

                //数据准备
                var _gysCate = 用户管理.查询用户<供应商>(0, 0, query).ToList();
               
                //写入数据
                var rowsCount = 0;
                foreach (var its in _gysCate)
                {
                    rowsCount++;
                    var row = ws.CreateRow(rowsCount);
                    row.HeightInPoints = 20;
                    var cell = row.CreateCell(0);
                    cell.CellStyle = style;
                    for (int t = 0; t < 7; t++) //列
                    {
                        cell = row.CreateCell(t);
                        switch (t)
                        {
                            case 0: cell.SetCellValue(its.企业联系人信息.联系人手机); ws.SetColumnWidth(t, 5000); break;
                            case 1: cell.SetCellValue(its.企业基本信息.企业名称); ws.SetColumnWidth(t, 12000); break;
                            case 2: cell.SetCellValue(its.所属地域.地域); ws.SetColumnWidth(t, 5000); break;
                            case 3: cell.SetCellValue(its.审核数据.审核状态.ToString()); ws.SetColumnWidth(t, 3000); break;
                            case 4: cell.SetCellValue(its.供应商用户信息.认证级别.ToString()); ws.SetColumnWidth(t, 5000); break;
                            case 5: var ert = "";
                                if (its.供应商用户信息.协议供应商)
                                    ert = "协议供应商";
                                else if (its.供应商用户信息.应急供应商)
                                    ert = "应急供应商";
                                else if (its.供应商用户信息.普通供应商)
                                    ert = "普通供应商";
                                else
                                    ert = "未设置";
                                cell.SetCellValue(ert);
                                ws.SetColumnWidth(t, 4000);
                                break;
                            case 6: cell.SetCellValue(its.企业基本信息.所属行业); ws.SetColumnWidth(t, 5000); break;
                        }
                    }
                }

                rs.ContentType = "application/vnd.ms-excel";
                rs.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", "供应商手机号信息表" + DateTime.Now.Second.ToString()));
                wb.Write(rs.OutputStream);
            }
예제 #28
0
            internal void 专家信息(HttpResponseBase rs)
            {
                var wb = CreateWorkbook(_excelVer);
                var ws = wb.CreateSheet("专家信息表");
                //设置样式
                var font = wb.CreateFont();
                font.FontName = "微软雅黑";
                font.FontHeightInPoints = 12;

                var font_1 = wb.CreateFont();
                font.FontName = "宋体";
                font.FontHeightInPoints = 12;

                ICellStyle style = wb.CreateCellStyle();
                style.VerticalAlignment = VerticalAlignment.Center;
                style.SetFont(font);
                style.Alignment = HorizontalAlignment.Center;
                style.BorderBottom = BorderStyle.Thin;
                style.BorderLeft = BorderStyle.Thin;
                style.BorderRight = BorderStyle.Thin;
                style.BorderTop = BorderStyle.Thin;

                ws.AddMergedRegion(new CellRangeAddress(0, 1, 0, 11));
                var rowp = ws.CreateRow(0);
                var cellp = rowp.CreateCell(0);
                cellp.SetCellValue("专家信息表");
                var ft = wb.CreateFont();
                ft.FontName = "微软雅黑";
                ft.FontHeightInPoints = 15;

                ICellStyle style0 = wb.CreateCellStyle();
                style0.SetFont(ft);
                style0.Alignment = HorizontalAlignment.Center;
                cellp.CellStyle = style0;
                //内容表头
                var row = ws.CreateRow(2);
                row.HeightInPoints = 25;
                for (int k = 0; k < 12; k++)
                {
                    var cell = row.CreateCell(k);
                    switch (k)
                    {
                        case 0: cell.SetCellValue("姓名"); ws.SetColumnWidth(k, 3000); break;
                        case 1: cell.SetCellValue("性别"); ws.SetColumnWidth(k, 1800); break;
                        case 2: cell.SetCellValue("专家证号"); ws.SetColumnWidth(k, 7000); break;
                        case 3: cell.SetCellValue("证件类型"); ws.SetColumnWidth(k, 3000); break;
                        case 4: cell.SetCellValue("证件号"); ws.SetColumnWidth(k, 5500); break;
                        case 5: cell.SetCellValue("专业技术职称"); ws.SetColumnWidth(k, 4000); break;
                        case 6: cell.SetCellValue("毕业院校"); ws.SetColumnWidth(k, 7500); break;
                        case 7: cell.SetCellValue("最高学历"); ws.SetColumnWidth(k, 3000); break;
                        case 8: cell.SetCellValue("工作单位"); ws.SetColumnWidth(k, 7000); break;
                        case 9: cell.SetCellValue("从事专业"); ws.SetColumnWidth(k, 4500); break;
                        case 10: cell.SetCellValue("联系电话"); ws.SetColumnWidth(k, 5000); break;
                        case 11: cell.SetCellValue("备注"); ws.SetColumnWidth(k, 5000); break;
                    }
                    cell.CellStyle = style;
                }

                //填充内容
                var _zjlist = 用户管理.查询用户<专家>(0, 0).ToList();
                var length = _zjlist.Count();

                for (int p = 0; p < length; p++)   //行
                {
                    row = ws.CreateRow(3 + p);
                    row.HeightInPoints = 20;
                    for (int t = 0; t < 12; t++) //列
                    {
                        var cell = row.CreateCell(t);
                        switch (t)
                        {
                            //case 0: cell.SetCellValue(p + 1); break;
                            case 0: cell.SetCellValue(_zjlist[p].身份信息.姓名); break;
                            case 1: cell.SetCellValue(_zjlist[p].身份信息.性别.ToString()); break;
                            case 2: cell.SetCellValue(_zjlist[p].身份信息.专家证号); break;
                            case 3: cell.SetCellValue(_zjlist[p].身份信息.证件类型.ToString()); break;
                            case 4: cell.SetCellValue(_zjlist[p].身份信息.证件号); break;
                            case 5: cell.SetCellValue(_zjlist[p].学历信息.专业技术职称.ToString()); break;
                            case 6: cell.SetCellValue(_zjlist[p].学历信息.毕业院校); break;
                            case 7: cell.SetCellValue(_zjlist[p].学历信息.最高学历.ToString()); break;
                            case 8: cell.SetCellValue(_zjlist[p].工作经历信息.工作单位); break;
                            case 9: cell.SetCellValue(_zjlist[p].工作经历信息.从事专业); break;
                            case 10: cell.SetCellValue(_zjlist[p].联系方式.手机); break;
                        }
                        style.SetFont(font_1);
                        cell.CellStyle = style;
                    }
                }
                ws.PrintSetup.Landscape = true;//设置横向打印
                ws.PrintSetup.PaperSize = 9; //设置打印纸张
                ws.PrintSetup.Scale = 94;  //设置缩放
                ws.FitToPage = false;
                //ws.SetRowBreak((page + 1) * 20);  //设置分页

                rs.ContentType = "application/vnd.ms-excel";
                rs.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", "专家信息表" + DateTime.Now.Second.ToString()));
                wb.Write(rs.OutputStream);
            }
예제 #29
0
            internal void 需求计划(long id, HttpResponseBase rs)
            {
                var 需求计划表 = 需求计划管理.查找需求计划(id);
                var wb = CreateWorkbook(_excelVer);

                #region 样式
                // 设置字体
                var font_10 = wb.CreateFont();
                font_10.FontName = "微软雅黑";
                font_10.FontHeightInPoints = 10;

                var font_12 = wb.CreateFont();
                font_12.FontName = "微软雅黑";
                font_12.FontHeightInPoints = 12;

                var font_15 = wb.CreateFont();
                font_15.FontHeightInPoints = 15;
                font_15.FontName = "微软雅黑";

                //设置样式-统一垂直居中
                //样式一:12号字体、右对齐
                ICellStyle style_1 = wb.CreateCellStyle();
                style_1.VerticalAlignment = VerticalAlignment.Center;
                style_1.SetFont(font_12);
                style_1.Alignment = HorizontalAlignment.Right;


                //样式二:12号字体、居中对齐
                ICellStyle style_2 = wb.CreateCellStyle();
                style_2.VerticalAlignment = VerticalAlignment.Center;
                style_2.SetFont(font_12);
                style_2.Alignment = HorizontalAlignment.Center;

                //样式三:12号字体、左对齐
                ICellStyle style_3 = wb.CreateCellStyle();
                style_3.VerticalAlignment = VerticalAlignment.Center;
                style_3.SetFont(font_12);
                style_3.Alignment = HorizontalAlignment.Left;

                //样式四:15号字体、右对齐
                ICellStyle style_4 = wb.CreateCellStyle();
                style_4.VerticalAlignment = VerticalAlignment.Center;
                style_4.SetFont(font_15);
                style_4.Alignment = HorizontalAlignment.Right;

                //样式五:15号字体、居中对齐
                ICellStyle style_5 = wb.CreateCellStyle();
                style_5.VerticalAlignment = VerticalAlignment.Center;
                style_5.SetFont(font_15);
                style_5.Alignment = HorizontalAlignment.Center;

                //样式六:15号字体、左对齐
                ICellStyle style_6 = wb.CreateCellStyle();
                style_6.VerticalAlignment = VerticalAlignment.Center;
                style_6.SetFont(font_15);
                style_6.Alignment = HorizontalAlignment.Left;

                //样式七:12号字体、居中对齐、有边框

                ICellStyle style_7 = wb.CreateCellStyle();
                style_7.VerticalAlignment = VerticalAlignment.Center;
                style_7.Alignment = HorizontalAlignment.Center;
                style_7.BorderBottom = BorderStyle.Thin;
                style_7.BorderLeft = BorderStyle.Thin;
                style_7.BorderRight = BorderStyle.Thin;
                style_7.BorderTop = BorderStyle.Thin;
                style_7.WrapText = true;
                #endregion

                for (int i = 0; i < 4; i++)
                {
                    switch (i)
                    {
                        case 0:
                            #region 封面
                            var ws = wb.CreateSheet("封面");
                            //秘密等级设置
                            ws.AddMergedRegion(new CellRangeAddress(2, 2, 0, 11));
                            var row = ws.CreateRow(2);
                            var cell = row.CreateCell(0);
                            cell.SetCellValue("秘密等级:");
                            ICellStyle style0 = wb.CreateCellStyle();
                            style0.SetFont(font_12);
                            style0.Alignment = HorizontalAlignment.Right;
                            cell.CellStyle = style0;
                            ws.AddMergedRegion(new CellRangeAddress(2, 2, 12, 13));
                            cell = row.CreateCell(12);
                            cell.SetCellValue(需求计划表.秘密等级.ToString());
                            ICellStyle style1 = wb.CreateCellStyle();
                            style1.BorderBottom = BorderStyle.Medium;
                            style1.Alignment = HorizontalAlignment.Left;
                            style1.SetFont(font_12);
                            cell.CellStyle = style1;
                            cell = row.CreateCell(13);
                            cell.CellStyle = style1;
                            //需求计划表标题设置
                            ws.AddMergedRegion(new CellRangeAddress(8, 8, 0, 13));
                            row = ws.CreateRow(8);
                            cell = row.CreateCell(0);
                            cell.SetCellValue("军 队 物 资 集 中 采 购 需 求 计 划");
                            var ft = wb.CreateFont();
                            ft.FontName = "微软雅黑";
                            ft.FontHeightInPoints = 30;
                            ICellStyle style2 = wb.CreateCellStyle();
                            style2.Alignment = HorizontalAlignment.Center;
                            style2.SetFont(ft);
                            cell.CellStyle = style2;
                            //编制单位
                            ws.AddMergedRegion(new CellRangeAddress(20, 20, 0, 4));
                            row = ws.CreateRow(20);
                            cell = row.CreateCell(0);
                            cell.SetCellValue("编制单位:");
                            ICellStyle style3 = wb.CreateCellStyle();
                            style3.SetFont(font_15);
                            style3.Alignment = HorizontalAlignment.Right;
                            cell.CellStyle = style3;
                            ws.AddMergedRegion(new CellRangeAddress(20, 20, 5, 9));
                            ICellStyle style4 = wb.CreateCellStyle();
                            style4.BorderBottom = BorderStyle.Medium;
                            style4.SetFont(font_12);
                            for (int j = 5; j < 10; j++)
                            {
                                cell = row.CreateCell(j);
                                if (j == 5)
                                {
                                    cell.SetCellValue(需求计划表.编制单位);
                                }
                                cell.CellStyle = style4;
                            }
                            //年月日
                            ws.AddMergedRegion(new CellRangeAddress(25, 25, 0, 13));
                            row = ws.CreateRow(25);
                            cell = row.CreateCell(0);
                            cell.SetCellValue("年                月                日");
                            ICellStyle style5 = wb.CreateCellStyle();
                            style5.SetFont(font_15);
                            style5.Alignment = HorizontalAlignment.Center;
                            cell.CellStyle = style5;

                            //打印设置
                            ws.PrintSetup.Landscape = true;//设置横向打印
                            ws.PrintSetup.PaperSize = 9; //设置打印纸张
                            break;
                            #endregion
                        case 1:
                            #region 物资列表
                            ws = wb.CreateSheet("军队物资集中采购需求计划表");

                            var 物资列表 = 需求计划表.物资列表;
                            var pageCount = 物资列表.Count % 14 == 0 ? 物资列表.Count / 14 : 物资列表.Count / 14 + 1;

                            for (int page = 0; page < pageCount; page++)
                            {
                                //设置表头
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 1, page * 20 + 1, 0, 10));
                                row = ws.CreateRow(page * 20 + 1);
                                cell = row.CreateCell(0);
                                cell.SetCellValue("军队物资集中采购需求计划表");
                                cell.CellStyle = style_5;
                                //编制单位、采购年度
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 2, page * 20 + 2, 0, 8));
                                row = ws.CreateRow(page * 20 + 2);
                                row.HeightInPoints = 25;
                                cell = row.CreateCell(0);
                                cell.SetCellValue("编制单位:" + 需求计划表.编制单位);
                                cell.CellStyle = style_3;
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 2, page * 20 + 2, 9, 10));
                                cell = row.CreateCell(9);
                                cell.SetCellValue("采购年度:" + 需求计划表.采购年度.ToString("yyyy年MM月dd日"));
                                cell.CellStyle = style_1;

                                //内容表头
                                row = ws.CreateRow(page * 20 + 3);
                                for (int k = 0; k < 11; k++)
                                {
                                    cell = row.CreateCell(k);
                                    switch (k)
                                    {
                                        case 0: cell.SetCellValue("序号"); ws.SetColumnWidth(k, 1000); break;
                                        case 1: cell.SetCellValue("物资名称"); ws.SetColumnWidth(k, 7000); break;
                                        case 2: cell.SetCellValue("规格型号"); ws.SetColumnWidth(k, 3000); break;
                                        case 3: cell.SetCellValue("计量单位"); ws.SetColumnWidth(k, 1200); break;
                                        case 4: cell.SetCellValue("数量"); break;
                                        case 5: cell.SetCellValue("单价(元)"); break;
                                        case 6: cell.SetCellValue("预算金额(元)"); ws.SetColumnWidth(k, 3000); break;
                                        case 7: cell.SetCellValue("质量技术标准"); ws.SetColumnWidth(k, 2400); break;
                                        case 8: cell.SetCellValue("交货期限"); ws.SetColumnWidth(k, 3300); break;
                                        case 9: cell.SetCellValue("采购方式建议"); ws.SetColumnWidth(k, 2400); break;
                                        case 10: cell.SetCellValue("备注"); ws.SetColumnWidth(k, 8000); break;
                                    }
                                    style_7.SetFont(font_12);
                                    cell.CellStyle = style_7;
                                }

                                //填充内容
                                var list = 物资列表.Skip(page * 14).Take(14).ToList();
                                var length = list.Count();
                                for (int p = 0; p < length; p++)   //行
                                {
                                    row = ws.CreateRow(page * 20 + 4 + p);
                                    row.HeightInPoints = 25;
                                    for (int t = 0; t < 11; t++) //列
                                    {
                                        cell = row.CreateCell(t);
                                        switch (t)
                                        {
                                            case 0: cell.SetCellValue(p + 1); break;
                                            case 1: cell.SetCellValue(list[p].需求计划物资数据.物资名称); break;
                                            case 2: cell.SetCellValue(list[p].需求计划物资数据.规格型号); break;
                                            case 3: cell.SetCellValue(list[p].需求计划物资数据.计量单位); break;
                                            case 4: cell.SetCellValue(list[p].需求计划物资数据.数量.ToString()); break;
                                            case 5: cell.SetCellValue(list[p].需求计划物资数据.单价.ToString()); break;
                                            case 6: cell.SetCellValue(list[p].需求计划物资数据.预算金额.ToString()); break;
                                            case 7: cell.SetCellValue(list[p].需求计划物资数据.技术指标); break;
                                            case 8: cell.SetCellValue(list[p].需求计划物资数据.交货期限.ToString("yyyy-MM-dd")); break;
                                            case 9: cell.SetCellValue(list[p].需求计划物资数据.建议采购方式.ToString()); break;
                                            case 10: cell.SetCellValue(list[p].需求计划物资数据.所属需求计划.需求计划数据.需求发起单位链接.用户数据.单位信息.单位代号 != null ? list[p].需求计划物资数据.所属需求计划.需求计划数据.需求发起单位链接.用户数据.单位信息.单位代号 : list[p].需求计划物资数据.所属需求计划.需求计划数据.需求发起单位链接.用户数据.单位信息.单位名称); break;
                                        }
                                        style_7.SetFont(font_10);
                                        cell.CellStyle = style_7;
                                    }
                                }

                                //数据不够时用空白填充
                                for (int m = 0; m < 14 - length; m++)
                                {
                                    row = ws.CreateRow(page * 20 + 4 + length + m);
                                    row.HeightInPoints = 25;
                                    for (int r = 0; r < 11; r++) //列
                                    {
                                        cell = row.CreateCell(r);
                                        switch (r)
                                        {
                                            case 0: cell.SetCellValue(""); break;
                                            case 1: cell.SetCellValue(""); break;
                                            case 2: cell.SetCellValue(""); break;
                                            case 3: cell.SetCellValue(""); break;
                                            case 4: cell.SetCellValue(""); break;
                                            case 5: cell.SetCellValue(""); break;
                                            case 6: cell.SetCellValue(""); break;
                                            case 7: cell.SetCellValue(""); break;
                                            case 8: cell.SetCellValue(""); break;
                                            case 9: cell.SetCellValue(""); break;
                                            case 10: cell.SetCellValue(""); break;
                                        }
                                        cell.CellStyle = style_7;
                                    }
                                }

                                //表格底部
                                row = ws.CreateRow(page * 20 + 18);
                                row.HeightInPoints = 25;
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 18, page * 20 + 18, 0, 5));
                                cell = row.CreateCell(0);
                                cell.SetCellValue("承办部门:" + 需求计划表.承办部门);
                                cell.CellStyle = style_3;
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 18, page * 20 + 18, 6, 8));
                                cell = row.CreateCell(6);
                                cell.SetCellValue("联系人:" + 需求计划表.联系人);
                                cell.CellStyle = style_3;
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 18, page * 20 + 18, 9, 10));
                                cell = row.CreateCell(9);
                                cell.SetCellValue("联系电话:" + 需求计划表.联系电话);
                                cell.CellStyle = style_3;

                                //打印设置
                                ws.PrintSetup.Landscape = true;//设置横向打印
                                ws.PrintSetup.PaperSize = 9; //设置打印纸张
                                ws.PrintSetup.Scale = 94;  //设置缩放
                                ws.FitToPage = false;
                                ws.SetRowBreak((page + 1) * 20);  //设置分页

                            }
                            break;
                            #endregion
                        case 2:
                            #region 分发列表
                            ws = wb.CreateSheet("军队物资集中采购需求计划分发表");

                            var 分发列表 = 需求计划表.分发列表;
                            pageCount = 分发列表.Count % 14 == 0 ? 分发列表.Count / 14 : 分发列表.Count / 14 + 1;

                            for (int page = 0; page < pageCount; page++)
                            {
                                //设置表头
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 1, page * 20 + 1, 0, 9));
                                row = ws.CreateRow(page * 20 + 1);
                                cell = row.CreateCell(0);
                                cell.SetCellValue("军队物资集中采购需求计划表");
                                cell.CellStyle = style_5;
                                //编制单位、采购年度
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 2, page * 20 + 2, 0, 9));
                                row = ws.CreateRow(page * 20 + 2);
                                row.HeightInPoints = 25;
                                cell = row.CreateCell(0);
                                cell.SetCellValue("编制单位:" + 需求计划表.编制单位);
                                cell.CellStyle = style_3;

                                //内容表头
                                row = ws.CreateRow(page * 20 + 3);
                                for (int k = 0; k < 10; k++)
                                {
                                    cell = row.CreateCell(k);
                                    switch (k)
                                    {
                                        case 0: cell.SetCellValue("序号"); ws.SetColumnWidth(k, 1000); break;
                                        case 1: cell.SetCellValue("物资名称"); ws.SetColumnWidth(k, 7000); break;
                                        case 2: cell.SetCellValue("规格型号"); ws.SetColumnWidth(k, 4000); break;
                                        case 3: cell.SetCellValue("计量单位"); ws.SetColumnWidth(k, 1200); break;
                                        case 4: cell.SetCellValue("收货单位名称"); ws.SetColumnWidth(k, 5000); break;
                                        case 5: cell.SetCellValue("分配数量"); ws.SetColumnWidth(k, 3000); break;
                                        case 6: cell.SetCellValue("提货方式"); ws.SetColumnWidth(k, 3000); break;
                                        case 7: cell.SetCellValue("运输方式"); ws.SetColumnWidth(k, 3000); break;
                                        case 8: cell.SetCellValue("到站"); ws.SetColumnWidth(k, 2000); break;
                                        case 9: cell.SetCellValue("备注"); ws.SetColumnWidth(k, 6500); break;
                                    }
                                    style_7.SetFont(font_12);
                                    cell.CellStyle = style_7;
                                }

                                //填充内容
                                var fflist = 分发列表.Skip(page * 14).Take(14).ToList();
                                var length = fflist.Count();
                                for (int p = 0; p < length; p++)   //行
                                {
                                    row = ws.CreateRow(page * 20 + 4 + p);
                                    row.HeightInPoints = 25;
                                    for (int t = 0; t < 10; t++) //列
                                    {
                                        cell = row.CreateCell(t);
                                        switch (t)
                                        {
                                            case 0: cell.SetCellValue(p + 1); break;
                                            case 1: cell.SetCellValue(fflist[p].需求计划分发数据.物资名称); break;
                                            case 2: cell.SetCellValue(fflist[p].需求计划分发数据.规格型号); break;
                                            case 3: cell.SetCellValue(fflist[p].需求计划分发数据.计量单位); break;
                                            case 4: cell.SetCellValue(fflist[p].需求计划分发数据.收货单位名称); break;
                                            case 5: cell.SetCellValue(fflist[p].需求计划分发数据.分配数量.ToString()); break;
                                            case 6: cell.SetCellValue(fflist[p].需求计划分发数据.提货方式.ToString()); break;
                                            case 7: cell.SetCellValue(fflist[p].需求计划分发数据.运输方式.ToString()); break;
                                            case 8: cell.SetCellValue(fflist[p].需求计划分发数据.到站); break;
                                            case 9: cell.SetCellValue(fflist[p].需求计划分发数据.备注); break;
                                        }
                                        style_7.SetFont(font_10);
                                        cell.CellStyle = style_7;
                                    }
                                }

                                //数据不够时用空白填充
                                for (int m = 0; m < 14 - length; m++)
                                {
                                    row = ws.CreateRow(page * 20 + 4 + length + m);
                                    row.HeightInPoints = 25;
                                    for (int r = 0; r < 10; r++) //列
                                    {
                                        cell = row.CreateCell(r);
                                        switch (r)
                                        {
                                            case 0: cell.SetCellValue(""); break;
                                            case 1: cell.SetCellValue(""); break;
                                            case 2: cell.SetCellValue(""); break;
                                            case 3: cell.SetCellValue(""); break;
                                            case 4: cell.SetCellValue(""); break;
                                            case 5: cell.SetCellValue(""); break;
                                            case 6: cell.SetCellValue(""); break;
                                            case 7: cell.SetCellValue(""); break;
                                            case 8: cell.SetCellValue(""); break;
                                            case 9: cell.SetCellValue(""); break;
                                            case 10: cell.SetCellValue(""); break;
                                        }
                                        cell.CellStyle = style_7;
                                    }
                                }

                                //表格底部
                                row = ws.CreateRow(page * 20 + 18);
                                row.HeightInPoints = 25;
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 18, page * 20 + 18, 0, 3));
                                cell = row.CreateCell(0);
                                cell.SetCellValue("承办部门:" + 需求计划表.承办部门);
                                cell.CellStyle = style_3;
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 18, page * 20 + 18, 4, 7));
                                cell = row.CreateCell(4);
                                cell.SetCellValue("联系人:" + 需求计划表.联系人);
                                cell.CellStyle = style_3;
                                ws.AddMergedRegion(new CellRangeAddress(page * 20 + 18, page * 20 + 18, 8, 9));
                                cell = row.CreateCell(8);
                                cell.SetCellValue("联系电话:" + 需求计划表.联系电话);
                                cell.CellStyle = style_3;

                                //打印设置
                                ws.PrintSetup.Landscape = true;//设置横向打印
                                ws.PrintSetup.PaperSize = 9; //设置打印纸张
                                ws.PrintSetup.Scale = 94;  //设置缩放
                                ws.FitToPage = false;
                                ws.SetRowBreak((page + 1) * 20);  //设置分页

                            }
                            break;
                            #endregion
                        case 3:
                            #region 编制说明
                            ws = wb.CreateSheet("《军队物资集中采购需求计划》填制说明");
                            ws.AddMergedRegion(new CellRangeAddress(0, 0, 0, 14));
                            ws.AddMergedRegion(new CellRangeAddress(1, 2, 0, 14));
                            ws.AddMergedRegion(new CellRangeAddress(3, 3, 0, 14));
                            ws.AddMergedRegion(new CellRangeAddress(4, 4, 0, 14));
                            ws.AddMergedRegion(new CellRangeAddress(5, 5, 0, 14));
                            ws.AddMergedRegion(new CellRangeAddress(6, 6, 0, 14));
                            ws.AddMergedRegion(new CellRangeAddress(7, 7, 0, 14));
                            ws.AddMergedRegion(new CellRangeAddress(8, 8, 0, 14));
                            ws.AddMergedRegion(new CellRangeAddress(9, 9, 0, 14));
                            row = ws.CreateRow(0);
                            row.HeightInPoints = 20;
                            cell = row.CreateCell(0);
                            cell.SetCellValue("《军队物资集中采购需求计划》填制说明");
                            cell.CellStyle = style_5;
                            row = ws.CreateRow(1);
                            row.HeightInPoints = 30;
                            cell = row.CreateCell(0);
                            cell.SetCellValue("一、《军队物资集中采购需求计划》包括《军队物资集中采购需求计划表》和《军队物资集中采购需求计划分发表》,由事业部门依据年度采购预算编制,预算批复后20个工作日内送军需物资油料部门。");
                            style_3.WrapText = true;
                            cell.CellStyle = style_3;
                            row = ws.CreateRow(3);
                            row.HeightInPoints = 20;
                            cell = row.CreateCell(0);
                            cell.SetCellValue("二、\"物资名称\"栏按照采购目录区分的物资类别填至具体品种名称。");
                            cell.CellStyle = style_3;
                            row = ws.CreateRow(4);
                            row.HeightInPoints = 20;
                            cell = row.CreateCell(0);
                            cell.SetCellValue("三、\"计量单位\"按照采购目录明确的计量单位填写。");
                            cell.CellStyle = style_3;
                            row = ws.CreateRow(5);
                            row.HeightInPoints = 20;
                            cell = row.CreateCell(0);
                            cell.SetCellValue("四、对采购机构、供应商的建议可在《军队物资集中采购需求计划表》\"备注\"栏内填写。");
                            cell.CellStyle = style_3;
                            row = ws.CreateRow(6);
                            row.HeightInPoints = 20;
                            cell = row.CreateCell(0);
                            cell.SetCellValue("五、非标准产品或者有特殊要求的产品应当另附详细说。");
                            cell.CellStyle = style_3;
                            row = ws.CreateRow(7);
                            row.HeightInPoints = 20;
                            cell = row.CreateCell(0);
                            cell.SetCellValue("六、\"提货方式\"栏填写:自提、代运。");
                            cell.CellStyle = style_3;
                            row = ws.CreateRow(8);
                            row.HeightInPoints = 20;
                            cell = row.CreateCell(0);
                            cell.SetCellValue("七、\"运输方式\"栏填写:铁路运输、公路运输、水路运输、航空运输。");
                            cell.CellStyle = style_3;
                            row = ws.CreateRow(9);
                            row.HeightInPoints = 20;
                            cell = row.CreateCell(0);
                            cell.SetCellValue("八、本表使用A4纸(210X297mm)。");
                            cell.CellStyle = style_3;

                            //打印设置
                            ws.PrintSetup.Landscape = true;//设置横向打印
                            ws.PrintSetup.PaperSize = 9; //设置打印纸张
                            break;
                            #endregion

                    }
                }


                rs.ContentType = "application/vnd.ms-excel";
                rs.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", "军队物资集中采购需求计划表" + DateTime.Now.Second.ToString()));
                wb.Write(rs.OutputStream);
                //FileStream file = new FileStream(@"e:\军队物资集中采购需求计划表.xls", FileMode.Create);
                //wb.Write(file);
                //file.Close();
            }
예제 #30
0
        protected virtual void SetCache(HttpResponseBase response, int cacheDuration, params string[] varyByParams)
        {
            // Cache
            if (cacheDuration > 0)
            {
                response.AddHeader("Cache-Control", string.Format("public, max-age={0}", cacheDuration));
                //DateTime timestamp = httpContext.Timestamp;

                //HttpCachePolicyBase cache = response.Cache;
                //int duration = cacheDuration;

                //cache.SetCacheability(HttpCacheability.Public);
                //cache.SetAllowResponseInBrowserHistory(true);
                //cache.SetExpires(timestamp.AddSeconds(duration));
                //cache.SetMaxAge(new TimeSpan(0, 0, duration));
                //cache.SetValidUntilExpires(true);
                //cache.SetLastModified(timestamp);
                //cache.VaryByHeaders["Accept-Encoding"] = true;
                //if (varyByParams != null)
                //{
                //    foreach (var p in varyByParams)
                //    {
                //        cache.VaryByParams[p] = true;
                //    }
                //}

                //cache.SetOmitVaryStar(true);
            }
        }