Esempio n. 1
0
        protected void editTree(double x, double y)
        {
            double tolerance = 5 * 2.54 / 72 / 100 * mapControl.MapScale;
            Tree   tree      = getTreeIDByLocation(x, y, tolerance);

            if (tree == null)
            {
                return;
            }

            // click a tree and then pop out a dialog to display the detail information about the tree.
            FormTreeInformation dlg = new FormTreeInformation();

            dlg.Id = tree.Id;
            dlg.setXY(tree.X, tree.Y);
            dlg.setTreeAge(tree.Age);
            dlg.setTreeDiameter(tree.Diameter);
            dlg.setTreeType(tree.Treetype);
            if (DialogResult.OK != dlg.ShowDialog())
            {
                return;
            }

            // edit tree info
            NpgsqlConnection conn = getConnection();
            string           sql  = String.Format(""
                                                  + " update "
                                                  + "      trees "
                                                  + " set "
                                                  + "      treetype = @t, "
                                                  + "     age = @a, "
                                                  + "     diameter = @d, "
                                                  + "     lasttime = now()"
                                                  + " where "
                                                  + "      id = @i ");
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            cmd.Parameters.AddWithValue("i", dlg.Id);
            cmd.Parameters.AddWithValue("d", dlg.getTreeDiameter());
            cmd.Parameters.AddWithValue("a", dlg.getTreeAge());
            cmd.Parameters.AddWithValue("t", dlg.getTreeType());
            cmd.ExecuteNonQuery();
            conn.Close();
        }
Esempio n. 2
0
        protected void addTree(double x, double y)
        {
            NpgsqlConnection    conn = getConnection(); // create a connection.
            FormTreeInformation dlg  = new FormTreeInformation();

            dlg.setXY(x, y);
            if (DialogResult.OK != dlg.ShowDialog())
            {
                return;
            }

            // Insert some data
            string        sql = String.Format("insert into trees(geo,treetype,age,diameter) values('SRID=3857;POINT({0} {1})'::geometry,@t,@d,@a)", x, y);
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);

            cmd.Parameters.AddWithValue("t", dlg.getTreeType());
            cmd.Parameters.AddWithValue("d", dlg.getTreeDiameter());
            cmd.Parameters.AddWithValue("a", dlg.getTreeAge());
            cmd.ExecuteNonQuery();

            conn.Close();
            mapControl.ActiveView.Refresh();
        }