コード例 #1
0
ファイル: frmMain-LogQuery.cs プロジェクト: Jackie2014/W1-IPC
        private void BindLogGrid(int pageIndex, int pageSize, bool onlyNotMatched)
        {
            this.p4_dvLog.AutoGenerateColumns = false;

            int totalRows = onlyNotMatched ? _clientIPLogsNotMatched.Count : _clientIPLogs.Count;
            int totalPages = (totalRows + pageSize - 1) / pageSize;

            this.P4_lblExport.Enabled = totalRows > 0;

            if (pageIndex <= 0) pageIndex = 1;
            if (pageIndex >= totalPages) pageIndex = totalPages;

            // get current page data and bind it
            List<ClientIPViewModel> currentPageList = new List<ClientIPViewModel>();
            int startIndex = (pageIndex - 1) * pageSize;
            int index = 0;

            if (onlyNotMatched)
            {
                foreach (var item in _clientIPLogsNotMatched)
                {
                    index++;
                    if (index > startIndex)
                    {
                        ClientIPViewModel ipView = new ClientIPViewModel(item);
                        ipView.SeqNo = index;
                        currentPageList.Add(ipView);
                    }

                    if (index >= startIndex + pageSize)
                    {
                        break;
                    }
                }
            }
            else
            {
                foreach (var item in _clientIPLogs)
                {
                    index++;
                    if (index > startIndex)
                    {
                        ClientIPViewModel ipView = new ClientIPViewModel(item);
                        ipView.SeqNo = index;
                        currentPageList.Add(ipView);
                    }

                    if (index >= startIndex + pageSize)
                    {
                        break;
                    }
                }
            }

            this.p4_lbl_pageTotalRow.Text = String.Format("共 {0} 条", totalRows);
            this.p4_page_totalPages.Text = String.Format("of {0} 页", totalPages);
            this.p4_txt_currentpage.Text = pageIndex.ToString();

            if (pageIndex <= 1)
            {
                pageIndex = 1;
                this.p4_pic1.Enabled = false;
                this.p4_pic2.Enabled = false;
            }
            else
            {
                this.p4_pic1.Enabled = true;
                this.p4_pic2.Enabled = true;
            }

            if (pageIndex >= totalPages)
            {
                pageIndex = totalPages;
                this.p4_pic3.Enabled = false;
                this.p4_pic3.Enabled = false;
            }
            else
            {
                this.p4_pic3.Enabled = true;
                this.p4_pic3.Enabled = true;
            }

            this.p4_txt_currentpage.Text = pageIndex.ToString();
            this.p4_dvLog.DataSource = currentPageList;
        }
コード例 #2
0
ファイル: frmMain-LogQuery.cs プロジェクト: Jackie2014/W1-IPC
        private void P4_lblExport_Click(object sender, EventArgs e)
        {
            try
            {
                string saveFileName = "";
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.Filter = "CSV文件(逗号分割)|*.csv|文本文件|*.txt";
                saveFileDialog1.Title = "查询日志导出文件";
                saveFileDialog1.ShowDialog();

                if (String.IsNullOrEmpty(saveFileDialog1.FileName))
                {
                    return;
                }
                else
                {
                    saveFileName = saveFileDialog1.FileName;
                }

                List<ClientIPViewModel> exportList = new List<ClientIPViewModel>();
                int index = 1;
                if (p4_chk_onlyNotMatched.Checked)
                {
                    foreach (var item in _clientIPLogsNotMatched)
                    {
                        ClientIPViewModel ipView = new ClientIPViewModel(item);
                        ipView.SeqNo = index;
                        exportList.Add(ipView);
                        index++;
                    }
                }
                else
                {
                    foreach (var item in _clientIPLogs)
                    {
                        ClientIPViewModel ipView = new ClientIPViewModel(item);
                        ipView.SeqNo = index;
                        exportList.Add(ipView);
                        index++;
                    }
                }

                var csvExport = new CSVExport<ClientIPViewModel>(exportList);

                Dictionary<string, string> headerNames = new Dictionary<string, string>();
                //{ "No.", "查询时间", "录入人", "待验证运营商", "详细地址", "IP", "查询结果", "判断结果" }
                headerNames.Add("SeqNo", "No.");
                headerNames.Add("QueryDate", "查询时间");
                headerNames.Add("Recordor", "录入人");
                headerNames.Add("ExpectedISP", "待验证运营商");
                headerNames.Add("Address", "详细地址");
                headerNames.Add("IP", "IP");
                headerNames.Add("RealISP", "查询结果");
                headerNames.Add("StatusDisplay", "判断结果");

                csvExport.ExportToFile(saveFileName, headerNames);

                MessageBox.Show("查询日志已成功导出到 " + saveFileName + "。", "导出成功");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误");
            }
        }