Exemple #1
0
        private void ShowTerminals()
        {
            var totalRecords = 0;
            var pageIndex    = "" == hidPageIndex.Value ? 1 : int.Parse(hidPageIndex.Value);
            var list         = TerminalInstance.FindPageList <TB_Terminal>(pageIndex, PageSize, out totalRecords,
                                                                           f => f.Delete == false && f.HasBound == false && f.Type == TerminalType, "Number");
            var totalPages = totalRecords / PageSize + (totalRecords % PageSize > 0 ? 1 : 0);

            string html = "";

            if (totalRecords < 1)
            {
                html = "<tr><td colspan=\"6\">No records</tr>";
            }
            else
            {
                var cnt = (pageIndex - 1) * PageSize;
                var n   = (int?)null;
                foreach (var obj in list)
                {
                    cnt++;
                    var id = Utility.UrlEncode(Utility.Encrypt(obj.id.ToString()));
                    html += "<tr>" +
                            "<td style=\"text-align: center;\"><input type=\"radio\" name=\"satId\" id=\"cb_" + id + "\" /></td>" +
                            "<td style=\"text-align: center;\">" + cnt + "</td>" +
                            "<td><a>" + obj.Number + "</a></td>" +
                            "<td>" + obj.Sim + "</td>" +
                            "<td>" + (n == obj.Satellite ? "-" : obj.TB_Satellite.CardNo) + "</td>" +
                            "<td>" + TerminalTypes.GetTerminalType(obj.Type.Value) + "</td>" +
                            "<td></td>" +
                            "</tr>";
                }
            }
            tbodyBody.InnerHtml  = html;
            divPagging.InnerHtml = "";
            if (totalRecords > 0)
            {
                ShowPaggings(pageIndex, totalPages, totalRecords, "./terminals.aspx", divPagging);
            }
        }
        /// <summary>
        /// 导出终端列表到excel
        /// </summary>
        /// <param name="bll"></param>
        /// <param name="excel"></param>
        private void ExportTerminalsToExcel(ExcelHandlerBLL bll, TB_ExcelHandler excel)
        {
            string      source = "", data = "";
            Application app   = null;
            Workbook    book  = null;
            Worksheet   sheet = null;

            try
            {
                app         = new Application();
                book        = app.Workbooks.Open(EXCEL_PATH + EXCEL_TERMINALS);
                sheet       = (Worksheet)book.ActiveSheet;
                app.Visible = false;
                app.AlertBeforeOverwriting = false;
                app.DisplayAlerts          = false;

                using (var tbll = new TerminalBLL())
                {
                    using (var ebll = new EquipmentBLL())
                    {
                        int line = 2;
                        int cnt  = 0;
                        var n    = (int?)null;
                        var list = tbll.FindList(f => f.Delete == false);
                        foreach (var obj in list)
                        {
                            var x = line + cnt;
                            sheet.Cells[x, 1] = (cnt + 1);
                            sheet.Cells[x, 2] = obj.Number;
                            sheet.Cells[x, 3] = n == obj.Satellite ? "-" : obj.TB_Satellite.CardNo;
                            sheet.Cells[x, 4] = string.IsNullOrEmpty(obj.Firmware) ? "-" : obj.Firmware;
                            sheet.Cells[x, 5] = obj.Revision;
                            sheet.Cells[x, 6] = TerminalTypes.GetTerminalType(obj.Type.Value);
                            sheet.Cells[x, 7] = obj.ProductionDate.Value.ToString("yyyy/MM/dd");
                            var e = ebll.Find(d => d.Terminal == obj.id && d.Deleted == false);
                            sheet.Cells[x, 8] = null == e ? "-" : ebll.GetFullNumber(e);

                            var link = EverdigmUtils.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime, false);
                            link = link.Substring(link.IndexOf('>') + 1);
                            link = link.Substring(0, link.IndexOf('<'));
                            sheet.Cells[x, 9]  = string.IsNullOrEmpty(link) ? "-" : link;
                            sheet.Cells[x, 10] = null == obj.OnlineTime ? "-" : obj.OnlineTime.Value.ToString("yyyy/MM/dd HH:mm");
                            cnt++;
                        }
                    }
                }

                // 另存为别的
                var date = excel.CreateDate.Value.ToString("yyyyMMdd");
                var path = Path.Combine(WEB_PATH, "files\\xls\\", date);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                source = path + "\\Terminals2Excel_" + excel.CreateDate.Value.ToString("yyyyMMdd") + ".xlsx";
                if (File.Exists(source))
                {
                    File.Delete(source);
                }
                book.SaveAs(source);
            }
            catch (Exception e)
            {
                data = e.StackTrace;
                ShowUnhandledMessage(format("{0}Terminal to Excel handler error: {1}{2}{3}", Now, e.Message, Environment.NewLine, e.StackTrace));
            }
            finally
            {
                // 关闭book
                if (null != book)
                {
                    book.Close();
                    book = null;
                }
                // 关闭application
                if (null != app)
                {
                    app.Quit();
                    app = null;
                }
                // 释放内存
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            var target = "../" + source.Replace(WEB_PATH, "").Replace("\\", "/");

            bll.Update(f => f.id == excel.id, act =>
            {
                act.Handled = true;
                act.Status  = (byte)(string.IsNullOrEmpty(data) ? 0 : 1);
                act.Target  = target;
                act.Data    = data;
            });
        }
Exemple #3
0
        private void ShowTerminalsBinded(int pageIndex)
        {
            var totalRecords = 0;
            // 表达式
            Expression <Func <TB_Equipment, bool> > expression = PredicateExtensions.True <TB_Equipment>();

            // 必须是绑定了终端的设备
            expression = expression.And(f => f.Deleted == false && f.Terminal != (int?)null);

            // 设备type
            //var type = ddlEquipmentType.SelectedValue;
            //if (!string.IsNullOrEmpty(type))
            //{
            //    expression = expression.And(a => a.TB_EquipmentModel.Type == ParseInt(type));
            //}

            // 设备model
            //var model = selModel.Value;
            //if (!string.IsNullOrEmpty(model)) { expression = expression.And(a => a.Model == ParseInt(model)); }

            // 是否绑定卫星
            // 是否绑定卫星 -1:ignore,0:not,1:bound
            var sat = int.Parse(selectedSatellite.Value);

            spanSatellite.InnerHtml = "Satellite:" + GotSelectedType(sat);
            if (sat >= 0)
            {
                if (sat == 0)
                {
                    expression = expression.And(a => a.TB_Terminal.Satellite == null);
                }
                else
                {
                    expression = expression.And(a => a.TB_Terminal.Satellite != null);
                }
            }

            // 号码查询
            var query = txtNumber.Value.Trim();

            if (!string.IsNullOrEmpty(query))
            {
                expression = expression.And(a => a.Number.Contains(query) || a.TB_Terminal.Number.Contains(query) || a.TB_Terminal.TB_Satellite.CardNo.Contains(query));
            }

            var list       = EquipmentInstance.FindPageList <TB_Equipment>(pageIndex, PageSize, out totalRecords, expression, "Number");
            var totalPages = totalRecords / PageSize + (totalRecords % PageSize > 0 ? 1 : 0);

            string html = "";

            if (totalRecords < 1)
            {
                html = "<tr><td colspan=\"13\">No records, You can change condition and try again or " +
                       " <a href=\"./terminal_register.aspx\">ADD</a> new one.</td></tr>";
            }
            else
            {
                var cnt = (pageIndex - 1) * PageSize;
                foreach (var obj in list)
                {
                    cnt++;
                    var id = Utility.UrlEncode(Utility.Encrypt(obj.id.ToString()));
                    html += "<tr>" +
                            //"<td style=\"text-align: center;\" class=\"in-tab-txt-rb\"><input type=\"checkbox\" id=\"cb_" + id + "\" /></td>" +
                            "<td style=\"text-align: center;\" class=\"in-tab-txt-rb\">" + cnt + "</td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left !important;\"><a href=\"./terminal_register.aspx?key=" + id + "\" >" + CheckQueryString(obj.TB_Terminal.Number) + "</a></td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left !important; cursor: pointer;\" title=\"Click to show advanced options\">" + CheckQueryString(TerminalInstance.GetSatellite(obj.TB_Terminal, true)) + "</td>" +
                            "<td class=\"in-tab-txt-rb\">" + obj.TB_Terminal.Firmware + "</td>" +
                            "<td class=\"in-tab-txt-rb\">" + obj.TB_Terminal.Revision.ToString() + "</td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left !important;\">" + TerminalTypes.GetTerminalType(obj.TB_Terminal.Type.Value) + "</td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left !important;\">" + obj.TB_Terminal.ProductionDate.Value.ToString("yyyy/MM/dd") + "</td>" +
                            "<td class=\"in-tab-txt-rb\">yes</td>" +
                            "<td class=\"in-tab-txt-rb\" style=\"text-align: left !important;\">" + CheckQueryString(GetEquipment(obj.TB_Terminal, obj)) + "</td>" +
                            "<td class=\"in-tab-txt-b\">" + Utility.GetOnlineStyle(obj.OnlineStyle, obj.OnlineTime, false) + "</td>" +
                            //"<td class=\"in-tab-txt-rb\">" + obj.TB_Terminal.Sim + "</td>" +
                            "<td class=\"in-tab-txt-b\"></td>" +
                            "</tr>";
                }
            }
            ShowFooter(totalRecords, pageIndex, totalPages, html);
        }