using System; using System.Collections.Generic; using System.Text; using System.Data; namespace CrimeScene { class WebServiceManager { private string serviceUrl; private Monster.Service service; private DataSet dataSet; public WebServiceManager(DataSet dataSet) { this.dataSet = dataSet; this.serviceUrl = "http://192.168.0.10:1584/CrimeSceneService/Service.asmx"; this.service = new Monster.Service(); this.service.Url = this.serviceUrl; } public void Connect() { } public DataTable DownloadUsers() { return service.DownloadUsers().Tables["USERS"]; } public DataTable DownloadSceneList() { return service.DownloadSceneList().Tables["SCENE"]; } public DataTable DownloadScene(int homeId) { return service.DownloadSceneList().Tables["SCENE"]; } public void UploadScene(int id) { DataSet res = new DataSet(); DataTable tableScene, tableSceneLocation, tableIncident, tableIncidentLocation, tableWitness, tableWitnessLocation, tableStatement, tableVehicle, tableImage, tableAction; DataRow[] dataRowScene, dataRowSceneLocation, dataRowIncident, dataRowIncidentLocation, dataRowWitness, dataRowWitnessLocation, dataRowStatement, dataRowVehicle, dataRowImage, dataRowAction; string strExpr = ""; string strSort = ""; // Adjust table structure // Scene tableScene = dataSet.Tables["SCENE"].Copy(); // Scene Location tableSceneLocation = dataSet.Tables["SCENE_LOCATION"].Copy(); // Incident tableIncident = dataSet.Tables["INCIDENT"].Copy(); // Inicdent Location tableIncidentLocation = dataSet.Tables["INCIDENT_LOCATION"].Copy(); // Witness tableWitness = dataSet.Tables["WITNESS"].Copy(); // Witness Location tableWitnessLocation = dataSet.Tables["WITNESS_LOCATION"].Copy(); // Statement tableStatement = dataSet.Tables["STATEMENT"].Copy(); // Vehicle tableVehicle = dataSet.Tables["VEHICLE"].Copy(); // Image tableImage = dataSet.Tables["IMAGE"].Copy(); //Action tableAction = dataSet.Tables["ACTION"].Copy(); // Retrieve data // Scene strExpr = "SCENE_ID=" + id; dataRowScene = tableScene.Select(strExpr, strSort); // Action dataRowAction = tableAction.Select(strExpr, strSort); // Scene Location dataRowSceneLocation = tableSceneLocation.Select(strExpr, strSort); // Incident dataRowIncident = tableIncident.Select(strExpr, strSort); // Incident Location strExpr = QueryString("INCIDENT_ID", dataRowIncident); dataRowIncidentLocation = tableIncidentLocation.Select(strExpr, strSort); // Vehicle dataRowVehicle = tableVehicle.Select(strExpr, strSort); // Image dataRowImage = tableImage.Select(strExpr, strSort); // Statement dataRowStatement = tableStatement.Select(strExpr, strSort); // Witness strExpr = QueryString("WITNESS_ID", dataRowStatement); dataRowWitness = tableWitness.Select(strExpr, strSort); // Witness Location strExpr = QueryString("WITNESS_ID", dataRowWitness); dataRowWitnessLocation = tableWitnessLocation.Select(strExpr, strSort); // Convert to client format Convert2Client(tableScene, dataRowScene); Convert2Client(tableSceneLocation, dataRowSceneLocation); Convert2Client(tableIncident, dataRowIncident); Convert2Client(tableIncidentLocation, dataRowIncidentLocation); Convert2Client(tableWitness, dataRowWitness); Convert2Client(tableWitnessLocation, dataRowWitnessLocation); Convert2Client(tableStatement, dataRowStatement); Convert2Client(tableVehicle, dataRowVehicle); Convert2Client(tableImage, dataRowImage); Convert2Client(tableAction, dataRowAction); // Populate dataset res.Tables.Add(tableScene); res.Tables.Add(tableSceneLocation); res.Tables.Add(tableIncident); res.Tables.Add(tableIncidentLocation); res.Tables.Add(tableWitness); res.Tables.Add(tableWitnessLocation); res.Tables.Add(tableStatement); res.Tables.Add(tableVehicle); res.Tables.Add(tableImage); res.Tables.Add(tableAction); service.UploadScene(res); } private void Convert2Client(DataTable table, DataRow[] rows) { bool[] intArray = new bool[table.Rows.Count]; bool del; for (int j = table.Rows.Count - 1; j >= 0; j--) { del = true; for (int i = 0; i < rows.Length; i++) { if ((Int32)rows[i][0] == (Int32)table.Rows[j][0]) { del = false; break; } } if (del) { table.Rows.RemoveAt(j); } } } private string QueryString(string field, DataRow[] row) { string query = ""; int size = row.Length; for (int i = 0; i < size; i++) { query += (field + "=" + row[i][field]); if (i < row.Length - 1) { query += " OR "; } } return query; } } }