public string AddCity(City addedCity) { string msg = ""; if (ConnectionCheck()) { msg = connectionEstablisherClient.MakeConnect(parser.AddCityEncode(addedCity),goodIP); } else { using (OleDbConnection localConn = new OleDbConnection(ConnString)) { string sql = "insert into Cities(Id, CityName, Region, Country, Attribute) values (?,?,?,?,?)"; int newID = LastId("Cities") + 1; using (OleDbCommand command = new OleDbCommand(sql,localConn)) { localConn.Open(); command.Parameters.AddWithValue("Id", newID); command.Parameters.AddWithValue("CityName", addedCity.Name); command.Parameters.AddWithValue("Region", addedCity.Region); command.Parameters.AddWithValue("Country", addedCity.Country); command.Parameters.AddWithValue("Attribute", addedCity.Attrib); command.ExecuteNonQuery(); newID++; msg = Resources.Success; } } } return msg; }
public void Should_ConvertCityObject_ToString() { City city = new City(); city.Id = 0; city.Name = "Donetsk"; city.Region = "Don"; city.Country = "UA"; city.Attrib = false; Parser parser = new Parser(); string res = parser.AddCityEncode(city); Assert.AreEqual(res,"#02#0#Donetsk#Don#UA#False"); }
private void AddCityButtonClick(object sender, EventArgs e) { City addedCity = new City(); InputSanitizer inputSanitizer = new InputSanitizer(); addedCity.Name = inputSanitizer.Names(CityTextBox.Text); addedCity.Region = inputSanitizer.Names(RegionTextBox.Text); addedCity.Country = inputSanitizer.Names(CountryTextBox.Text); addedCity.Attrib = AttributeCheckbox.Checked; DBActions dbAct = new DBActions(); string msg = dbAct.AddCity(addedCity); MessageBox.Show(msg); }
public string SendCity() { City city = new City(); DBActions dbActions = new DBActions(); string msg = ""; string table = "Cities"; int lastId = dbActions.LastId(table); city = dbActions.GetCity(lastId); msg = dbActions.AddCity(city); string delRes = dbActions.DeleteLocal(lastId, table); if (delRes != Resources.Success) { msg = string.Concat("Deletion from local DB failed: ", delRes); } DBActions.CheckCitiesEmptiness(); return msg; }
private void EditButton_Click(object sender, EventArgs e) { City editedCity = new City(); DBActions dbActions = new DBActions(); InputSanitizer inputSanitizer = new InputSanitizer(); try { editedCity.Id = Convert.ToInt32(inputSanitizer.DigitsOnly(IDTextBox.Text)); editedCity.Name = inputSanitizer.Names(NameTextBox.Text); editedCity.Region = inputSanitizer.Names(RegionTextBox.Text); editedCity.Country = inputSanitizer.Names(CountryTextBox.Text); editedCity.Attrib = attribCheckBox.Checked; string msg = dbActions.EditCity(editedCity); MessageBox.Show(msg); } catch(Exception ex) { MessageBox.Show(Resources.IdIncorrect + ex.Message); } }
public City GetCity(int id) { City city = new City(); string sql = "select top 1 Id, CityName, Region, Country, Attribute from cities where id=@id"; using (OleDbConnection connection = new OleDbConnection(ConnString)) { using (OleDbCommand command = new OleDbCommand(sql, connection)) { connection.Open(); command.Parameters.AddWithValue("@id", id); using (OleDbDataReader dataReader = command.ExecuteReader()) { while (dataReader.Read()) { city.Id = (int) dataReader[0]; city.Name = (string) dataReader[1]; city.Region = (string) dataReader[2]; city.Country = (string) dataReader[3]; city.Attrib = (bool) dataReader[4]; } } } } return city; }
public string EditCity(City editedCity) { string msg = ""; if (ConnectionCheck()) { msg = connectionEstablisherClient.MakeConnect(parser.EditCityEncode(editedCity),goodIP); } else { msg = Resources.NoConnectionToServer; } return msg; }
public string EditCityEncode(City city) { string ret = string.Concat("#04#", city.Id.ToString(),delimiter, city.Name , delimiter, city.Region, delimiter, city.Country, delimiter, city.Attrib.ToString()); return ret; }