Esempio n. 1
0
 internal bool AddPerson(Person addedPerson)
 {
     string personAddSQL = @"insert into People (CityId, FIO) values (?,?)";
     try
     {
         using (SqlConnection connection = new SqlConnection(SQLConnStr))
         {
             using (SqlCommand command = new SqlCommand(personAddSQL,connection))
             {
                 connection.Open();
                 command.Parameters.AddWithValue("CityId", addedPerson.CityId);
                 command.Parameters.AddWithValue("FIO", addedPerson.FIO);
                 command.ExecuteNonQuery();
             }
         }
         return true;
     }
     catch (SqlException ex)
     {
         Console.WriteLine(ex.Message);
         return false;
     }
 }
Esempio n. 2
0
 internal bool EditPerson(int id, Person changedPerson)
 {
     string personEditSQL = string.Concat("update People set CityId=@CityId, FIO=@FIO where Id=",id.ToString());
     try
     {
         using (SqlConnection connection = new SqlConnection(SQLConnStr))
         {
             using (SqlCommand command = new SqlCommand(personEditSQL,connection))
             {
                 connection.Open();
                 command.Parameters.AddWithValue("@CityId", changedPerson.CityId);
                 command.Parameters.AddWithValue("@FIO", changedPerson.FIO);
                 command.ExecuteNonQuery();
             }
         }
         return true;
     }
     catch (SqlException ex)
     {
         Console.WriteLine(ex.Message);
         return false;
     }
 }
 public Person DecodePerson(string personInput)
 {
     Person person = new Person();
     string[] personInputSplit = personInput.Split(delimiter);
     person.Id = Convert.ToInt32(personInputSplit[2]);
     person.CityId = Convert.ToInt32(personInputSplit[3]);
     person.FIO = personInputSplit[4];
     return person;
 }