/// <summary> /// Load information about IC into person's object /// </summary> /// <param name="tempPerson">Object representing person</param> /// <returns>Object representing person with icInfo loaded</returns> public Person SelectIc(Person tempPerson) { //database command for inserting adress into database in string form string query = "Select * FROM IcInfo where PersonID = @PersonID"; SqlConnection connect = new SqlConnection(connectionString); SqlDataReader reader; try { connect.Open(); SqlCommand cmd = new SqlCommand(query, connect); //creating sql command cmd.Parameters.AddWithValue("@PersonID", tempPerson.PersonID); //entering variables represented in command string by @value reader = cmd.ExecuteReader(); //executing command while (reader.Read()) { ICO tempIc = new ICO(reader[1].ToString(), reader[2].ToString(), reader[3].ToString()); tempPerson.ICInfo = tempIc; } } catch (Exception exp) { throw exp; } finally { connect.Close(); } return(tempPerson); }
/// <summary> /// Loading info about company from identification number /// </summary> /// <param name="tempPerson"></param> /// <returns></returns> public Person loadIcInfo(Person tempPerson) { if (tempPerson.IC != 0) { string uri = "http://wwwinfo.mfcr.cz/cgi-bin/ares/darv_std.cgi?ico=" + tempPerson.IC; //creating request XmlTextReader reader = new XmlTextReader(uri); //request reader.MoveToContent(); //moving to content string companyName = ""; string dateCreated = ""; string dateValid = ""; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (reader.Name == "are:Datum_vzniku") //Date of company creating { XElement el = XNode.ReadFrom(reader) as XElement; dateCreated = el.Value; } if (reader.Name == "are:Datum_platnosti")//Date of IC validity { XElement el = XNode.ReadFrom(reader) as XElement; dateValid = el.Value; } if (reader.Name == "are:Obchodni_firma") //Name of Company { XElement el = XNode.ReadFrom(reader) as XElement; companyName = el.Value; break; } } } ICO tempIco = new ICO(dateCreated, dateValid, companyName); //creating ico Object tempPerson.ICInfo = tempIco; } else { ICO tempIco = new ICO("", "", ""); //if we are unable to download XML file with information, everything is set to emtpy string tempPerson.ICInfo = tempIco; //setting icinfo object into Person object } return(tempPerson); }