Esempio n. 1
0
        public List<turway> GetAllTurWay()
        {
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("SELECT id,idturoperator,idtype, name,  comment, agent,country FROM turway", con);
            cmd.CommandType = CommandType.Text;

            // Создать коллекцию для всех записей
            List<turway> list = new List<turway>();
            try
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    turway emp = new turway(
                    (int)reader["id"],
                    (int)reader["idturoperator"],
                    (int)reader["idtype"],
                    (string)reader["name"],
                    (string)reader["comment"],
                    (int)reader["agent"],
                    (string)reader["country"]
                    );

                    list.Add(emp);
                }
                reader.Close();
                return list;
            }
            catch
            {
                throw new ApplicationException("Ошибка данныx.");
            }
            finally
            {
                con.Close();
            }
        }
Esempio n. 2
0
        public List<turway> GetAllTurWayInGroup(int turgroup)
        {
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("SELECT id,idturoperator,idtype, name,  comment, agent,country FROM turway where turway.id = TurWayInGroup.idturway and TurWayInGroup.idturgroup = @idturgroup", con);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add(new SqlParameter("@idturgroup", SqlDbType.Int, 6));
            cmd.Parameters["@idturgroup"].Value = turgroup;
            // Создать коллекцию для всех записей
            List<turway> list = new List<turway>();
            try
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    turway emp = new turway(
                    (int)reader["id"],
                    (int)reader["idturoperator"],
                    (int)reader["idtype"],
                    (string)reader["name"],
                    (string)reader["comment"],
                    (int)reader["agent"],
                    (string)reader["country"]
                    );

                    list.Add(emp);
                }
                reader.Close();
                return list;
            }
            catch
            {
                throw new ApplicationException("Ошибка данныx. Вывод всех турнаправлений в группе тур");
            }
            finally
            {
                con.Close();
            }
        }
Esempio n. 3
0
        public int AddTurWay(turway emp1)
        {
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("Insert into turway(idturoperator,idtype,name,comment,agent,country) values (@idturoperator,@idtype,@name,@comment,@agent,@country) SET @id = @@IDENTITY", con);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add(new SqlParameter("@name", SqlDbType.NVarChar, 150));
            cmd.Parameters["@name"].Value = emp1.Name;
            cmd.Parameters.Add(new SqlParameter("@comment", SqlDbType.NVarChar, 200));
            cmd.Parameters["@comment"].Value = emp1.Comment;
            cmd.Parameters.Add(new SqlParameter("@idturoperator", SqlDbType.Int, 6));
            cmd.Parameters["@idturoperator"].Value = emp1.Idturoperator;
            cmd.Parameters.Add(new SqlParameter("@idtype", SqlDbType.Int,6));
            cmd.Parameters["@idtype"].Value = emp1.Idtype;
            cmd.Parameters.Add(new SqlParameter("@agent", SqlDbType.Int, 3));
            cmd.Parameters["@agent"].Value = emp1.Agent;

            cmd.Parameters.Add(new SqlParameter("@country", SqlDbType.NVarChar, 200));
            cmd.Parameters["@country"].Value = emp1.Country;
            cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.Int, 6));
            cmd.Parameters["@id"].Direction = ParameterDirection.Output;

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                return (int)cmd.Parameters["id"].Value;
            }
            catch
            {
                return 0;
                throw new ApplicationException("Ошибка данныx. Добавление турнаправления");

            }
            finally
            {
                con.Close();
            }
        }