Exemplo n.º 1
0
        public static OLog Start(string log, ConsoleColor errorColor = ConsoleColor.Red, bool isAddTime = true, int millisecond = 500, string modify = "正在{0}")
        {
            var sp = new StrPlus();

            if (isAddTime)
            {
                sp.Append(string.Format("{0}\t", DateTime.Now.ToString("HH:mm:ss")));
            }
            sp.Append(string.Format(modify + " ", log));
            Console.Write(sp);
            return(new OLog(millisecond, errorColor));
        }
Exemplo n.º 2
0
        /// <summary>
        ///     生成Excel文件
        /// </summary>
        /// <param name="dt">数据源</param>
        /// <param name="fileName">保存的文件名</param>
        public static void CreateExcel(DataTable dt, string fileName)
        {
            var response = HttpContext.Current.Response;

            response.ContentEncoding = Encoding.GetEncoding("gb2312");
            response.AppendHeader("content-disposition",
                                  "attachment;filename=\"" + HttpUtility.UrlEncode(fileName, Encoding.UTF8) + ".xls\"");
            response.ContentType = "application/ms-excel";

            var SP = new StrPlus();

            SP.Append("<table border='1' cellspacing='0' cellpadding='0'>");

            SP.Append("<tr>");
            foreach (DataColumn item in dt.Columns)
            {
                SP.AppendFormat(
                    "<td style='font-size: 12px;text-align:center;background-color: #DCE0E2; font-weight:bold;' height='20'>{0}</td>",
                    item.Caption);
            }
            SP.Append("</tr>");


            //定义表对象与行对象,同时用DataSet对其值进行初始化
            foreach (DataRow row in dt.Rows)
            {
                SP.Append("<tr>");

                //在当前行中,逐列获得数据,数据之间以\t分割,结束时加回车符\n
                for (var i = 0; i < dt.Columns.Count; i++)
                {
                    SP.AppendFormat("<td style='background-color: #E9ECED;font-size: 12px;'>{0}</td>",
                                    row[i].ToString());
                }
                SP.Append("</tr>");
            }

            SP.Append("</table>");
            response.Write(SP);
            response.End();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 分页函数(模板)
        /// </summary>
        /// <param name="pageTotal">总记录数</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="pageShowLength">显示页码长度</param>
        /// <param name="pageName">页面名称</param>
        public SplitResult Split(int pageTotal, int pageSize, int pageIndex, int pageShowLength, string pageName, string pageParam = "")
        {
            //总页数
            var pageCount = 0;
            //下一页
            var nextIndex = 0;
            //上一页
            var preIndex = 0;
            //开始页码
            var startCount = 0;
            //结束页码
            var endCount = 0;
            // 将返回的结果
            var sr = new SplitResult();
            var sp = new StrPlus();

            if (pageIndex < 1)
            {
                pageIndex = 1;
            }

            //计算总页数
            if (pageSize != 0)
            {
                pageCount = (pageTotal / pageSize);
                pageCount = ((pageTotal % pageSize) != 0 ? pageCount + 1 : pageCount);
                pageCount = (pageCount == 0 ? 1 : pageCount);
            }
            nextIndex = pageIndex + 1;
            preIndex  = pageIndex - 1;

            if (preIndex < 1)
            {
                preIndex = 1;
            }
            if (nextIndex > pageCount)
            {
                nextIndex = pageCount;
            }

            //中间页起始序号
            startCount = (pageIndex + pageShowLength / 2) > pageCount ? pageCount - (pageShowLength - 1) : pageIndex - pageShowLength / 2;

            //中间页终止序号
            endCount = pageIndex < pageShowLength / 2 ? pageShowLength : pageIndex + pageShowLength / 2;

            if (pageShowLength % 2 == 0)
            {
                startCount = startCount + 1;
            }


            //为了避免输出的时候产生负数,设置如果小于1就从序号1开始
            if (startCount < 1)
            {
                startCount = 1;
            }

            //页码+5的可能性就会产生最终输出序号大于总页码,那么就要将其控制在页码数之内
            if (pageCount < endCount)
            {
                endCount = pageCount;
            }

            // 首页
            sp += Template(Template_First, pageTotal, pageCount, nextIndex, preIndex, pageSize, pageIndex, pageName, pageParam);
            // 上一页
            sp += Template(Template_Pre, pageTotal, pageCount, nextIndex, preIndex, pageSize, pageIndex, pageName, pageParam);
            // 页码列表
            for (var i = startCount; i <= endCount; i++)
            {
                if (i != pageIndex || string.IsNullOrWhiteSpace(Template_Active))
                {
                    sp += Template(Template_Default, pageTotal, pageCount, nextIndex, preIndex, pageSize, i, pageName, pageParam);
                }
                else
                {
                    sp += Template(Template_Active, pageTotal, pageCount, nextIndex, preIndex, pageSize, i, pageName, pageParam);
                }
            }
            // 下一页
            sp += Template(Template_Next, pageTotal, pageCount, nextIndex, pageIndex, pageSize, pageIndex, pageName, pageParam);
            // 尾页
            sp += Template(Template_Last, pageTotal, pageCount, nextIndex, pageIndex, pageSize, pageIndex, pageName, pageParam);

            sr.Split  = sp;
            sr.Record = Template(Template_Record, pageTotal, pageCount, nextIndex, preIndex, pageSize, pageIndex);

            return(sr);
        }