Пример #1
0
        public void Should_ConvertPersonObject_ToString()
        {
            Person person = new Person();
            Parser parser = new Parser();

            person.Id = 1;
            person.CityId = 8;
            person.FIO = "Ivanov Petr Olegovich";
            string res = parser.AddPersonEncode(person);
            Assert.AreEqual(res,"#12#1#8#Ivanov Petr Olegovich");
        }
Пример #2
0
        public string SendPerson()
        {
            Person person = new Person();
            DBActions dbActions = new DBActions();
            string msg = "";
            string table = "People";
            int lastId = dbActions.LastId(table);

            person = dbActions.GetPerson(lastId);
            msg = dbActions.PersonAdd(person);
            string delRes = dbActions.DeleteLocal(lastId, table);
            if (delRes != Resources.Success)
            {
                msg = string.Concat("Deletion from local DB failed: ", delRes);
            }
            DBActions.CheckPeopleEmptiness();
            return msg;
        }
Пример #3
0
        private void AddPeopleButton_Click(object sender, EventArgs e)
        {
            InputSanitizer  inputSanitizer = new InputSanitizer();
            Person addedPerson = new Person();
            addedPerson.FIO = inputSanitizer.Names(FIOTextBox.Text);
            try
            {
                addedPerson.CityId = Convert.ToInt32(inputSanitizer.DigitsOnly(CityIDTextBox.Text));
                DBActions dbActions = new DBActions();
                string res = dbActions.PersonAdd(addedPerson);
                MessageBox.Show(res, "Client message");
            }

            catch (Exception ex)
            {
                MessageBox.Show(Resources.IdIncorrect + ex.Message);
            }
        }
        private void ChangePersonButton_Click(object sender, EventArgs e)
        {
            Person changedPerson = new Person();
            DBActions dbActions = new DBActions();
            InputSanitizer inputSanitizer = new InputSanitizer();

            try
            {
                changedPerson.Id = Convert.ToInt32(inputSanitizer.DigitsOnly(IDTexbBox.Text));
                changedPerson.CityId = Convert.ToInt32(inputSanitizer.DigitsOnly(CityIDTextBox.Text));
                changedPerson.FIO = inputSanitizer.Names(FIOTextBox.Text);
                string msg = dbActions.PersonEdit(changedPerson);
                MessageBox.Show(msg, "Client message");
            }
            catch(Exception ex)
            {
                MessageBox.Show(Resources.IdIncorrect + ex.Message);
            }
        }
Пример #5
0
 public string PersonEdit(Person changedPerson)
 {
     string msg = "";
     if (ConnectionCheck())
     {
         msg = connectionEstablisherClient.MakeConnect(parser.EditPersonEncode(changedPerson),goodIP);
     }
     else
     {
         msg = Resources.NoConnectionToServer;
     }
     return msg;
 }
Пример #6
0
        public string PersonAdd(Person addedPerson)
        {
            string msg = "";
            if (ConnectionCheck())
            {
                msg = connectionEstablisherClient.MakeConnect(parser.AddPersonEncode(addedPerson),goodIP);
            }
            else
            {
                using (OleDbConnection localConn = new OleDbConnection(ConnString))
                {
                    string sql = "insert into People(Id, CityId, FIO) values (?,?,?)";
                    int newID = LastId("People") + 1;

                    using (OleDbCommand command = new OleDbCommand(sql, localConn))
                    {
                        localConn.Open();
                        command.Parameters.AddWithValue("Id", newID);
                        command.Parameters.AddWithValue("CityId", addedPerson.CityId.ToString());
                        command.Parameters.AddWithValue("FIO", addedPerson.FIO);
                        command.ExecuteNonQuery();
                        newID++;
                        msg = Resources.Success;
                    }
                }
            }
            return msg;
        }
Пример #7
0
        public Person GetPerson(int id)
        {
            Person person = new Person();
            string sql = "select top 1 Id, CityId, Fio from People 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())
                        {
                            person.Id = (int) dataReader[0];
                            person.CityId = (int) dataReader[1];
                            person.FIO = (string) dataReader[2];
                        }
                    }
                }
            }
            return person;
        }
Пример #8
0
 public string EditPersonEncode(Person person)
 {
     string ret = string.Concat("#13#", person.Id.ToString(), delimiter, person.CityId.ToString(), delimiter, person.FIO);
     return ret;
 }