public void withPlayer (RichChar user) { user.landing = cache_current_property; user.stepdata = this; if (owner == -1) { buildingtitle = relation.UNCLAIMED; } else if (owner == -2) { buildingtitle = relation.FUNCTIONAL_LAND; } else { if (owner == user.owner_id) buildingtitle = relation.MY_PROPERTY; if (owner != user.owner_id) { buildingtitle = relation.OWNED_BY_OTHER; } } }
public static void addFamily(bool student, relation relationship, string first, string last, string contact, string email, string empRelation = "Brother") { if (student) { Navigate.RandomStudent(); CustomControls.click("li[id='li-family'] a[class='rToggle']", propertytype.CssSelector); CustomControls.click("#btn-family", propertytype.CssSelector); Wait.ImplicitWait(10); //select relation type, for that we need to click the drop down and select the relation type CustomControls.click("/html/body/div[2]/div[2]/div[2]/div/div/div/div/div/form/div/div[1]/div/select", propertytype.XPath); CustomControls.Selectdropdown("/html/body/div[2]/div[2]/div[2]/div/div/div/div/div/form/div/div[1]/div/select", Enum.GetName(typeof(relation), relationship), propertytype.XPath); Wait.ImplicitWait(10); CustomControls.Entertext("/html/body/div[2]/div[2]/div[2]/div/div/div/div/div/form/div/div[3]/div/input", first, propertytype.XPath); CustomControls.Entertext("/html/body/div[2]/div[2]/div[2]/div/div/div/div/div/form/div/div[5]/div/input", last, propertytype.XPath); CustomControls.Entertext("/html/body/div[2]/div[2]/div[2]/div/div/div/div/div/form/div/div[6]/div/input", contact, propertytype.XPath); CustomControls.Entertext("/html/body/div[2]/div[2]/div[2]/div/div/div/div/div/form/div/div[7]/div/input", email, propertytype.XPath); //submit CustomControls.click("/html/body/div[2]/div[2]/div[2]/div/div/div/div/div/form/div/div[10]/button[3]", propertytype.XPath); //confirmation OK CustomControls.click("/html/body/div[6]/div[7]/button[2]", propertytype.XPath); delayfor.delay(); } else { Navigate.RandomEmployee(); CustomControls.click("li[id='li-familys'] a[class='rToggle']", propertytype.CssSelector); CustomControls.click("#btn-family", propertytype.CssSelector); Wait.ImplicitWait(10); CustomControls.Entertext("#contact-type-name", first + " " + last, propertytype.CssSelector); CustomControls.click("#relationship-type", propertytype.CssSelector); CustomControls.Selectdropdown("#relationship-type", empRelation, propertytype.CssSelector); CustomControls.Entertext("#contact-type-number", contact, propertytype.CssSelector); CustomControls.click("//*[@id=\"save-close-button\"]", propertytype.CssSelector); delayfor.delay(); CustomControls.click("button[class='confirm']", propertytype.CssSelector); delayfor.delay(); } }
/// <summary> /// Deletes the given relation by adding it's deletion to the current changeset. /// </summary> /// <param name="relation"></param> public void RelationDelete(Relation relation) { if (_current_changeset == null) { throw new InvalidOperationException("No open changeset found!"); } if (!relation.Id.HasValue) { throw new ArgumentOutOfRangeException("Cannot update an object without an id!"); } // build a new node. relation xml_relation = relation.ConvertTo(); xml_relation.changeset = _current_changeset.id; xml_relation.changesetSpecified = true; // encapsulate into an osm object. OsmSharp.Osm.Xml.v0_6.osm osm = new Osm.Xml.v0_6.osm(); osm.relation = new Osm.Xml.v0_6.relation[1]; osm.relation[0] = xml_relation; // serialize the changeset. XmlSerializer serializer = new XmlSerializer(typeof(OsmSharp.Osm.Xml.v0_6.osm)); MemoryStream mem_stream = new MemoryStream(); Stream stream = mem_stream; serializer.Serialize(stream, osm); stream.Flush(); mem_stream.Flush(); byte[] put_data = mem_stream.ToArray(); // do the api call. this.DoApiCall(true, string.Format("api/0.6/relation/{0}", relation.Id.Value), Method.DELETE, put_data); }
internal static Relation ConvertToSimple(relation re) { Relation relation = new Relation(); if (re.idSpecified) { relation.Id = new long?(re.id); } if (re.changesetSpecified) { relation.ChangeSetId = new long?(re.changeset); } if (re.visibleSpecified) { relation.Visible = new bool?(re.visible); } else { relation.Visible = new bool?(true); } if (re.timestampSpecified) { relation.TimeStamp = new DateTime?(re.timestamp); } if (re.uidSpecified) { relation.UserId = new long?(re.uid); } if (re.versionSpecified) { relation.Version = new ulong?(re.version); } relation.UserName = re.user; relation.Tags = XmlSimpleConverter.ConvertToTags(re.tag); if (re.member != null && re.member.Length != 0) { relation.Members = new List <RelationMember>(); for (int index = 0; index < re.member.Length; ++index) { member member = re.member[index]; RelationMember relationMember = new RelationMember(); if (member.refSpecified) { relationMember.MemberId = new long?(member.@ref); } relationMember.MemberRole = member.role; if (member.typeSpecified) { switch (member.type) { case memberType.node: relationMember.MemberType = new OsmGeoType?(OsmGeoType.Node); break; case memberType.way: relationMember.MemberType = new OsmGeoType?(OsmGeoType.Way); break; case memberType.relation: relationMember.MemberType = new OsmGeoType?(OsmGeoType.Relation); break; } } relation.Members.Add(relationMember); } } return(relation); }
private void search(object file) { bool right = false; string errorMessage = ""; AsyncEnableButton(false); try { project pro = new project(); pro = (project)file; Cursor.Current = Cursors.WaitCursor; switch (pro.dbDataType) { case project.databaseType.mySql: String connectionString = null; connectionString = "Server=" + pr.host + ";Database=" + pr.database + ";Uid=" + pr.user + ";Pwd=" + pr.password + ";"; dbMySql db = new dbMySql(); errorMessage = db.test(connectionString); if (errorMessage.Equals("")) { AsyncWrite(""); AsyncWriteLine("Success connection \n"); //pr = new project(); //pr.name = pr.name; // lets get the tables... List<table> lista = new List<table>(); lista = db.getTables(connectionString, pr.database); //lista.Sort(); pr.tables.Clear(); foreach (table item in lista) { AsyncWriteLine("Found table... " + item.Name + "\n"); // now lets get the fields for each table... List<field> listaField = new List<field>(); listaField = db.getFields(connectionString, pr.database, item.Name); if (listaField != null) { foreach (field fi in listaField) { item.fields.Add(fi); AsyncWriteLine("Found field... " + fi.Name + "\n"); } // the descriptionField its the first string field of table... foreach (field campito in listaField) { if (campito.type.ToString().Equals("_string") || campito.type.ToString().Equals("_text")) { item.fieldDescription = campito.Name; break; } } if (item.fieldDescription == null) item.fieldDescription = listaField[0].Name; } // lets get primary keys and foreign keys for the table... db.getKeys(connectionString, item, pr.database); // lets sort the fields in the table... // we order but put first key fields if (general.orderFields) { item.fields.Sort(new compareFields(compareFields.CompareByOptions.name)); item.fields.Sort(new compareFields(compareFields.CompareByOptions.key)); } pr.tables.Add(item); } pr.tables.Sort(); //// now lets get the relations ... pr.relations.Clear(); List<relation> listarelation = new List<relation>(); listarelation = db.getRelations(connectionString, pr.database); if (listarelation != null) { foreach (relation re in listarelation) { // found description of fields... foreach (table item in pr.tables) { if (item.Name.ToLower().Equals(re.childTable.ToLower())) { re.childDescription = item.fieldDescription; // we put the field as keyfield... foreach (field fi in item.fields) { if (fi.Name.ToLower().Equals(re.childField.ToLower())) fi.isForeignKey = true; } } if (item.Name.ToLower().Equals(re.parentTable.ToLower())) re.parentDescription = item.fieldDescription; } if (!pr.existsRelation(re.parentTable, re.childTable)) { pr.relations.Add(re); AsyncWriteLine("Found relation... " + re.name + "\n"); } // now if the relation has to do with the tables... foreach (table item in pr.tables) { // we put the relation in the child table... if (item.Name.ToLower().Equals(re.childTable.ToLower())) item.relations.Add(re); } } } // also we can get relations about the field names foreach (table tab in pr.tables) { foreach (field campo in tab.fields) { if (campo.isKey) { foreach (table tab2 in pr.tables) { if (!tab.Name.ToLower().Equals(tab2.Name.ToLower())) { foreach (field campo2 in tab2.fields) { if (campo.Name.ToLower().Equals(campo2.Name.ToLower())) { // check if relation exists.. if (!pr.existsRelation(tab.Name, tab2.Name)) { campo2.isForeignKey = true; relation rel = new relation(); rel.name = tab2.Name + "_" + tab.Name; bool found = false; foreach (relation relax in pr.relations) { if (relax.name.Equals(rel.name)) found = true; } if (!found) { rel.parentTable = tab.Name; rel.parentField = campo.Name; rel.childTable = tab2.Name; rel.childField = campo2.Name; // found description of fields... foreach (table item in pr.tables) { if (item.Name.ToLower().Equals(rel.childTable.ToLower())) rel.childDescription = item.fieldDescription; if (item.Name.ToLower().Equals(rel.parentTable.ToLower())) rel.parentDescription = item.fieldDescription; } pr.relations.Add(rel); // now if the relation has to do with the tables... foreach (table item in pr.tables) { if (item.Name.Equals(tab2.Name)) item.relations.Add(rel); } } } } } } } } } } right = true; pr.host = pro.host; pr.database = pro.database; pr.user = pro.user; pr.password = pro.password; pr.dbDataType = pro.dbDataType; //pr.saveProject(Path.Combine(util.projects_dir, pro.name + ".xml")); // lets save it for next load of application... // pr.saveProject(Path.Combine(util.projects_dir, "conf.xml")); // AsyncWriteLine("Project saved... \n"); } else { AsyncWrite(errorMessage); } break; case project.databaseType.SqlServer: connectionString = "Data Source=" + pro.host + ";Network Library=DBMSSOCN;Initial Catalog=" + pro.database + ";User ID=" + pro.user + ";Password="******";"; // connectionStringOleDb = "Provider=SQLNCLI;Server=" + txtHost.Text + ";Database=" + txtDatabase.Text + ";Uid=" + txtUser.Text + ";Pwd=" + txtPassword.Text + ";"; dbSql2005 dbSqlServer = new dbSql2005(); errorMessage = dbSqlServer.test(connectionString); if (errorMessage.Equals("")) { AsyncWrite(""); AsyncWriteLine("Success connection \n"); //pr = new project(); //pr.name = pro.name; // lets get the tables... List<table> lista = new List<table>(); lista = dbSqlServer.getTables(connectionString, pro.database); //lista.Sort(); foreach (table item in lista) { AsyncWriteLine("Found table... " + item.Name + "\n"); // now lets get the fields for each table... List<field> listaField = new List<field>(); listaField = dbSqlServer.getFields(connectionString, item.Name); if (listaField != null) { foreach (field fi in listaField) { item.fields.Add(fi); AsyncWriteLine("Found field... " + fi.Name + "\n"); } // the descriptionField its the first string field of table... foreach (field campito in listaField) { if (campito.type.ToString().Equals("_string") || campito.type.ToString().Equals("_text")) { item.fieldDescription = campito.Name; break; } } if (item.fieldDescription == null) item.fieldDescription = listaField[0].Name; } // lets get primary keys and foreign keys for the table... dbSqlServer.getKeys(connectionString, item); // lets get not primary keys foreach (field campito in item.fields) { if (!campito.isKey) item.getNotKeyFields.Add(campito); } // lets sort the fields in the table... // we order but put first key fields if (general.orderFields) { item.fields.Sort(new compareFields(compareFields.CompareByOptions.name)); item.fields.Sort(new compareFields(compareFields.CompareByOptions.key)); } pr.tables.Add(item); // lets get description of table string DescriptionOfTable = ""; DescriptionOfTable = dbSqlServer.getCommentsFromTable(connectionString, item.Name); if (DescriptionOfTable.IndexOf("#exclude#") != -1) { item.excludeFromGeneration = true; DescriptionOfTable.Replace("#exclude#", ""); } if (!DescriptionOfTable.Equals("")) item.TargetName = DescriptionOfTable; // end of description for table } pr.tables.Sort(); // now lets get the relations ... List<relation> listarelation = new List<relation>(); listarelation = dbSqlServer.getRelations(connectionString); if (listarelation != null) { foreach (relation re in listarelation) { // item.fields.Add(re); pr.relations.Add(re); AsyncWriteLine("Found relation... " + re.name + "\n"); // now if the relation has to do with the tables... foreach (table item in pr.tables) { // we put the relation in the parent table... if (item.Name.ToLower().Equals(re.parentTable.ToLower())) { // le añadimos la descripcion re.parentDescription = item.fieldDescription; foreach (table taby in pr.tables) { if (taby.Name.Equals(re.childTable)) re.childDescription = taby.fieldDescription; } item.relations.Add(re); } } } } // also we can get relations about the field names foreach (table tab in pr.tables) { foreach (field campo in tab.fields) { if (campo.isKey) { foreach (table tab2 in pr.tables) { if (!tab.Name.ToLower().Equals(tab2.Name.ToLower())) { foreach (field campo2 in tab2.fields) { if (campo.Name.ToLower().Equals(campo2.Name.ToLower())) { campo2.isForeignKey = true; relation rel = new relation(); rel.name = tab.Name + "_" + tab2.Name; if (!pr.relations.Contains(rel.name)) { rel.parentTable = tab2.Name; rel.parentField = campo2.Name; rel.childTable = tab.Name; rel.childField = campo.Name; // found description of fields... foreach (table item in pr.tables) { if (item.Name.ToLower().Equals(rel.childTable.ToLower())) rel.childDescription = item.fieldDescription; if (item.Name.ToLower().Equals(rel.parentTable.ToLower())) rel.parentDescription = item.fieldDescription; } pr.relations.Add(rel); // now if the relation has to do with the tables... foreach (table item in pr.tables) { if (item.Name.Equals(tab2.Name)) { // see if the relation exists.. bool seguir = true; foreach (relation rel2 in tab2.relations) { if (rel2.name.ToLower().Equals(rel.name.ToLower())) seguir = false; } if (seguir) item.relations.Add(rel); } } } } } } } } } } right = true; pr.host = pro.host; pr.database = pro.database; pr.user = pro.user; pr.password = pro.password; pr.dbDataType = pro.dbDataType; //pr.saveProject(Path.Combine(util.projects_dir, pro.name + ".xml")); // lets save it for next load of application... // pr.saveProject(Path.Combine(util.projects_dir, "conf.xml")); //AsyncWriteLine("Project saved... \n"); } else { AsyncWrite(errorMessage); } break; case project.databaseType.dbf: connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pro.database + ";Extended Properties=dBASE IV;User ID=" + pro.user + ";Password="******";"; dbDbf dbf = new dbDbf(); errorMessage = dbf.test(connectionString); if (errorMessage.Equals("")) { AsyncWrite(""); AsyncWriteLine("Success connection \n"); //pr = new project(); //pr.name = pro.name; // lets get the tables... List<table> lista = new List<table>(); lista = dbf.getTables(connectionString, pro.database); //lista.Sort(); foreach (table item in lista) { AsyncWriteLine("Found table... " + item.Name + "\n"); // now lets get the fields for each table... List<field> listaField = new List<field>(); listaField = dbf.getFields(connectionString, item.Name); if (listaField != null) { foreach (field fi in listaField) { item.fields.Add(fi); AsyncWriteLine("Found field... " + fi.Name + "\n"); } // the descriptionField its the first string field of table... foreach (field campito in listaField) { if (campito.type.ToString().Equals("_string") || campito.type.ToString().Equals("_text")) { item.fieldDescription = campito.Name; break; } } if (item.fieldDescription == null) item.fieldDescription = listaField[0].Name; } // lets get primary keys and foreign keys for the table... dbf.getKeys(connectionString, item); // lets sort the fields in the table... // we order but put first key fields if (general.orderFields) { item.fields.Sort(new compareFields(compareFields.CompareByOptions.name)); item.fields.Sort(new compareFields(compareFields.CompareByOptions.key)); } pr.tables.Add(item); } pr.tables.Sort(); // now lets get the relations ... List<relation> listarelation = new List<relation>(); listarelation = dbf.getRelations(connectionString); if (listarelation != null) { foreach (relation re in listarelation) { // item.fields.Add(re); pr.relations.Add(re); AsyncWriteLine("Found relation... " + re.name + "\n"); // now if the relation has to do with the tables... foreach (table item in pr.tables) { // we put the relation in the parent table... if (item.Name.ToLower().Equals(re.parentTable.ToLower())) { // le añadimos la descripcion re.parentDescription = item.fieldDescription; foreach (table taby in pr.tables) { if (taby.Name.Equals(re.childTable)) re.childDescription = taby.fieldDescription; } item.relations.Add(re); } } } } // also we can get relations about the field names foreach (table tab in pr.tables) { foreach (field campo in tab.fields) { if (campo.isKey) { foreach (table tab2 in pr.tables) { if (!tab.Name.ToLower().Equals(tab2.Name.ToLower())) { foreach (field campo2 in tab2.fields) { if (campo.Name.ToLower().Equals(campo2.Name.ToLower())) { campo2.isForeignKey = true; relation rel = new relation(); rel.name = tab.Name + "_" + tab2.Name; if (!pr.relations.Contains(rel.name)) { rel.parentTable = tab2.Name; rel.parentField = campo2.Name; rel.childTable = tab.Name; rel.childField = campo.Name; // found description of fields... foreach (table item in pr.tables) { if (item.Name.ToLower().Equals(rel.childTable.ToLower())) rel.childDescription = item.fieldDescription; if (item.Name.ToLower().Equals(rel.parentTable.ToLower())) rel.parentDescription = item.fieldDescription; } pr.relations.Add(rel); // now if the relation has to do with the tables... foreach (table item in pr.tables) { if (item.Name.Equals(tab2.Name)) { // see if the relation exists.. bool seguir = true; foreach (relation rel2 in tab2.relations) { if (rel2.name.ToLower().Equals(rel.name.ToLower())) seguir = false; } if (seguir) item.relations.Add(rel); } } } } } } } } } } right = true; pr.host = pro.host; pr.database = pro.database; pr.user = pro.user; pr.password = pro.password; pr.dbDataType = pro.dbDataType; } else { AsyncWriteLine(errorMessage); } break; case project.databaseType.access2003: connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pro.database + ";User ID=" + pro.user + ";Password="******";"; dbAccess dba2003 = new dbAccess(); errorMessage = dba2003.test(connectionString); if (errorMessage.Equals("")) { AsyncWrite(""); AsyncWriteLine("Success connection \n"); //pr = new project(); //pr.name = pro.name; // lets get the tables... List<table> lista = new List<table>(); lista = dba2003.getTables(connectionString, pro.database); //lista.Sort(); foreach (table item in lista) { AsyncWriteLine("Found table... " + item.Name + "\n"); // now lets get the fields for each table... List<field> listaField = new List<field>(); listaField = dba2003.getFields(connectionString, item.Name); if (listaField != null) { foreach (field fi in listaField) { item.fields.Add(fi); AsyncWriteLine("Found field... " + fi.Name + "\n"); } } // lets get primary keys and foreign keys for the table... dba2003.getKeys(connectionString, item); // now we search a text field that is not key if (listaField != null) { // the descriptionField its the first string field of table... foreach (field campito in listaField) { if (campito.type.ToString().Equals("_string") && !campito.isKey) { item.fieldDescription = campito.Name; break; } } } if (item.fieldDescription == null) item.fieldDescription = item.GetKey; // lets sort the fields in the table... // we order but put first key fields if (general.orderFields) { item.fields.Sort(new compareFields(compareFields.CompareByOptions.name)); item.fields.Sort(new compareFields(compareFields.CompareByOptions.key)); } pr.tables.Add(item); } pr.tables.Sort(); // now lets get the relations ... List<relation> listarelation = new List<relation>(); listarelation = dba2003.getRelations(connectionString); if (listarelation != null) { foreach (relation re in listarelation) { // item.fields.Add(re); pr.relations.Add(re); AsyncWriteLine("Found relation... " + re.name + "\n"); // now if the relation has to do with the tables... foreach (table item in pr.tables) { // we put the relation in the parent table... if (item.Name.ToLower().Equals(re.parentTable.ToLower())) { // le añadimos la descripcion re.parentDescription = item.fieldDescription; foreach (table taby in pr.tables) { if (taby.Name.Equals(re.childTable)) re.childDescription = taby.fieldDescription; } item.relations.Add(re); } } } } // also we can get relations about the field names foreach (table tab in pr.tables) { foreach (field campo in tab.fields) { if (campo.isKey) { foreach (table tab2 in pr.tables) { if (!tab.Name.ToLower().Equals(tab2.Name.ToLower())) { foreach (field campo2 in tab2.fields) { if (campo.Name.ToLower().Equals(campo2.Name.ToLower())) { campo2.isForeignKey = true; relation rel = new relation(); rel.name = tab.Name + "_" + tab2.Name; if (!pr.relations.Contains(rel.name)) { rel.parentTable = tab2.Name; rel.parentField = campo2.Name; rel.childTable = tab.Name; rel.childField = campo.Name; // found description of fields... foreach (table item in pr.tables) { if (item.Name.ToLower().Equals(rel.childTable.ToLower())) rel.childDescription = item.fieldDescription; if (item.Name.ToLower().Equals(rel.parentTable.ToLower())) rel.parentDescription = item.fieldDescription; } pr.relations.Add(rel); // now if the relation has to do with the tables... foreach (table item in pr.tables) { if (item.Name.Equals(tab2.Name)) { // see if the relation exists.. bool seguir = true; foreach (relation rel2 in tab2.relations) { if (rel2.name.ToLower().Equals(rel.name.ToLower())) seguir = false; } if (seguir) item.relations.Add(rel); } } } } } } } } } } right = true; pr.host = pro.host; pr.database = pro.database; pr.user = pro.user; pr.password = pro.password; pr.dbDataType = pro.dbDataType; } else { AsyncWriteLine(errorMessage); } break; case project.databaseType.access2007: connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pro.database + ";Persist Security Info=False;"; //Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pro.database + ";Jet OLEDB:Database Password=MyDbPassword; dbAccess dba2007 = new dbAccess(); errorMessage = dba2007.test(connectionString); if (errorMessage.Equals("")) { AsyncWrite(""); AsyncWriteLine("Success connection \n"); //pr = new project(); //pr.name = pro.name; // lets get the tables... List<table> lista = new List<table>(); lista = dba2007.getTables(connectionString, pro.database); //lista.Sort(); foreach (table item in lista) { AsyncWriteLine("Found table... " + item.Name + "\n"); // now lets get the fields for each table... List<field> listaField = new List<field>(); listaField = dba2007.getFields(connectionString, item.Name); if (listaField != null) { foreach (field fi in listaField) { item.fields.Add(fi); AsyncWriteLine("Found field... " + fi.Name + "\n"); } } // lets get primary keys and foreign keys for the table... dba2007.getKeys(connectionString, item); // now we search a text field that is not key if (listaField != null) { // the descriptionField its the first string field of table... foreach (field campito in listaField) { if (campito.type.ToString().Equals("_string") || campito.type.ToString().Equals("_text") ) { item.fieldDescription = campito.Name; break; } } } if (item.fieldDescription == null) item.fieldDescription = item.GetKey; // lets sort the fields in the table... // we order but put first key fields if (general.orderFields) { item.fields.Sort(new compareFields(compareFields.CompareByOptions.name)); item.fields.Sort(new compareFields(compareFields.CompareByOptions.key)); } pr.tables.Add(item); } pr.tables.Sort(); // now lets get the relations ... List<relation> listarelation = new List<relation>(); listarelation = dba2007.getRelations(connectionString); if (listarelation != null) { foreach (relation re in listarelation) { // item.fields.Add(re); pr.relations.Add(re); AsyncWriteLine("Found relation... " + re.name + "\n"); // now if the relation has to do with the tables... foreach (table item in pr.tables) { // we put the relation in the parent table... if (item.Name.ToLower().Equals(re.parentTable.ToLower())) { // le añadimos la descripcion re.parentDescription = item.fieldDescription; foreach (table taby in pr.tables) { if (taby.Name.Equals(re.childTable)) re.childDescription = taby.fieldDescription; } item.relations.Add(re); } } } } // also we can get relations about the field names foreach (table tab in pr.tables) { foreach (field campo in tab.fields) { if (campo.isKey) { foreach (table tab2 in pr.tables) { if (!tab.Name.ToLower().Equals(tab2.Name.ToLower())) { foreach (field campo2 in tab2.fields) { if (campo.Name.ToLower().Equals(campo2.Name.ToLower())) { campo2.isForeignKey = true; relation rel = new relation(); rel.name = tab.Name + "_" + tab2.Name; if (!pr.relations.Contains(rel.name)) { rel.parentTable = tab2.Name; rel.parentField = campo2.Name; rel.childTable = tab.Name; rel.childField = campo.Name; // found description of fields... foreach (table item in pr.tables) { if (item.Name.ToLower().Equals(rel.childTable.ToLower())) rel.childDescription = item.fieldDescription; if (item.Name.ToLower().Equals(rel.parentTable.ToLower())) rel.parentDescription = item.fieldDescription; } pr.relations.Add(rel); // now if the relation has to do with the tables... foreach (table item in pr.tables) { if (item.Name.Equals(tab2.Name)) { // see if the relation exists.. bool seguir = true; foreach (relation rel2 in tab2.relations) { if (rel2.name.ToLower().Equals(rel.name.ToLower())) seguir = false; } if (seguir) item.relations.Add(rel); } } } } } } } } } } right = true; pr.host = pro.host; pr.database = pro.database; pr.user = pro.user; pr.password = pro.password; pr.dbDataType = pro.dbDataType; } else { AsyncWriteLine(errorMessage); } break; // end of access2007 case project.databaseType.excelOrCsv: if (pr.database.Contains("xls")) connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pr.database + ";Extended Properties=\"text;HDR=Yes;FMT=Delimited\""; else connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pr.database + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""; dbExcelOrCsv dbaODBC = new dbExcelOrCsv(); errorMessage = dbaODBC.test(connectionString); if (errorMessage.Equals("")) { AsyncWrite(""); AsyncWriteLine("Success connection \n"); //pr = new project(); //pr.name = pro.name;9 // lets get the tables... List<table> lista = new List<table>(); lista = dbaODBC.getTables(connectionString, pr.database); //lista.Sort(); foreach (table item in lista) { AsyncWriteLine("Found table... " + item.Name + "\n"); // now lets get the fields for each table... List<field> listaField = new List<field>(); listaField = dbaODBC.getFields(connectionString, item.Name); if (listaField != null) { foreach (field fi in listaField) { item.fields.Add(fi); AsyncWriteLine("Found field... " + fi.Name + "\n"); } } // lets get primary keys and foreign keys for the table... dbaODBC.getKeys(connectionString, item); // now we search a text field that is not key if (listaField != null) { // the descriptionField its the first string field of table... foreach (field campito in listaField) { if (campito.type.ToString().Equals("_string") || campito.type.ToString().Equals("_text")) { item.fieldDescription = campito.Name; break; } } } if (item.fieldDescription == null) item.fieldDescription = item.GetKey; // lets sort the fields in the table... // we order but put first key fields if (general.orderFields) { item.fields.Sort(new compareFields(compareFields.CompareByOptions.name)); item.fields.Sort(new compareFields(compareFields.CompareByOptions.key)); } pr.tables.Add(item); } pr.tables.Sort(); // now lets get the relations ... List<relation> listarelation = new List<relation>(); listarelation = dbaODBC.getRelations(connectionString); if (listarelation != null) { foreach (relation re in listarelation) { // item.fields.Add(re); pr.relations.Add(re); AsyncWriteLine("Found relation... " + re.name + "\n"); // now if the relation has to do with the tables... foreach (table item in pr.tables) { // we put the relation in the parent table... if (item.Name.ToLower().Equals(re.parentTable.ToLower())) { // le añadimos la descripcion re.parentDescription = item.fieldDescription; foreach (table taby in pr.tables) { if (taby.Name.Equals(re.childTable)) re.childDescription = taby.fieldDescription; } item.relations.Add(re); } } } } // also we can get relations about the field names foreach (table tab in pr.tables) { foreach (field campo in tab.fields) { if (campo.isKey) { foreach (table tab2 in pr.tables) { if (!tab.Name.ToLower().Equals(tab2.Name.ToLower())) { foreach (field campo2 in tab2.fields) { if (campo.Name.ToLower().Equals(campo2.Name.ToLower())) { campo2.isForeignKey = true; relation rel = new relation(); rel.name = tab.Name + "_" + tab2.Name; if (!pr.relations.Contains(rel.name)) { rel.parentTable = tab2.Name; rel.parentField = campo2.Name; rel.childTable = tab.Name; rel.childField = campo.Name; // found description of fields... foreach (table item in pr.tables) { if (item.Name.ToLower().Equals(rel.childTable.ToLower())) rel.childDescription = item.fieldDescription; if (item.Name.ToLower().Equals(rel.parentTable.ToLower())) rel.parentDescription = item.fieldDescription; } pr.relations.Add(rel); // now if the relation has to do with the tables... foreach (table item in pr.tables) { if (item.Name.Equals(tab2.Name)) { // see if the relation exists.. bool seguir = true; foreach (relation rel2 in tab2.relations) { if (rel2.name.ToLower().Equals(rel.name.ToLower())) seguir = false; } if (seguir) item.relations.Add(rel); } } } } } } } } } } right = true; pr.host = pr.host; pr.database = pr.database; pr.user = pr.user; pr.password = pr.password; pr.dbDataType = pr.dbDataType; } else { AsyncWriteLine(errorMessage); } break; // end of excelOrCsv } Cursor.Current = Cursors.Default; switch (right) { case true: AsyncWriteLine("All right. Now you can save the project..."); AsyncEnableButton(true); SystemSounds.Exclamation.Play(); break; case false: AsyncWriteLine("Error, review the configuration."); AsyncEnableButton(false); //util.playSimpleSound(Path.Combine(util.sound_dir, "zasentodalaboca.wav")); SystemSounds.Asterisk.Play(); break; } // we have finished with new project Cursor.Current = Cursors.Default; } catch (Exception ex) { AsyncWrite(ex.Message); } }
public List<relation> getRelations(string cadconexion, string database) { MySqlConnection conexion = null; try { List<relation> lista = new List<relation>(); string sql = @"SELECT * FROM information_schema.key_column_usage where constraint_schema = '{0}' and referenced_table_name <> ''"; conexion = new MySqlConnection(cadconexion); miComando = new MySqlCommand(string.Format(sql, database)); miComando.Connection = conexion; conexion.ConnectionString = cadconexion; conexion.Open(); // System.Data.DataTable dt = new System.Data.DataTable(); miLector = miComando.ExecuteReader(); while (miLector.Read()) { relation rel = new relation(); //rel.name = sf.cadena(miLector["constraint_name"]) ; rel.name = sf.cadena(miLector["table_name"]) + "_" + sf.cadena(miLector["referenced_table_name"]); rel.childTable = sf.cadena(miLector["table_name"]); rel.childField = sf.cadena(miLector["column_name"]); rel.parentTable = sf.cadena(miLector["referenced_table_name"]); rel.parentField = sf.cadena(miLector["referenced_column_name"]); // if the name of fields its equal... if (rel.childField.ToLower().Equals(rel.parentField.ToLower())) rel.relationType = relation.typeOfRelation.hasMany; else rel.relationType = relation.typeOfRelation.hasOne; lista.Add(rel); } return lista; } catch (Exception ep) { // lo.tratarError(ep, "Error en dbClass.new", ""); return null; } finally { conexion.Close(); } }
public void Execute(ESRI.ArcGIS.esriSystem.IArray paramvalues, ESRI.ArcGIS.esriSystem.ITrackCancel TrackCancel, ESRI.ArcGIS.Geoprocessing.IGPEnvironmentManager envMgr, ESRI.ArcGIS.Geodatabase.IGPMessages message) { try { IGPUtilities3 execute_Utilities = new GPUtilitiesClass(); if (TrackCancel == null) { TrackCancel = new CancelTrackerClass(); } IGPParameter inputFeatureDatasetParameter = paramvalues.get_Element(in_featureDatasetParameterNumber) as IGPParameter; IGPValue inputFeatureDatasetGPValue = execute_Utilities.UnpackGPValue(inputFeatureDatasetParameter); IGPValue outputOSMFileGPValue = execute_Utilities.UnpackGPValue(paramvalues.get_Element(out_osmFileLocationParameterNumber)); // get the name of the feature dataset int fdDemlimiterPosition = inputFeatureDatasetGPValue.GetAsText().LastIndexOf("\\"); string nameOfFeatureDataset = inputFeatureDatasetGPValue.GetAsText().Substring(fdDemlimiterPosition + 1); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; System.Xml.XmlWriter xmlWriter = null; try { xmlWriter = XmlWriter.Create(outputOSMFileGPValue.GetAsText(), settings); } catch (Exception ex) { message.AddError(120021, ex.Message); return; } xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("osm"); // start the osm root node xmlWriter.WriteAttributeString("version", "0.6"); // add the version attribute xmlWriter.WriteAttributeString("generator", "ArcGIS Editor for OpenStreetMap"); // add the generator attribute // write all the nodes // use a feature search cursor to loop through all the known points and write them out as osm node IFeatureClassContainer osmFeatureClasses = execute_Utilities.OpenDataset(inputFeatureDatasetGPValue) as IFeatureClassContainer; if (osmFeatureClasses == null) { message.AddError(120022, string.Format(resourceManager.GetString("GPTools_NullPointerParameterType"), inputFeatureDatasetParameter.Name)); return; } IFeatureClass osmPointFeatureClass = osmFeatureClasses.get_ClassByName(nameOfFeatureDataset + "_osm_pt"); if (osmPointFeatureClass == null) { message.AddError(120023, string.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_no_pointfeatureclass"), nameOfFeatureDataset + "_osm_pt")); return; } // check the extension of the point feature class to determine its version int internalOSMExtensionVersion = osmPointFeatureClass.OSMExtensionVersion(); IFeatureCursor searchCursor = null; System.Xml.Serialization.XmlSerializerNamespaces xmlnsEmpty = new System.Xml.Serialization.XmlSerializerNamespaces(); xmlnsEmpty.Add("", ""); message.AddMessage(resourceManager.GetString("GPTools_OSMGPExport2OSM_exporting_pts_msg")); int pointCounter = 0; string nodesExportedMessage = String.Empty; // collect the indices for the point feature class once int pointOSMIDFieldIndex = osmPointFeatureClass.Fields.FindField("OSMID"); int pointChangesetFieldIndex = osmPointFeatureClass.Fields.FindField("osmchangeset"); int pointVersionFieldIndex = osmPointFeatureClass.Fields.FindField("osmversion"); int pointUIDFieldIndex = osmPointFeatureClass.Fields.FindField("osmuid"); int pointUserFieldIndex = osmPointFeatureClass.Fields.FindField("osmuser"); int pointTimeStampFieldIndex = osmPointFeatureClass.Fields.FindField("osmtimestamp"); int pointVisibleFieldIndex = osmPointFeatureClass.Fields.FindField("osmvisible"); int pointTagsFieldIndex = osmPointFeatureClass.Fields.FindField("osmTags"); using (ComReleaser comReleaser = new ComReleaser()) { searchCursor = osmPointFeatureClass.Search(null, false); comReleaser.ManageLifetime(searchCursor); System.Xml.Serialization.XmlSerializer pointSerializer = new System.Xml.Serialization.XmlSerializer(typeof(node)); IFeature currentFeature = searchCursor.NextFeature(); IWorkspace pointWorkspace = ((IDataset)osmPointFeatureClass).Workspace; while (currentFeature != null) { if (TrackCancel.Continue() == true) { // convert the found point feature into a osm node representation to store into the OSM XML file node osmNode = ConvertPointFeatureToOSMNode(currentFeature, pointWorkspace, pointTagsFieldIndex, pointOSMIDFieldIndex, pointChangesetFieldIndex, pointVersionFieldIndex, pointUIDFieldIndex, pointUserFieldIndex, pointTimeStampFieldIndex, pointVisibleFieldIndex, internalOSMExtensionVersion); pointSerializer.Serialize(xmlWriter, osmNode, xmlnsEmpty); // increase the point counter to later status report pointCounter++; currentFeature = searchCursor.NextFeature(); } else { // properly close the document xmlWriter.WriteEndElement(); // closing the osm root element xmlWriter.WriteEndDocument(); // finishing the document xmlWriter.Close(); // closing the document // report the number of elements loader so far nodesExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_pts_exported_msg"), pointCounter); message.AddMessage(nodesExportedMessage); return; } } } nodesExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_pts_exported_msg"), pointCounter); message.AddMessage(nodesExportedMessage); // next loop through the line and polygon feature classes to export those features as ways // in case we encounter a multi-part geometry, store it in a relation collection that will be serialized when exporting the relations table IFeatureClass osmLineFeatureClass = osmFeatureClasses.get_ClassByName(nameOfFeatureDataset + "_osm_ln"); if (osmLineFeatureClass == null) { message.AddError(120023, string.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_no_linefeatureclass"), nameOfFeatureDataset + "_osm_ln")); return; } message.AddMessage(resourceManager.GetString("GPTools_OSMGPExport2OSM_exporting_ways_msg")); // as we are looping through the line and polygon feature classes let's collect the multi-part features separately // as they are considered relations in the OSM world List<relation> multiPartElements = new List<relation>(); System.Xml.Serialization.XmlSerializer waySerializer = new System.Xml.Serialization.XmlSerializer(typeof(way)); int lineCounter = 0; int relationCounter = 0; string waysExportedMessage = String.Empty; using (ComReleaser comReleaser = new ComReleaser()) { searchCursor = osmLineFeatureClass.Search(null, false); comReleaser.ManageLifetime(searchCursor); IFeature currentFeature = searchCursor.NextFeature(); // collect the indices for the point feature class once int lineOSMIDFieldIndex = osmLineFeatureClass.Fields.FindField("OSMID"); int lineChangesetFieldIndex = osmLineFeatureClass.Fields.FindField("osmchangeset"); int lineVersionFieldIndex = osmLineFeatureClass.Fields.FindField("osmversion"); int lineUIDFieldIndex = osmLineFeatureClass.Fields.FindField("osmuid"); int lineUserFieldIndex = osmLineFeatureClass.Fields.FindField("osmuser"); int lineTimeStampFieldIndex = osmLineFeatureClass.Fields.FindField("osmtimestamp"); int lineVisibleFieldIndex = osmLineFeatureClass.Fields.FindField("osmvisible"); int lineTagsFieldIndex = osmLineFeatureClass.Fields.FindField("osmTags"); int lineMembersFieldIndex = osmLineFeatureClass.Fields.FindField("osmMembers"); IWorkspace lineWorkspace = ((IDataset)osmLineFeatureClass).Workspace; while (currentFeature != null) { if (TrackCancel.Continue() == false) { // properly close the document xmlWriter.WriteEndElement(); // closing the osm root element xmlWriter.WriteEndDocument(); // finishing the document xmlWriter.Close(); // closing the document // report the number of elements loaded so far waysExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_ways_exported_msg"), lineCounter); message.AddMessage(waysExportedMessage); return; } //test if the feature geometry has multiple parts IGeometryCollection geometryCollection = currentFeature.Shape as IGeometryCollection; if (geometryCollection != null) { if (geometryCollection.GeometryCount == 1) { // convert the found polyline feature into a osm way representation to store into the OSM XML file way osmWay = ConvertFeatureToOSMWay(currentFeature, lineWorkspace, osmPointFeatureClass, pointOSMIDFieldIndex, lineTagsFieldIndex, lineOSMIDFieldIndex, lineChangesetFieldIndex, lineVersionFieldIndex, lineUIDFieldIndex, lineUserFieldIndex, lineTimeStampFieldIndex, lineVisibleFieldIndex, internalOSMExtensionVersion); waySerializer.Serialize(xmlWriter, osmWay, xmlnsEmpty); // increase the line counter for later status report lineCounter++; } else { relation osmRelation = ConvertRowToOSMRelation((IRow)currentFeature, lineWorkspace, lineTagsFieldIndex, lineOSMIDFieldIndex, lineChangesetFieldIndex, lineVersionFieldIndex, lineUIDFieldIndex, lineUserFieldIndex, lineTimeStampFieldIndex, lineVisibleFieldIndex, lineMembersFieldIndex, internalOSMExtensionVersion); multiPartElements.Add(osmRelation); // increase the line counter for later status report relationCounter++; } } currentFeature = searchCursor.NextFeature(); } } IFeatureClass osmPolygonFeatureClass = osmFeatureClasses.get_ClassByName(nameOfFeatureDataset + "_osm_ply"); IFeatureWorkspace commonWorkspace = ((IDataset)osmPolygonFeatureClass).Workspace as IFeatureWorkspace; if (osmPolygonFeatureClass == null) { message.AddError(120024, string.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_no_polygonfeatureclass"), nameOfFeatureDataset + "_osm_ply")); return; } using (ComReleaser comReleaser = new ComReleaser()) { searchCursor = osmPolygonFeatureClass.Search(null, false); comReleaser.ManageLifetime(searchCursor); IFeature currentFeature = searchCursor.NextFeature(); // collect the indices for the point feature class once int polygonOSMIDFieldIndex = osmPolygonFeatureClass.Fields.FindField("OSMID"); int polygonChangesetFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmchangeset"); int polygonVersionFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmversion"); int polygonUIDFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmuid"); int polygonUserFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmuser"); int polygonTimeStampFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmtimestamp"); int polygonVisibleFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmvisible"); int polygonTagsFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmTags"); int polygonMembersFieldIndex = osmPolygonFeatureClass.Fields.FindField("osmMembers"); IWorkspace polygonWorkspace = ((IDataset)osmPolygonFeatureClass).Workspace; while (currentFeature != null) { if (TrackCancel.Continue() == false) { // properly close the document xmlWriter.WriteEndElement(); // closing the osm root element xmlWriter.WriteEndDocument(); // finishing the document xmlWriter.Close(); // closing the document // report the number of elements loaded so far waysExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_ways_exported_msg"), lineCounter); message.AddMessage(waysExportedMessage); message.AddAbort(resourceManager.GetString("GPTools_toolabort")); return; } //test if the feature geometry has multiple parts IGeometryCollection geometryCollection = currentFeature.Shape as IGeometryCollection; if (geometryCollection != null) { if (geometryCollection.GeometryCount == 1) { // convert the found polyline feature into a osm way representation to store into the OSM XML file way osmWay = ConvertFeatureToOSMWay(currentFeature, polygonWorkspace, osmPointFeatureClass, pointOSMIDFieldIndex, polygonTagsFieldIndex, polygonOSMIDFieldIndex, polygonChangesetFieldIndex, polygonVersionFieldIndex, polygonUIDFieldIndex, polygonUserFieldIndex, polygonTimeStampFieldIndex, polygonVisibleFieldIndex, internalOSMExtensionVersion); waySerializer.Serialize(xmlWriter, osmWay, xmlnsEmpty); // increase the line counter for later status report lineCounter++; } else { relation osmRelation = ConvertRowToOSMRelation((IRow)currentFeature, polygonWorkspace, polygonTagsFieldIndex, polygonOSMIDFieldIndex, polygonChangesetFieldIndex, polygonVersionFieldIndex, polygonUIDFieldIndex, polygonUserFieldIndex, polygonTimeStampFieldIndex, polygonVisibleFieldIndex, polygonMembersFieldIndex, internalOSMExtensionVersion); multiPartElements.Add(osmRelation); // increase the line counter for later status report relationCounter++; } } currentFeature = searchCursor.NextFeature(); } } waysExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_ways_exported_msg"), lineCounter); message.AddMessage(waysExportedMessage); // now let's go through the relation table message.AddMessage(resourceManager.GetString("GPTools_OSMGPExport2OSM_exporting_relations_msg")); ITable relationTable = commonWorkspace.OpenTable(nameOfFeatureDataset + "_osm_relation"); if (relationTable == null) { message.AddError(120025, String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_no_relationTable"), nameOfFeatureDataset + "_osm_relation")); return; } System.Xml.Serialization.XmlSerializer relationSerializer = new System.Xml.Serialization.XmlSerializer(typeof(relation)); string relationsExportedMessage = String.Empty; using (ComReleaser comReleaser = new ComReleaser()) { ICursor rowCursor = relationTable.Search(null, false); comReleaser.ManageLifetime(rowCursor); IRow currentRow = rowCursor.NextRow(); // collect the indices for the relation table once int relationOSMIDFieldIndex = relationTable.Fields.FindField("OSMID"); int relationChangesetFieldIndex = relationTable.Fields.FindField("osmchangeset"); int relationVersionFieldIndex = relationTable.Fields.FindField("osmversion"); int relationUIDFieldIndex = relationTable.Fields.FindField("osmuid"); int relationUserFieldIndex = relationTable.Fields.FindField("osmuser"); int relationTimeStampFieldIndex = relationTable.Fields.FindField("osmtimestamp"); int relationVisibleFieldIndex = relationTable.Fields.FindField("osmvisible"); int relationTagsFieldIndex = relationTable.Fields.FindField("osmTags"); int relationMembersFieldIndex = relationTable.Fields.FindField("osmMembers"); IWorkspace polygonWorkspace = ((IDataset)osmPolygonFeatureClass).Workspace; while (currentRow != null) { if (TrackCancel.Continue() == false) { // properly close the document xmlWriter.WriteEndElement(); // closing the osm root element xmlWriter.WriteEndDocument(); // finishing the document xmlWriter.Close(); // closing the document // report the number of elements loaded so far relationsExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_relations_exported_msg"), relationCounter); message.AddMessage(relationsExportedMessage); message.AddAbort(resourceManager.GetString("GPTools_toolabort")); return; } relation osmRelation = ConvertRowToOSMRelation(currentRow, (IWorkspace)commonWorkspace, relationTagsFieldIndex, relationOSMIDFieldIndex, relationChangesetFieldIndex, relationVersionFieldIndex, relationUIDFieldIndex, relationUserFieldIndex, relationTimeStampFieldIndex, relationVisibleFieldIndex, relationMembersFieldIndex, internalOSMExtensionVersion); relationSerializer.Serialize(xmlWriter, osmRelation, xmlnsEmpty); // increase the line counter for later status report relationCounter++; currentRow = rowCursor.NextRow(); } } // lastly let's serialize the collected multipart-geometries back into relation elements foreach (relation currentRelation in multiPartElements) { if (TrackCancel.Continue() == false) { // properly close the document xmlWriter.WriteEndElement(); // closing the osm root element xmlWriter.WriteEndDocument(); // finishing the document xmlWriter.Close(); // closing the document // report the number of elements loaded so far relationsExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_relations_exported_msg"), relationCounter); message.AddMessage(relationsExportedMessage); return; } relationSerializer.Serialize(xmlWriter, currentRelation, xmlnsEmpty); relationCounter++; } relationsExportedMessage = String.Format(resourceManager.GetString("GPTools_OSMGPExport2OSM_relations_exported_msg"), relationCounter); message.AddMessage(relationsExportedMessage); xmlWriter.WriteEndElement(); // closing the osm root element xmlWriter.WriteEndDocument(); // finishing the document xmlWriter.Close(); // closing the document } catch (Exception ex) { message.AddError(11111, ex.StackTrace); message.AddError(120026, ex.Message); } }
private relation ConvertRowToOSMRelation(IRow currentRow, IWorkspace featureWorkspace, int tagsFieldIndex, int osmIDFieldIndex, int changesetIDFieldIndex, int osmVersionFieldIndex, int userIDFieldIndex, int userNameFieldIndex, int timeStampFieldIndex, int visibleFieldIndex, int membersFieldIndex, int extensionVersion) { if (currentRow == null) throw new ArgumentNullException("currentRow"); relation osmRelation = new relation(); object featureValue = DBNull.Value; List<object> relationItems = new List<object>(); if (membersFieldIndex != -1) { member[] members = _osmUtility.retrieveMembers(currentRow, membersFieldIndex); relationItems.AddRange(members); } if (osmIDFieldIndex != -1) { osmRelation.id = Convert.ToString(currentRow.get_Value(osmIDFieldIndex)); } if (changesetIDFieldIndex != -1) { featureValue = currentRow.get_Value(changesetIDFieldIndex); if (featureValue != DBNull.Value) { osmRelation.changeset = Convert.ToString(currentRow.get_Value(changesetIDFieldIndex)); } } if (osmVersionFieldIndex != -1) { featureValue = currentRow.get_Value(osmVersionFieldIndex); if (featureValue != DBNull.Value) { osmRelation.version = Convert.ToString(featureValue); } } if (userIDFieldIndex != -1) { featureValue = currentRow.get_Value(userIDFieldIndex); if (featureValue != DBNull.Value) { osmRelation.uid = Convert.ToString(featureValue); } } if (userNameFieldIndex != -1) { featureValue = currentRow.get_Value(userNameFieldIndex); if (featureValue != DBNull.Value) { osmRelation.user = Convert.ToString(featureValue); } } if (timeStampFieldIndex != -1) { featureValue = currentRow.get_Value(timeStampFieldIndex); if (featureValue != DBNull.Value) { osmRelation.timestamp = Convert.ToDateTime(featureValue).ToUniversalTime().ToString("u"); } } if (visibleFieldIndex != -1) { featureValue = currentRow.get_Value(visibleFieldIndex); if (featureValue != DBNull.Value) { osmRelation.visible = Convert.ToString(featureValue); } } if (tagsFieldIndex > -1) { tag[] tags = null; tags = _osmUtility.retrieveOSMTags((IRow)currentRow, tagsFieldIndex, featureWorkspace); //// if the row is of type IFeature and a polygon then add the type=multipolygon tag //if (currentRow is IFeature) //{ // IFeature currentFeature = currentRow as IFeature; // if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon) // { // tag mpTag = new tag(); // mpTag.k = "type"; // mpTag.v = "multipolygon"; // relationItems.Add(mpTag); // } //} if (tags.Length != 0) { relationItems.AddRange(tags); } } // add all items (member and tags) to the relation element osmRelation.Items = relationItems.ToArray(); return osmRelation; }
void ProductReverseAdd() { string detailid = ""; int lastAdd = lProidOld.Count - 1; int count = lProidOld.Where(q => q.ProductId == lProidOld[lastAdd].ProductId).Count(); if (count > 2) { #region if more than one SalePosReverseDialog dig = new SalePosReverseDialog(); int cnt = 0; for (int i = 0; i < dataGridView1.Rows.Count; ++i) { if (dataGridView1.Rows[i].Cells[1].Value.ToString() == dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value.ToString() && cnt < count - 1) { cnt++; List<object> str = new List<object>(); for (int c = 0; c < dataGridView1.Columns.Count; ++c) { str.Add(dataGridView1.Rows[i].Cells[c].Value); } dig.AddRow(str.ToArray()); } } dig.ShowDialog(); if (dig.dataGridView1.SelectedRows.Count > 0) { detailid = dig.GetDetailId; } #endregion } for (int idx = 0; idx <= lastAdd - 1; ++idx) { if (lProidOld[idx].ProductId == lProidOld[lastAdd].ProductId || lProidOld[idx].DetailId == detailid) { relation r = new relation(); r.detailId = lProidOld[idx].DetailId; r.detailIdReturn = lProidOld[lastAdd].DetailId; r.qtyPack = lProidOld[idx].QuantityPack.ToDouble(); r.qty = lProidOld[idx].Quantity.ToDouble(); r.price = lProidOld[idx].price.ToDecimal(); irelation.Add(r); lProidOld[lastAdd].QuantityPack = "-" + lProidOld[idx].QuantityPack; lProidOld[lastAdd].Quantity = "-" + lProidOld[idx].Quantity; dataGridView1.Rows[lastAdd].Cells[3].Value = dataGridView1.Rows[idx].Cells[3].Value == "" || dataGridView1.Rows[idx].Cells[3].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[3].Value : "-" + dataGridView1.Rows[idx].Cells[3].Value; dataGridView1.Rows[lastAdd].Cells[5].Value = dataGridView1.Rows[idx].Cells[5].Value == "" || dataGridView1.Rows[idx].Cells[5].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[5].Value : "-" + dataGridView1.Rows[idx].Cells[5].Value; dataGridView1.Rows[lastAdd].Cells[7].Value = dataGridView1.Rows[idx].Cells[7].Value == "" || dataGridView1.Rows[idx].Cells[7].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[7].Value : "-" + dataGridView1.Rows[idx].Cells[7].Value; dataGridView1.Rows[lastAdd].Cells[8].Value = dataGridView1.Rows[idx].Cells[8].Value == "" || dataGridView1.Rows[idx].Cells[8].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[8].Value : "-" + dataGridView1.Rows[idx].Cells[8].Value; dataGridView1.Rows[lastAdd].Cells[9].Value = dataGridView1.Rows[idx].Cells[9].Value == "" || dataGridView1.Rows[idx].Cells[9].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[9].Value : "-" + dataGridView1.Rows[idx].Cells[9].Value; dataGridView1.Rows[lastAdd].Cells[10].Value = dataGridView1.Rows[idx].Cells[10].Value == "" || dataGridView1.Rows[idx].Cells[10].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[10].Value : "-" + dataGridView1.Rows[idx].Cells[10].Value; dataGridView1.Rows[lastAdd].Cells[11].Value = dataGridView1.Rows[idx].Cells[11].Value == "" || dataGridView1.Rows[idx].Cells[11].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[11].Value : "-" + dataGridView1.Rows[idx].Cells[11].Value; dataGridView1.Rows[lastAdd].Cells[12].Value = dataGridView1.Rows[idx].Cells[12].Value == "" || dataGridView1.Rows[idx].Cells[12].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[12].Value : "-" + dataGridView1.Rows[idx].Cells[12].Value; dataGridView1.Rows[lastAdd].Cells[14].Value = dataGridView1.Rows[idx].Cells[14].Value == "" || dataGridView1.Rows[idx].Cells[14].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[14].Value : "-" + dataGridView1.Rows[idx].Cells[14].Value; dataGridView1.Rows[lastAdd].Cells[15].Value = dataGridView1.Rows[idx].Cells[15].Value == "" || dataGridView1.Rows[idx].Cells[15].Value.ToDouble() == 0 ? dataGridView1.Rows[idx].Cells[15].Value : "-" + dataGridView1.Rows[idx].Cells[15].Value; txtMsgForDelete.Visible = false; setCalulate(); } } if (txtMsgForDelete.Visible) MessageBox.Show("ไม่พบรายที่เลือก"); }
public Relation(string a, string b, relation relationBetweenWords) { this.a = a; this.b = b; this.relationBetweenWords = relationBetweenWords; }
public override void AddRelation(Relation simpleRelation) { relation relation1 = new relation(); relation1.idSpecified = false; long?nullable; if (simpleRelation.Id.HasValue) { relation1.idSpecified = true; relation relation2 = relation1; nullable = simpleRelation.Id; long num = nullable.Value; relation2.id = num; } relation1.changesetSpecified = false; nullable = simpleRelation.ChangeSetId; if (nullable.HasValue) { relation relation2 = relation1; nullable = simpleRelation.ChangeSetId; long num = nullable.Value; relation2.changeset = num; relation1.changesetSpecified = true; } relation1.visibleSpecified = false; if (simpleRelation.Visible.HasValue) { relation1.visible = simpleRelation.Visible.Value; relation1.visibleSpecified = true; } relation1.timestampSpecified = false; if (simpleRelation.TimeStamp.HasValue) { relation1.timestamp = simpleRelation.TimeStamp.Value; relation1.timestampSpecified = true; } relation1.uidSpecified = false; nullable = simpleRelation.UserId; if (nullable.HasValue) { relation relation2 = relation1; nullable = simpleRelation.UserId; long num = nullable.Value; relation2.uid = num; relation1.uidSpecified = true; } relation1.user = simpleRelation.UserName; relation1.tag = this.ConvertToXmlTags(simpleRelation.Tags); if (simpleRelation.Members != null) { relation1.member = new member[simpleRelation.Members.Count]; for (int index = 0; index < simpleRelation.Members.Count; ++index) { member member1 = new member(); RelationMember member2 = simpleRelation.Members[index]; member1.refSpecified = false; nullable = member2.MemberId; if (nullable.HasValue) { member member3 = member1; nullable = member2.MemberId; long num = nullable.Value; member3.@ref = num; member1.refSpecified = true; } member1.typeSpecified = false; if (member2.MemberType.HasValue) { switch (member2.MemberType.Value) { case OsmGeoType.Node: member1.type = memberType.node; break; case OsmGeoType.Way: member1.type = memberType.way; break; case OsmGeoType.Relation: member1.type = memberType.relation; break; } member1.typeSpecified = true; } member1.role = member2.MemberRole; relation1.member[index] = member1; } } if (simpleRelation.Version.HasValue) { relation1.version = simpleRelation.Version.Value; relation1.versionSpecified = true; } XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); MemoryStream memoryStream = new MemoryStream(); XmlWriterSettings settings = this._settings; XmlWriter xmlWriter = XmlWriter.Create((Stream)memoryStream, settings); new XmlSerializer(typeof(relation), string.Empty).Serialize(xmlWriter, (object)relation1, namespaces); Stream stream = this._stream; memoryStream.WriteTo(stream); this._stream.Flush(); this._streamWriter.WriteLine(); this._streamWriter.Flush(); }
public fact(pair p = default, relation r = default) { this.p = p; this.r = r; }
public PSObject AdaptRelationObject(Cmdlet myCmdlet, relation[] relObjects,string domain) { var promotedObject = new PSObject(relObjects); promotedObject.TypeNames.Insert(1, relObjects.GetType().FullName); promotedObject.TypeNames[0] = String.Format(CultureInfo.CurrentCulture, "RelationObject#{0}",domain); return promotedObject; }
protected override void ProcessRecord() { base.BeginProcessing(); try { var rel = new relation {domainName = _name, card1Id = SourceId, card2Id = TargetId}; var rval = _clientconnection.createRelation(rel); WriteObject(rval); } catch (Exception e) { WriteError(new ErrorRecord(e, "Unknown error", ErrorCategory.NotSpecified, _name)); } }
public List<relation> getRelations(string cadconexion, string table) { SqlConnection conexion = null; try { List<relation> lista = new List<relation>(); conexion = new SqlConnection(cadconexion); miComando = new SqlCommand(""); miComando.Connection = conexion; conexion.ConnectionString = cadconexion; conexion.Open(); System.Data.DataTable dt = new System.Data.DataTable(); dt = conexion.GetSchema(SqlClientMetaDataCollectionNames.ForeignKeys, new String[] { null, null, table, null }); foreach (System.Data.DataRow row in dt.Rows) { relation rel = new relation(); // rel.name = sf.cadena(row["FK_NAME"]); // descripcion = schemaTable.Rows(i)("PK_NAME").ToString //tablaPadre = schemaTable.Rows(i)("PK_TABLE_NAME").ToString //campoPadre = schemaTable.Rows(i)("PK_COLUMN_NAME").ToString //tablaHijo = schemaTable.Rows(i)("FK_TABLE_NAME").ToString //campoHijo = schemaTable.Rows(i)("FK_COLUMN_NAME").ToString //If schemaTable.Rows(i)("UPDATE_RULE").ToString.IndexOf("CASCADE") <> -1 Then // update = True //End If //If schemaTable.Rows(i)("DELETE_RULE").ToString.IndexOf("CASCADE") <> -1 Then // delete = True //End If lista.Add(rel); } return lista; } catch (Exception ep) { // lo.tratarError(ep, "Error en dbClass.new", ""); return null; } finally { conexion.Close(); } }
// get all relations for project public List<relation> getRelations(string cadconexion) { SqlConnection conexion = null; try { List<relation> lista = new List<relation>(); String sql = @"SELECT tablesA.name AS ParentTable, columnsA.name AS ParentPK, tablesB.name AS ReferencedTable, columnsB.name AS ReferencedFK FROM sys.foreign_key_columns INNER JOIN sys.columns AS columnsA ON sys.foreign_key_columns.parent_object_id = columnsA.object_id AND sys.foreign_key_columns.parent_column_id = columnsA.column_id INNER JOIN sys.columns AS columnsB ON sys.foreign_key_columns.referenced_object_id = columnsB.object_id AND sys.foreign_key_columns.referenced_column_id = columnsB.column_id INNER JOIN sys.tables AS tablesA ON sys.foreign_key_columns.parent_object_id = tablesA.object_id INNER JOIN sys.tables AS tablesB ON sys.foreign_key_columns.referenced_object_id = tablesB.object_id "; conexion = new SqlConnection(cadconexion); miComando = new SqlCommand(sql); miComando.Connection = conexion; conexion.ConnectionString = cadconexion; conexion.Open(); // System.Data.DataTable dt = new System.Data.DataTable(); miLector = miComando.ExecuteReader(); while (miLector.Read()) { relation rel = new relation(); rel.name = sf.cadena(miLector["ParentTable"]) + "_" + sf.cadena(miLector["ReferencedTable"]); rel.parentTable = sf.cadena(miLector["ParentTable"]); rel.parentField = sf.cadena(miLector["ParentPK"]); rel.childTable = sf.cadena(miLector["ReferencedTable"]); rel.childField = sf.cadena(miLector["ReferencedFK"]); // descripcion = schemaTable.Rows(i)("PK_NAME").ToString //tablaPadre = schemaTable.Rows(i)("PK_TABLE_NAME").ToString //campoPadre = schemaTable.Rows(i)("PK_COLUMN_NAME").ToString //tablaHijo = schemaTable.Rows(i)("FK_TABLE_NAME").ToString //campoHijo = schemaTable.Rows(i)("FK_COLUMN_NAME").ToString //If schemaTable.Rows(i)("UPDATE_RULE").ToString.IndexOf("CASCADE") <> -1 Then // update = True //End If //If schemaTable.Rows(i)("DELETE_RULE").ToString.IndexOf("CASCADE") <> -1 Then // delete = True //End If // if the name of fields its equal... if (rel.childField.ToLower().Equals(rel.parentField.ToLower())) rel.relationType = relation.typeOfRelation.hasMany; else rel.relationType = relation.typeOfRelation.hasOne; lista.Add(rel); } return lista; } catch (Exception ep) { // lo.tratarError(ep, "Error en dbClass.new", ""); return null; } finally { conexion.Close(); } }