My codebehind is crazy long and I'd like to "modularize" it a bit.In my web app, there are two ways to do a search: a) type in a number in a box, or b) draw a rectangle on the map.Once the selection is done, the rest of the work is pretty much the same - get the attributes and put it into a grid.I would like to have two user controls, one for a and one for b. Once the query is done, I'd like to send the "ExecuteCompleted" to a single file (results.cs), where it does a bunch of stuff with the results.I've made a UserControl of a panel where the user can type in the number in a box, then click a button.After the button is clicked, a sql string is made and passed to do a query. I could put the ExecuteCompleted in the same file, but I don't really want to. I'd rather have it seperate. However, I don't know how to get the user control to talk to the results.Search.xaml - User Control that has a panel with the text box and button.Search.cs - uses the text box to create a sql statement, passes the sql statement to a query.Results.cs - has the ExecuteCompleted stuff.Don't know how to make Search.cs talk to Results.csAny ideas?Here's the code.Search.cs:
private void CertButton_Click(object sender, RoutedEventArgs e)
{
if (CertNum.Text != "")
{
// ClearGridGraphics(sender, e);
string query_string = "cert_nbr = " + CertNum.Text;
search_waterright(query_string);
}
else MessageBox.Show("You have not typed in a number. Please enter a valid number.");
}
private void search_waterright(string query_string)
{
QueryTask pou_queryTask = new QueryTask("http://weaver.wrd.state.or.us/ArcGIS/rest/services/WR/wr_query/MapServer/1");
// PART I'D LIKE TO CHANGE
pou_queryTask.ExecuteCompleted += pou_QueryTask_ExecuteCompleted;
pou_queryTask.Failed += QueryTask_Failed;
Query pou_query = new ESRI.ArcGIS.Client.Tasks.Query();
pou_query.OutFields.Add("*");
pou_query.Where = query_string;
pou_query.ReturnGeometry = true;
pou_queryTask.ExecuteAsync(pou_query);
}
Results.cs:
public void pou_QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
FeatureSet featureSet = args.FeatureSet;
int i = 0;
i = featureSet.Features.Count;
if (featureSet.Features.Count < 1)
{
ViewWaterRights.Visibility = Visibility.Visible;
POU_WRDetailsDataGrid.Visibility = Visibility.Collapsed;
POU_Message.Visibility = Visibility.Visible;
tabItemPOU.Header = "Places of Use: (Count: 0)";
return;
}
GraphicsLayer graphicsLayer = MyMap.Layers["POUResultsGraphicsLayer"] as GraphicsLayer;
if (featureSet != null && featureSet.Features.Count > 0)
{
List<pouClass> pouList = new List<pouClass>();
foreach (Graphic feature in featureSet.Features)
{
do a bunch of stuff: gather attributes and put in a grid.