Exemple #1
0
    private void WriteData(string layerId, string ids)
    {
        Configuration config = AppContext.GetConfiguration();

        Configuration.LayerFunctionRow layerFunction = config.LayerFunction.First(o => o.LayerID == layerId && o.FunctionName == "export");
        DataTable table = new DataTable();

        using (OleDbCommand command = layerFunction.GetDatabaseCommand())
        {
            command.Parameters[0].Value = ids;

            if (command.Parameters.Count > 1)
            {
                command.Parameters[1].Value = AppUser.GetRole();
            }

            using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
            {
                adapter.Fill(table);
            }

            command.Connection.Dispose();
        }

        // create a CSV file if specified

        if (AppContext.AppSettings.ExportFormat == "csv")
        {
            ExportToCsv(table);
        }
        else
        {
            ExportToExcel(table, layerFunction.LayerRow.Name);
        }
    }
Exemple #2
0
        public StringCollection GetTargetIds(string parameterValues)
        {
            StringCollection ids = new StringCollection();

            try
            {
                Configuration.LayerFunctionRow layerFunction = GetLayerFunctionRows().First(o => o.FunctionName == "targetparams");

                using (OleDbCommand command = layerFunction.GetDatabaseCommand())
                {
                    string[] p = parameterValues.Split(',');

                    for (int i = 0; i < command.Parameters.Count - 1; ++i)
                    {
                        command.Parameters[i].Value = p[i];
                    }

                    command.Parameters[command.Parameters.Count - 1].Value = AppUser.GetRole();

                    using (OleDbDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            ids.Add(reader.GetValue(0).ToString());
                        }
                    }
                }
            }
            catch { }

            return(ids);
        }
Exemple #3
0
    public static DataListBuilder SearchMapTab(string mapTabID, string[] visibleLayers, string levelID, double x, double y,
                                               double distance, double scale, bool addSpace)
    {
        DataListBuilder dataListBuilder = new DataListBuilder();

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.First(o => o.MapTabID == mapTabID);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);

        Dictionary <String, Configuration.LayerRow>         layers         = new Dictionary <String, Configuration.LayerRow>();
        Dictionary <String, Configuration.LayerFunctionRow> layerFunctions = new Dictionary <String, Configuration.LayerFunctionRow>();

        bool useDefaultVisible = visibleLayers.Length == 1 && visibleLayers[0] == "*";

        foreach (Configuration.MapTabLayerRow mapTabLayer in mapTab.GetMapTabLayerRows())
        {
            bool isCandidateLayer = mapTab.IsInteractiveLegendNull() || mapTab.InteractiveLegend == 0;

            if (!isCandidateLayer)
            {
                bool shownInLegend   = !mapTabLayer.IsShowInLegendNull() && mapTabLayer.ShowInLegend == 1;
                bool checkedInLegend = mapTabLayer.IsCheckInLegendNull() || mapTabLayer.CheckInLegend < 0 || visibleLayers.Any(o => o == mapTabLayer.LayerID);
                bool defaultVisible  = useDefaultVisible && !mapTabLayer.IsCheckInLegendNull() && mapTabLayer.CheckInLegend == 1;
                isCandidateLayer = !shownInLegend || checkedInLegend || defaultVisible;
            }

            if (isCandidateLayer)
            {
                Configuration.LayerRow         layer         = mapTabLayer.LayerRow;
                Configuration.LayerFunctionRow layerFunction = layer.GetLayerFunctionRows().FirstOrDefault(o => o.FunctionName.ToLower() == "identify");

                if (layerFunction != null)
                {
                    layers.Add(layer.LayerName, layer);
                    layerFunctions.Add(layer.LayerName, layerFunction);
                }
            }
        }

        foreach (CommonLayer commonLayer in dataFrame.Layers)
        {
            DataTable table = null;

            if (layers.ContainsKey(commonLayer.Name) && commonLayer.IsWithinScaleThresholds(scale))
            {
                Configuration.LayerRow layer = layers[commonLayer.Name];

                if (commonLayer.Type == CommonLayerType.Feature)
                {
                    CommonField keyField   = commonLayer.FindField(layer.KeyField);
                    string      levelQuery = layer.GetLevelQuery(commonLayer, levelID);
                    table = commonLayer.GetFeatureTable(keyField.Name, levelQuery, x, y, commonLayer.FeatureType == OgcGeometryType.MultiPolygon ? 0 : distance * scale);
                }

                if (commonLayer.Type == CommonLayerType.Image && commonLayer is AgsLayer)
                {
                    string id = ((AgsLayer)commonLayer).GetRasterValue(x, y);
                    table = new DataTable();
                    table.Columns.Add("ID");
                    table.Rows.Add(id);
                }
            }

            if (table != null && table.Rows.Count > 0)
            {
                Configuration.LayerFunctionRow layerFunction = layerFunctions[commonLayer.Name];

                foreach (DataRow row in table.Rows)
                {
                    string id = row[0].ToString();

                    using (OleDbCommand command = layerFunction.GetDatabaseCommand())
                    {
                        command.Parameters[0].Value = id;

                        if (command.Parameters.Count > 1)
                        {
                            command.Parameters[1].Value = AppUser.GetRole();
                        }

                        using (OleDbDataReader reader = command.ExecuteReader())
                        {
                            dataListBuilder.AddFromReader(reader, addSpace);
                        }

                        command.Connection.Dispose();
                    }
                }
            }
        }

        return(dataListBuilder);
    }
Exemple #4
0
    private void DefaultMethod()
    {
        string v = Request.Form["visiblelayers"];

        string[] visibleLayers = v == null ? new string[0] : v.Split('\u0001');

        string level    = Request.Form["level"];
        double x        = Convert.ToDouble(Request.Form["x"]);
        double y        = Convert.ToDouble(Request.Form["y"]);
        double distance = Convert.ToDouble(Request.Form["distance"]);
        double scale    = Convert.ToDouble(Request.Form["scale"]);

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.First(o => o.MapTabID == Request.Form["maptab"]);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);

        Dictionary <String, Configuration.LayerRow>         layers         = new Dictionary <String, Configuration.LayerRow>();
        Dictionary <String, Configuration.LayerFunctionRow> layerFunctions = new Dictionary <String, Configuration.LayerFunctionRow>();

        foreach (Configuration.MapTabLayerRow mapTabLayer in mapTab.GetMapTabLayerRows())
        {
            bool isCandidateLayer = mapTab.IsInteractiveLegendNull() || mapTab.InteractiveLegend == 0;

            if (!isCandidateLayer)
            {
                bool shownInLegend   = !mapTabLayer.IsShowInLegendNull() && mapTabLayer.ShowInLegend == 1;
                bool checkedInLegend = mapTabLayer.IsCheckInLegendNull() || mapTabLayer.CheckInLegend < 0 || visibleLayers.Any(o => o == mapTabLayer.LayerID);
                isCandidateLayer = !shownInLegend || checkedInLegend;
            }

            if (isCandidateLayer)
            {
                Configuration.LayerRow         layer         = mapTabLayer.LayerRow;
                Configuration.LayerFunctionRow layerFunction = layer.GetLayerFunctionRows().FirstOrDefault(o => o.FunctionName.ToLower() == "maptip");

                if (layerFunction != null)
                {
                    layers.Add(layer.LayerName, layer);
                    layerFunctions.Add(layer.LayerName, layerFunction);
                }
            }
        }

        string tipText = null;

        for (int i = 0; i < dataFrame.Layers.Count - 1 && tipText == null; ++i)
        {
            CommonLayer commonLayer = dataFrame.Layers[i];
            string      id          = null;

            if (layers.ContainsKey(commonLayer.Name) && commonLayer.IsWithinScaleThresholds(scale))
            {
                if (commonLayer.Type == CommonLayerType.Feature)
                {
                    Configuration.LayerRow layer = layers[commonLayer.Name];
                    string levelQuery            = layer.GetLevelQuery(commonLayer, level);

                    CommonField keyField = commonLayer.FindField(layer.KeyField);
                    DataTable   table    = commonLayer.GetFeatureTable(keyField.Name, levelQuery, x, y, commonLayer.FeatureType == OgcGeometryType.MultiPolygon ? 0 : distance * scale);

                    if (table != null && table.Rows.Count > 0)
                    {
                        id = table.Rows[table.Rows.Count - 1][0].ToString();
                    }
                }

                if (commonLayer.Type == CommonLayerType.Image)
                {
                    id = ((AgsLayer)commonLayer).GetRasterValue(x, y);
                }
            }

            if (!String.IsNullOrEmpty(id))
            {
                Configuration.LayerFunctionRow layerFunction = layerFunctions[commonLayer.Name];

                using (OleDbCommand command = layerFunction.GetDatabaseCommand())
                {
                    command.Parameters[0].Value = id;

                    if (command.Parameters.Count > 1)
                    {
                        command.Parameters[1].Value = AppUser.GetRole();
                    }

                    using (OleDbDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            StringCollection text = new StringCollection();

                            for (int j = 0; j < reader.FieldCount; ++j)
                            {
                                if (!reader.IsDBNull(j))
                                {
                                    text.Add(reader.GetValue(j).ToString());
                                }
                            }

                            if (text.Count > 0)
                            {
                                tipText = text.Join("\n");
                            }
                        }
                    }

                    command.Connection.Close();
                }
            }
        }

        if (tipText == null)
        {
            ReturnJson(null);
        }
        else
        {
            Dictionary <String, Object> result = new Dictionary <String, Object>();
            result.Add("tipText", tipText);
            ReturnJson(result);
        }
    }
Exemple #5
0
    private void CreateLabels(string id, string fontName, float textSize, bool columnMajor)
    {
        Configuration config = AppContext.GetConfiguration();

        string layerID = (string)ViewState["layer"];

        Configuration.LayerFunctionRow layerFunction = config.LayerFunction.First(o => o.LayerID == layerID && o.FunctionName == "mailinglabel");
        Configuration.MailingLabelRow  mailingLabel  = config.MailingLabel.First(o => o.ID == Convert.ToInt32(id));

        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "inline; filename=Labels.pdf");

        float pageWidth  = 8.5f * PointsPerInch;
        float pageHeight = 11.0f * PointsPerInch;

        iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(pageWidth, pageHeight);
        pageSize.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.White);
        Document document = new Document(pageSize);

        document.SetMargins(0, 0, 0, 0);

        PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);

        document.Open();
        PdfContentByte content = writer.DirectContent;

        float textWidth  = mailingLabel.dxLabel - 2 * mailingLabel.xOrg;
        float textHeight = mailingLabel.dyLabel - 2 * mailingLabel.yOrg;

        float labelStartX = mailingLabel.xLeft;
        float labelStartY = pageHeight - mailingLabel.yTop - mailingLabel.dyLabel;

        float leading = textSize * 1.2f;

        BaseFont baseFont = BaseFont.CreateFont(fontName, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

        iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, textSize, iTextSharp.text.Font.NORMAL);

        using (OleDbCommand command = layerFunction.GetDatabaseCommand())
        {
            command.Parameters[0].Value = (string)ViewState["ids"];

            if (command.Parameters.Count > 1)
            {
                command.Parameters[1].Value = AppUser.GetRole();
            }

            using (OleDbDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    List <String> text = new List <String>();

                    for (int i = 0; i < reader.FieldCount; ++i)
                    {
                        if (!reader.IsDBNull(i))
                        {
                            text.Add(reader.GetValue(i).ToString());
                        }
                    }

                    if (text.Count > 0)
                    {
                        float originX = labelStartX + mailingLabel.xOrg;
                        float originY = labelStartY + mailingLabel.yOrg;

                        ColumnText columnText = new ColumnText(content);
                        columnText.SetSimpleColumn(originX, originY, originX + textWidth, originY + textHeight, leading, Element.ALIGN_LEFT);
                        columnText.AddText(new Phrase(leading, String.Join("\n", text.ToArray()), font));
                        columnText.Go();

                        if (columnMajor)
                        {
                            labelStartY -= mailingLabel.dyLabel + mailingLabel.dySpace;

                            if (labelStartY <= 0)
                            {
                                labelStartY  = pageHeight - mailingLabel.yTop - mailingLabel.dyLabel;
                                labelStartX += mailingLabel.dxLabel + mailingLabel.dxSpace;

                                if (labelStartX + mailingLabel.dxLabel > pageWidth)
                                {
                                    document.NewPage();
                                    labelStartX = mailingLabel.xLeft;
                                }
                            }
                        }
                        else
                        {
                            labelStartX += mailingLabel.dxLabel + mailingLabel.dxSpace;

                            if (labelStartX + mailingLabel.dxLabel > pageWidth)
                            {
                                labelStartX  = mailingLabel.xLeft;
                                labelStartY -= mailingLabel.dyLabel + mailingLabel.dySpace;

                                if (labelStartY <= 0)
                                {
                                    document.NewPage();
                                    labelStartY = pageHeight - mailingLabel.yTop - mailingLabel.dyLabel;
                                }
                            }
                        }
                    }
                }
            }

            command.Connection.Dispose();
        }

        document.Close();
        Response.End();
    }