示例#1
0
        public ActionResult VideoExprt(string txtMac, string txtAPName, string txtLName, string txtBeginTime, string txtEndTime, string txtNETBAR_WACODE)
        {
            try
            {
                UserInfo user = (UserInfo)Session["userInfo"];

                if (Convert.ToDateTime(txtBeginTime) > Convert.ToDateTime(txtEndTime))
                {
                    return(Content("<script>alert('开始时间不能大于结束时间');</script>"));
                }

                int[] userType = ChangeValue.GetUserType();
                Dictionary <string, string> dic = new Dictionary <string, string>()
                {
                    { "txtMac", txtMac }, { "txtNETBAR_WACODE", txtNETBAR_WACODE }, { "txtLName", txtLName }, { "txtAPName", txtAPName }, { "txtBeginTime", txtBeginTime }, { "txtEndTime", txtEndTime }, { "UserType", userType[0].ToString() }, { "AreaId", userType[1].ToString() }
                };

                if (!string.IsNullOrEmpty(txtLName))
                {
                    log.What = "场所名称:" + txtLName;
                }
                if (!string.IsNullOrEmpty(txtAPName))
                {
                    log.What += "AP名称:" + txtAPName;
                }
                if (!string.IsNullOrEmpty(txtMac))
                {
                    log.What += "AP设备MAC地址:" + txtMac;
                }
                if (!string.IsNullOrEmpty(txtNETBAR_WACODE))
                {
                    log.What += "上网服务场所编码:" + txtNETBAR_WACODE;
                }
                if (!string.IsNullOrEmpty(txtBeginTime))
                {
                    log.What += "开始时间:" + txtBeginTime;
                }
                if (!string.IsNullOrEmpty(txtEndTime))
                {
                    log.What += "结束时间:" + txtEndTime;
                }
                if (!string.IsNullOrEmpty(log.What))
                {
                    log.What = "视频数据列表导出Excel" + log.What; new OPLogDAL().InsertLog(log);
                }
                DataTable dt = new Video3CDAL().GetVideoToTable(dic);

                int rowCount = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ExprotCout"]);
                if (dt == null || dt.Rows.Count == 0)
                {
                    return(Content("{\"err\":\"对不起,没有要导出的数据\"}"));
                }
                else if (dt.Rows.Count > rowCount)
                {
                    return(Content("{\"err\":\"为了保证导出数据的速度,数据源不能大于“" + rowCount + "”行\"}"));
                }
                else
                {
                    Dictionary <string, string> Head_Dic = new Dictionary <string, string>();
                    if (!string.IsNullOrEmpty(txtLName))
                    {
                        Head_Dic.Add("场所名称", txtLName);
                    }
                    if (!string.IsNullOrEmpty(txtAPName))
                    {
                        Head_Dic.Add("AP名称", txtAPName);
                    }
                    if (!string.IsNullOrEmpty(txtMac))
                    {
                        Head_Dic.Add("AP设备MAC地址", txtMac);
                    }
                    if (!string.IsNullOrEmpty(txtNETBAR_WACODE))
                    {
                        Head_Dic.Add("上网服务场所编码", txtNETBAR_WACODE);
                    }
                    if (!string.IsNullOrEmpty(txtBeginTime))
                    {
                        Head_Dic.Add("开始时间", txtBeginTime);
                    }
                    if (!string.IsNullOrEmpty(txtEndTime))
                    {
                        Head_Dic.Add("结束时间", txtEndTime);
                    }

                    Dictionary <string, string> Title_Dic = new Dictionary <string, string>()
                    {
                        { "序号", "PageNum" },
                        { "场所名称", "LName" },
                        { "AP名称", "APName" },
                        { "文件名", "FileName" },
                        { "文件大小", "FileSize" },
                        { "开始时间", "BeginTime" },
                        { "结束时间", "EndTime" },
                        { "创建时间", "CreateTime" }
                    };

                    NPOISheetModel sheet = new NPOISheetModel();
                    sheet.dt          = dt;
                    sheet.ExcelTitle  = "视频数据查询";
                    sheet.TableTitle  = Title_Dic;
                    sheet.TableSearch = Head_Dic;

                    string path = new ComNPOIExcel().Export(sheet, Server.MapPath("~/") + "UserData/EXP/Video/");
                    return(Content("{\"result\":\"" + path + "\"}"));
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                return(Content("{\"err\":\"检索数据遇到错误,请联系管理员\"}"));
            }
            catch (Exception ex)
            {
                Logger.ErrorLog(ex, new Dictionary <string, string>()
                {
                    { "Function", this.GetType().Name + ".VideoExprt()[HttpGet]" }
                });
                return(Content("{\"err\":\"导出文件时出错,请联系管理员\"}"));
            }
        }