示例#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);
            }
        }
示例#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");
                }
            }
        }