Esempio n. 1
0
        private void SaveSelection()
        {
            int    gridID   = int.Parse(Request["grid"]);
            string col1     = Request["c1"];
            string col2     = Request["c2"];
            double value    = double.Parse(Request["val"]);
            bool   selected = Request["sel"] == "true";

            string sql = selected ? "INSERT INTO TblSelection (fGridRef, fColor1, fColor2, fValue) VALUES (@fGridRef, @fColor1, @fColor2, @fValue)" : "DELETE FROM TblSelection WHERE fGridRef=@fGridRef AND fColor1=@fColor1 AND fColor2=@fColor2";

            using (SqlConnection con = new SqlConnection(dbsource.main))
            {
                con.Open();
                using (SqlCommand cmd = new SqlCommand(sql, con))
                {
                    cmd.Parameters.AddWithValue("@fGridRef", gridID);
                    cmd.Parameters.AddWithValue("@fColor1", col1);
                    cmd.Parameters.AddWithValue("@fColor2", col2);
                    if (selected)
                    {
                        cmd.Parameters.AddWithValue("@fValue", value);
                    }
                    cmd.ExecuteNonQuery();
                }


                double total = 0;
                String query = "SELECT * FROM TblSelection WHERE fGridRef = @fGridRef";
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    cmd.Parameters.AddWithValue("@fGridRef", gridID);
                    using (SqlDataReader set = cmd.ExecuteReader())
                    {
                        while (set.Read() == true)
                        {
                            double val = (double)set["fValue"];
                            total += val;
                        }
                    }
                }

                ColorRamp ramp = new ColorRamp();
                ramp.Load(Server.MapPath("images/ramp.png"));
                String color = ramp.GetColor(total / 100);


                Response.Write(Math.Round(total) + "|" + color);
            }
        }
Esempio n. 2
0
        protected void LoadSelection()
        {
            using (SqlConnection con = new SqlConnection(dbsource.main))
            {
                con.Open();

                GridTools gt        = new GridTools(con, Context);
                int       featureID = int.Parse(Request["fid"]);
                int       i1        = gt.GetIndicatorID(Request["i1"]);
                int       i2        = gt.GetIndicatorID(Request["i2"]);
                int       gridID    = gt.GetGridID(featureID, i1, i2);
                double    total     = 0;
                bool      valFound  = false;
                String    query     = "SELECT * FROM TblSelection WHERE fGridRef = @fGridRef";
                using (SqlCommand cmd = new SqlCommand(query, con))
                {
                    cmd.Parameters.AddWithValue("@fGridRef", gridID);
                    using (SqlDataReader set = cmd.ExecuteReader())
                    {
                        while (set.Read() == true)
                        {
                            double val = (double)set["fValue"];
                            total   += val;
                            valFound = true;
                        }
                    }
                }

                if (valFound == true)
                {
                    ColorRamp ramp = new ColorRamp();
                    ramp.Load(Server.MapPath("images/ramp.png"));
                    String color = ramp.GetColor(total / 100);
                    Response.Write(Request["id"] + "|" + Math.Round(total) + "|" + color);
                }
                else
                {
                    Response.Write(Request["id"] + "|" + "0" + "|" + "#ffffff");
                }
            }
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Session.LCID = 1033;

            String mode = Request["mode"];

            if (mode != null && mode != "")
            {
                if (mode == "savesel")
                {
                    SaveSelection();
                }

                Response.End();
                return;
            }


            id = Request["id"];
            v1 = Request["v1"];
            v2 = Request["v2"];

            GSTool gs = new GSTool(Context);

            feature = gs.GetFeatureDB(Context, int.Parse(id));


            if (Request["v"] != null)
            {
                v = Request["v"];
            }

            double x1 = feature.x1;
            double y1 = feature.y1;
            double x2 = feature.x2;
            double y2 = feature.y2;

            ramp = new ColorRamp();
            ramp.Load(Server.MapPath("images/ramp.png"));

            CMapRect    maprect = new CMapRect(x1, y1, x2, y2);
            CScreenRect scrrect = new CScreenRect(0, 0, bmpx, bmpy);
            CZoom       zoom    = new CZoom();

            zoom.ZoomToFullExtent(maprect, scrrect);

            wkt  = feature.wkt;
            mask = new Bitmap(bmpx, bmpy);
            using (Graphics gr = Graphics.FromImage(mask))
            {
                Brush white = new SolidBrush(Color.White);
                Brush black = new SolidBrush(Color.Black);
                gr.FillRectangle(white, new Rectangle(0, 0, bmpx, bmpy));

                string wkt1 = wkt;
                wkt1 = wkt1.Replace("POLYGON((", "");
                wkt1 = wkt1.Replace("))", "");
                wkt1 = wkt1.Replace("), (", "|");

                GraphicsPath path = new GraphicsPath();

                String[] parts = wkt1.Split('|');
                foreach (String part in parts)
                {
                    String[]     coords     = part.Split(',');
                    List <Point> pointArray = new List <Point>();

                    foreach (String coord in coords)
                    {
                        String[] xy = coord.Trim().Split(' ');
                        double   mx = double.Parse(xy[0].Trim(), CultureInfo.InvariantCulture);
                        double   my = double.Parse(xy[1].Trim(), CultureInfo.InvariantCulture);
                        int      sx = 0;
                        int      sy = 0;
                        zoom.Map2Screen(mx, my, out sx, out sy);
                        pointArray.Add(new Point(sx, sy));
                    }
                    path.AddPolygon(pointArray.ToArray());
                }
                gr.FillPath(black, path);
            }
            String name = "temp/mask_" + Guid.NewGuid().ToString() + ".png";
            String file = Server.MapPath(name);

            mask.Save(file, System.Drawing.Imaging.ImageFormat.Png);
            file_mask = name;


            MMTools mm    = new MMTools(Context);
            dynamic ideas = mm.ReadIdeas(Context);

            if (v1 != null && v1 != "")
            {
                var1 = mm.GetVariable(ideas, v1, Context);
                if (var1 == null)
                {
                    Response.End();
                    return;
                }
                ProcessChart(1, var1);
            }

            if (v2 != null && v2 != "")
            {
                var2 = mm.GetVariable(ideas, v2, Context);
                if (var2 == null)
                {
                    Response.End();
                    return;
                }
                ProcessChart(2, var2);
            }

            // normalize
            double dTotalMain1 = 0;
            double dTotalSub1  = 0;

            foreach (String key in var1.dicb.Keys)
            {
                MMBucket bucket = var1.dicb[key];
                dTotalMain1 += bucket.count;
                foreach (String sub in bucket.dict.Keys)
                {
                    dTotalSub1 += bucket.dict[sub].count;
                }
            }

            foreach (String key in var1.dicb.Keys)
            {
                MMBucket bucket = var1.dicb[key];
                bucket.count = (bucket.count / dTotalMain1);
                foreach (String sub in bucket.dict.Keys)
                {
                    bucket.dict[sub].count = (bucket.dict[sub].count / dTotalSub1);
                }
            }

            // var 2
            if (var2 != null)
            {
                LoadGrid();

                double dTotalMain2 = 0;
                double dTotalSub2  = 0;
                foreach (String key in var2.dicb.Keys)
                {
                    MMBucket bucket = var2.dicb[key];
                    dTotalMain2 += bucket.count;
                    foreach (String sub in bucket.dict.Keys)
                    {
                        dTotalSub2 += bucket.dict[sub].count;
                    }
                }

                foreach (String key in var2.dicb.Keys)
                {
                    MMBucket bucket = var2.dicb[key];
                    bucket.count = (bucket.count / dTotalMain2);
                    foreach (String sub in bucket.dict.Keys)
                    {
                        bucket.dict[sub].count = (bucket.dict[sub].count / dTotalSub2);
                    }
                }
            }

            // dispose
            if (bmp1 != null)
            {
                bmp1.Dispose();
            }

            if (bmp2 != null)
            {
                bmp2.Dispose();
            }

            if (mask != null)
            {
                mask.Dispose();
            }
        }