Пример #1
0
        protected void ViewMonth(HttpResponse Response, DateTime dtBegMonth, DateTime dtEndMonth)
        {
            GetData();

            DateTime dtBegOfWeek = dtBegMonth.AddDays(1 - (int)dtBegMonth.Day);

            dtBegOfWeek = dtBegOfWeek.AddDays(-(int)dtBegOfWeek.DayOfWeek);
            DateTime dtEndOfWeek = dtBegOfWeek.AddDays(6);

            string Html = "";

            if (fnBegCal != null)
            {
                Html += fnBegCal();
            }

            // Month top
            Html +=
                (fNewPage ? "<div style='page-break-before: always;'>&nbsp;</div>\n" : "") +
                WebPage.Tabs(0) + WebPage.Table("align='center' valign='top' class='CalSched'") +
                WebPage.Tabs(1) + "<tr><td colspan='" + (fShowTimeColumn ? 8 : 7) + "' align='center' class='RptNotice'>" +
                dtBegMonth.ToString("MMMM yyyy") + "</td></tr>\n" +
                WebPage.Tabs(1) + "<tr>\n" +
                (fShowTimeColumn ? WebPage.Tabs(2) + "<td align='center'>Time</td>\n" : "");

            // days of the week
            DateTime dtDay = dtBegOfWeek;

            while (dtDay <= dtEndOfWeek)
            {
                Html +=
                    WebPage.Tabs(2) + "<td align='center'><b>" + dtDay.ToString("ddd") + "</b></td>\n";
                dtDay = dtDay.AddDays(1);
            }
            Html +=
                WebPage.Tabs(1) + "</tr>\n" +
                WebPage.Tabs(1) + "<tr>\n";

            // min width for column
            dtDay = dtBegOfWeek;
            while (dtDay <= dtEndOfWeek)
            {
                Html += WebPage.Tabs(2) + "<td class='NoBorder'>" + WebPage.NoOp(80, 1) + "</td>\n";
                dtDay = dtDay.AddDays(1);
            }
            Html +=
                WebPage.Tabs(1) + "</tr>\n";

            while (dtBegOfWeek < dtEndMonth)
            {
                DateTime tmBegBlockWeek = new DateTime(dtBegOfWeek.Year, dtBegOfWeek.Month, dtBegOfWeek.Day);
                DateTime tmEndBlockWeek = new DateTime(dtBegOfWeek.Year, dtBegOfWeek.Month, dtBegOfWeek.Day, tmBegDay.Hour, tmBegDay.Minute, 0);
                DateTime tmEndDayWeek   = new DateTime(dtBegOfWeek.Year, dtBegOfWeek.Month, dtBegOfWeek.Day, tmEndDay.Hour, tmEndDay.Minute, 0);
                TimeSpan tsBlock        = new TimeSpan(0, this.TimeBlock, 0);
                string   sTime          = "Before<br>" + tmEndBlockWeek.ToString("h:mmt").ToLower();
                string   sClass         = "CalSched";

                bool fFirstBlock = true;
                bool fLastBlock  = false;
                while (!fLastBlock)
                {
                    fLastBlock = (tmEndBlockWeek.Hour == 0);                                    // last block of time will end at 00:00 of the next day

                    Html += WebPage.Tabs(1) + "<tr>\n";
                    if (fShowTimeColumn)
                    {
                        Html += WebPage.Tabs(2) + "<td align='center' valign='top' class='" + sClass + "'>" + sTime + "</td>\n";
                    }

                    dtDay = dtBegOfWeek;
                    while (dtDay <= dtEndOfWeek)
                    {
                        dtDay = new DateTime(dtDay.Year, dtDay.Month, dtDay.Day, 0, 0, 0);
                        DateTime tmBegBlockDay = dtDay;
                        DateTime tmEndBlockDay = (tmBegBlockWeek.Day == tmEndBlockWeek.Day ? dtDay : dtDay.AddDays(1));
                        tmBegBlockDay = new DateTime(tmBegBlockDay.Year, tmBegBlockDay.Month, tmBegBlockDay.Day, tmBegBlockWeek.Hour, tmBegBlockWeek.Minute, 0);
                        tmEndBlockDay = new DateTime(tmEndBlockDay.Year, tmEndBlockDay.Month, tmEndBlockDay.Day, tmEndBlockWeek.Hour, tmEndBlockWeek.Minute, 0);

                        string sInRange = "";
                        string sEvent   =
                            (fFirstBlock ? WebPage.Tabs(3) + "<div align='right'>" + dtDay.Day + "</div>\n" : "");

                        if (dtDay.Month == dtBegMonth.Month && dtDay >= dtBeg && dtDay <= dtEnd)
                        {
                            int iEvent = FirstEvent(tmBegBlockDay, tmEndBlockDay);
                            if (iEvent > -1)
                            {
                                while (iEvent > -1)
                                {
                                    sEvent +=
                                        (sEvent.Length > 0 ? WebPage.SpaceTable(1, 2) : "") +
                                        FormatEvent(iEvent);

                                    iEvent = NextEvent(iEvent, tmBegBlockDay, tmEndBlockDay);
                                }
                            }
                            else
                            {
                                sEvent += WebPage.Tabs(3) + "&nbsp;\n";
                            }
                        }
                        else
                        {
                            sInRange = "Not";
                            sEvent  += WebPage.Tabs(3) + "&nbsp;\n";
                        }

                        Html +=
                            WebPage.Tabs(2) + "<td class='" + sClass + sInRange + "' valign='top'>\n" +
                            sEvent +
                            WebPage.Tabs(2) + "</td>\n";

                        dtDay = dtDay.AddDays(1);
                    }
                    Html +=
                        WebPage.Tabs(1) + "</tr>\n";

                    sClass      = "CalSchedMid";
                    fFirstBlock = false;

                    // 2 cases exist here,
                    // the last block of time at the end of the normal day (tmEndDay)
                    // or anytime before that

                    if (tmEndBlockWeek >= tmEndDayWeek)
                    {
                        // last block of time for the day (after the End of Day time)
                        tmBegBlockWeek = tmEndDayWeek;
                        tmEndBlockWeek = new DateTime(dtBegOfWeek.Year, dtBegOfWeek.Month, dtBegOfWeek.Day).AddDays(1);
                        sTime          = tmBegBlockWeek.ToString("h:mmt").ToLower() + "<br>&amp; After";
                    }
                    else
                    {
                        tmBegBlockWeek  = tmEndBlockWeek;
                        tmEndBlockWeek += tsBlock;
                        sTime           = tmBegBlockWeek.ToString("h:mmt").ToLower();
                    }
                    Debug.WriteLine("BegBlockWeek " + tmBegBlockWeek.ToString());
                    Debug.WriteLine("EndBlockWeek " + tmEndBlockWeek.ToString());
                }
                dtBegOfWeek = dtEndOfWeek.AddDays(1);
                dtEndOfWeek = dtBegOfWeek.AddDays(6);
            }

            Html +=
                WebPage.Tabs(0) + WebPage.TableEnd();

            if (fnEndCal != null)
            {
                Html += fnEndCal();
            }

            Response.Write(Html);
        }
Пример #2
0
        // 输出硬盘文件,提供下载
        // 输入参数 _Request: Page.Request对象, _Response: Page.Response对象, _fileName: 下载文件名, _fullPath: 带文件名下载路径, _speed 每秒允许下载的字节数
        // 返回是否成功
        public bool ResponseFile(HttpRequest _Request, HttpResponse _Response, string _fileName, string _fullPath, long _speed)
        {
            try
            {
                FileStream   myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                BinaryReader br     = new BinaryReader(myFile);
                try
                {
                    _Response.AddHeader("Accept-Ranges", "bytes");
                    _Response.Buffer = false;
                    long fileLength = myFile.Length;
                    long startBytes = 0;

                    int pack = 10240; //10K bytes
                    //int sleep = 200; //每秒5次 即5*10K bytes每秒
                    int sleep = (int)Math.Floor(Convert.ToDouble(1000 * pack / _speed)) + 1;
                    if (_Request.Headers["Range"] != null)
                    {
                        _Response.StatusCode = 206;
                        string[] range = _Request.Headers["Range"].Split(new char[] { '=', '-' });
                        startBytes = Convert.ToInt64(range[1]);
                    }
                    _Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
                    if (startBytes != 0)
                    {
                        _Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength - 1, fileLength));
                    }
                    _Response.AddHeader("Connection", "Keep-Alive");
                    _Response.ContentType = "application/octet-stream";
                    _Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(_fileName, System.Text.Encoding.UTF8));

                    br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
                    int maxCount = (int)Math.Floor(Convert.ToDouble((fileLength - startBytes) / pack)) + 1;

                    for (int i = 0; i < maxCount; i++)
                    {
                        if (_Response.IsClientConnected)
                        {
                            _Response.BinaryWrite(br.ReadBytes(pack));
                            Thread.Sleep(sleep);
                        }
                        else
                        {
                            i = maxCount;
                        }
                    }
                }
                catch
                {
                    return(false);
                }
                finally
                {
                    br.Close();
                    myFile.Close();
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
Пример #3
0
        protected void ViewWeek(HttpResponse Response)
        {
            GetData();

            string Html = "";

            if (fnBegCal != null)
            {
                Html += fnBegCal();
            }

            DateTime dtBegOfWeek = dtBeg;

            Html =
                WebPage.Tabs(0) + WebPage.Table("align='center' class='CalSched'") +
                WebPage.Tabs(1) + "<tr>\n";

            if (fShowTimeColumn)
            {
                Html += WebPage.Tabs(2) + "<td align='center'>Time</td>\n";
            }

            // days of the week
            DateTime dtDay = dtBeg;

            while (dtDay <= dtEnd)
            {
                Html +=
                    WebPage.Tabs(2) + "<td align='center'><b>" + dtDay.ToString("MM/dd<br>ddd") + "</b></td>\n";
                dtDay = dtDay.AddDays(1);
            }
            Html +=
                WebPage.Tabs(1) + "</tr>\n" +
                WebPage.Tabs(1) + "<tr>\n";

            // min width for column
            dtDay = dtBeg;
            while (dtDay <= dtEnd)
            {
                Html += WebPage.Tabs(2) + "<td class='NoBorder'>" + WebPage.NoOp(80, 1) + "</td>\n";
                dtDay = dtDay.AddDays(1);
            }
            Html +=
                WebPage.Tabs(1) + "</tr>\n";

            DateTime tmBegBlockWeek = new DateTime(dtBegOfWeek.Year, dtBegOfWeek.Month, dtBegOfWeek.Day);
            DateTime tmEndBlockWeek = new DateTime(dtBegOfWeek.Year, dtBegOfWeek.Month, dtBegOfWeek.Day, tmBegDay.Hour, tmBegDay.Minute, 0);
            DateTime tmEndDayWeek   = new DateTime(dtBegOfWeek.Year, dtBegOfWeek.Month, dtBegOfWeek.Day, tmEndDay.Hour, tmEndDay.Minute, 0);
            TimeSpan tsBlock        = new TimeSpan(0, this.TimeBlock, 0);
            string   sTime          = "Before<br>" + tmEndBlockWeek.ToString("h:mmt").ToLower();
            string   sClass         = "CalSched";

            bool fLastBlock = false;

            while (!fLastBlock)
            {
                fLastBlock = (tmEndBlockWeek.Hour == 0);                                // last block of time will end at 00:00 of the next day

                Html += WebPage.Tabs(1) + "<tr>\n";
                if (fShowTimeColumn)
                {
                    Html += WebPage.Tabs(2) + "<td align='center' valign='top' class='" + sClass + "'>" + sTime + "</td>\n";
                }

                dtDay = dtBeg;
                while (dtDay <= dtEnd)
                {
                    dtDay = new DateTime(dtDay.Year, dtDay.Month, dtDay.Day, 0, 0, 0);
                    DateTime tmBegBlockDay = dtDay;
                    DateTime tmEndBlockDay = (tmBegBlockWeek.Day == tmEndBlockWeek.Day ? dtDay : dtDay.AddDays(1));
                    tmBegBlockDay = new DateTime(tmBegBlockDay.Year, tmBegBlockDay.Month, tmBegBlockDay.Day, tmBegBlockWeek.Hour, tmBegBlockWeek.Minute, 0);
                    tmEndBlockDay = new DateTime(tmEndBlockDay.Year, tmEndBlockDay.Month, tmEndBlockDay.Day, tmEndBlockWeek.Hour, tmEndBlockWeek.Minute, 0);

                    string sEvent = "";
                    int    iEvent = FirstEvent(tmBegBlockDay, tmEndBlockDay);
                    if (iEvent > -1)
                    {
                        while (iEvent > -1)
                        {
                            sEvent +=
                                (sEvent.Length > 0 ? WebPage.SpaceTable(1, 2) : "") +
                                FormatEvent(iEvent);

                            iEvent = NextEvent(iEvent, tmBegBlockDay, tmEndBlockDay);
                        }
                    }
                    else
                    {
                        sEvent = WebPage.Tabs(3) + "&nbsp;\n";
                    }

                    Html +=
                        WebPage.Tabs(2) + "<td class='" + sClass + "' valign='top'>\n" +
                        sEvent +
                        WebPage.Tabs(2) + "</td>\n";

                    dtDay = dtDay.AddDays(1);
                }
                Html +=
                    WebPage.Tabs(1) + "</tr>\n";

                sClass = "CalSchedMid";

                // 2 cases exist here,
                // the last block of time at the end of the normal day (tmEndDay)
                // or anytime before that

                if (tmEndBlockWeek >= tmEndDayWeek)
                {
                    // last block of time for the day (after the End of Day time)
                    tmBegBlockWeek = tmEndDayWeek;
                    tmEndBlockWeek = new DateTime(dtBegOfWeek.Year, dtBegOfWeek.Month, dtBegOfWeek.Day).AddDays(1);
                    sTime          = tmBegBlockWeek.ToString("h:mmt").ToLower() + "<br>&amp; After";
                }
                else
                {
                    tmBegBlockWeek  = tmEndBlockWeek;
                    tmEndBlockWeek += tsBlock;
                    sTime           = tmBegBlockWeek.ToString("h:mmt").ToLower();
                }
                Debug.WriteLine("BegBlockWeek " + tmBegBlockWeek.ToString());
                Debug.WriteLine("EndBlockWeek " + tmEndBlockWeek.ToString());
            }

            Html +=
                WebPage.Tabs(0) + WebPage.TableEnd();

            if (fnEndCal != null)
            {
                Html += fnEndCal();
            }

            Response.Write(Html);
        }
Пример #4
0
 public Export()
 {
     this.appType  = "Web";
     this.response = HttpContext.Current.Response;
 }