Beispiel #1
0
        /// <summary>
        /// 绑定数据源
        /// </summary>
        private void DataBindGrid(bool isQuery = false)
        {
            VehicleManager vehicleManager = new VehicleManager();
            int            count          = 0;
            int            pageIndex      = isQuery ? 1 : PageControl1.PageIndex;

            KeyValuePair <StringBuilder, IList <SqlParam> > keyValue = InitCondition();
            DataTable dt = vehicleManager.GetVehicleInfoPage(keyValue.Key, keyValue.Value, pageIndex, PageControl1.PageSize, ref count);

            ControlBindHelper.BindRepeaterList(dt, rp_Item);
            this.PageControl1.PageIndex   = pageIndex;
            this.PageControl1.RecordCount = Convert.ToInt32(count);
            this.PageControl1.PageChecking();
        }
Beispiel #2
0
        protected void lbtExport_Click(object sender, EventArgs e)
        {
            VehicleManager vehicleManager = new VehicleManager();
            int            count          = 0;
            int            pageIndex      = 1;

            KeyValuePair <StringBuilder, IList <SqlParam> > keyValue = InitCondition();
            DataTable dt = vehicleManager.GetVehicleInfoPage(keyValue.Key, keyValue.Value, pageIndex, 1000000000, ref count);

            StringBuilder s = new StringBuilder();

            s.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
            s.AppendLine("<table cellspacing=\"0\" cellpadding=\"5\" rules=\"all\" border=\"1\">");

            //写出列名
            s.AppendLine("<tr style=\"font-weight: bold; white-space: nowrap;\">");
            s.AppendLine("<td>车辆名称</td><td>型号</td><td>车牌号</td><td>电量</td><td>所属平台</td><td>所属城市</td><td>使用状态</td><td>车辆状态</td><td>电源状态</td><td>在线状态</td><td>最近更新</td>");
            s.AppendLine("</tr>");

            //写数据
            foreach (DataRow row in dt.Rows)
            {
                s.Append("<tr>");
                s.Append("<td>'").Append(row["Name"].ToString()).Append("</td>");
                s.Append("<td>").Append(row["modelName"].ToString()).Append("</td>");
                s.Append("<td>'").Append(row["LicenseNumber"].ToString());
                s.Append("<td>'").Append(row["Electricity"].ToString()).Append("</td>");
                s.Append("<td>").Append(row["Platform"].ToString()).Append("</td>");
                s.Append("<td>").Append(row["VehicleCityName"].ToString()).Append("</td>");
                s.Append("<td>").Append(Asiasofti.SmartVehicle.Common.EnumHelper.GetEnumShowName(typeof(Asiasofti.SmartVehicle.Common.Enum.VehicleUseState), Convert.ToInt32(row["UseState"].ToString()))).Append("</td>");
                s.Append("<td>").Append(Asiasofti.SmartVehicle.Common.EnumHelper.GetEnumShowName(typeof(Asiasofti.SmartVehicle.Common.Enum.VehicleState), Convert.ToInt32(row["VehicleState"].ToString()))).Append("</td>");
                s.Append("<td>").Append(row["LockState"].ToString() == "lock" ? "已关" : "已开").Append("</td>");
                s.Append("<td>").Append(row["LightState"].ToString() == "on" ? "已开灯" : "已关灯").Append("</td>");
                s.Append("<td>").Append(int.Parse(row["diffminutes"].ToString()) < 5 ? "在线" : "离线").Append("</td>");
                s.Append("<td>").Append(row["LastUpdateTime"].ToString()).Append("</td>");
                s.AppendLine("</tr>");
            }
            s.AppendLine("</table>");
            this.Page.Response.ContentType     = "application/vnd.ms-excel";
            this.Page.Response.ContentEncoding = System.Text.Encoding.UTF8;
            this.Page.Response.Charset         = "utf-8";
            string filename = "车辆列表_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls";

            this.Page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename));
            this.Page.Response.Write(s.ToString());
            this.Page.Response.End();
        }