Ejemplo n.º 1
0
    /// <summary>
    /// To insert the Country by passing the individual fields
    /// </summary>
    /// <param name="CountryName">string</param>
    /// <param name="ZipCodeStart">long</param>
    /// <param name="ZipCodeEnd">long</param>
    /// <param name="IsActive">bool</param>
    public void InsertCountry(string CountryName, long ZipCodeStart, long ZipCodeEnd, bool IsActive)
    {
        Country objCountry = new Country(-1, CountryName, ZipCodeStart, ZipCodeEnd, IsActive);

        objCountry.Validate();
        CountryDB.ManageCountry(objCountry, ActionType.Add);
    }
Ejemplo n.º 2
0
        public Form1()
        {
            InitializeComponent();

            countryDB               = new CountryDB();
            comboBox1.DataSource    = null;
            comboBox1.DataSource    = countryDB.GetListCombobox();
            comboBox1.DisplayMember = "NameCountry";

            categoryDB              = new CategoryDB();
            comboBox3.DataSource    = null;
            comboBox3.DataSource    = categoryDB.GetListCombobox();
            comboBox3.DisplayMember = "NameCategory";

            discoveredDB            = new DiscoveredDB();
            comboBox5.DataSource    = null;
            comboBox5.DataSource    = discoveredDB.GetDiscoveredBox();
            comboBox5.DisplayMember = "Status";

            dB = new AdvertisementDB();
            // создаем экземпл¤р пагинатора дл¤ отображени¤ 10 записей на странице. „исло 10 можно сделать переменной и вынести в настройки
            paginator = new Paginator <AdvertisementDB, Advertisement>(dB, 10);
            // дл¤ отображени¤ данных в листвью ¤ сделал отдельный класс
            // в нем кэшируютс¤ строки
            viewer = new ListViewViewer(listView1, 5, 10);


            // вызываем обновление всех данных и событий
            // за счет того, что данный метод вызываетс¤ ѕќ—Ћ≈ создани¤ пагинатора интерфейс успевает подписатьс¤ на событи¤ пагинатора и нормально отобразить все данные
            dB.Save();
        }
Ejemplo n.º 3
0
    /// <summary>
    /// To update Country by passing the individual parameteres
    /// </summary>
    /// <param name="PKCountyId">int</param>
    /// <param name="CountryName">string</param>
    /// <param name="ZipCodeStart">long</param>
    /// <param name="ZipCodeEnd">long</param>
    /// <param name="IsActive">bool</param>
    public void UpDateCountry(int PKCountyId, string CountryName, int ZipCodeStart, int ZipCodeEnd, bool IsActive)
    {
        Country objCountry = new Country(PKCountyId, CountryName, ZipCodeStart, ZipCodeEnd, IsActive);

        objCountry.Validate();
        CountryDB.ManageCountry(objCountry, ActionType.Update);
    }
Ejemplo n.º 4
0
        private void taidalist()
        {
            if (dataGridViewCountry.SelectedCells.Count == 1)
            {   // otsime valitud rea riigi nimetus
                int selectedrowindex = dataGridViewCountry.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = dataGridViewCountry.Rows[selectedrowindex];

                label1.Text = Convert.ToString(selectedRow.Cells[0].Value);



                List <City> city = new List <City>();
                city = CountryDB.GetAllCitiesbyCountryName(label1.Text);

                DataTable table = new DataTable();

                DataColumn idColumn = table.Columns.Add("Name", typeof(string));
                table.Columns.Add("District", typeof(string));

                table.Columns.Add("Population", typeof(long));

                table.PrimaryKey = new DataColumn[] { idColumn };

                foreach (City c in city)
                {
                    table.Rows.Add(new object[] { c.Name, c.District, c.Population });
                }
                table.AcceptChanges();
                dataGridViewCity.DataSource = table;
            }
        }
Ejemplo n.º 5
0
    /// <summary>
    /// To fetch the Country by CountryId
    /// </summary>
    /// <param name="CountryId">int</param>
    /// <returns>Country</returns>
    public Country GetCountryByPKId(int CountryId)
    {
        Country objCountry = new Country();

        objCountry = CountryDB.GetCountryByPKCoundtryId(CountryId);
        return(objCountry);
    }
Ejemplo n.º 6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //  ConnectionDatabase.connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=world.mdb;Persist Security Info=True";
            //  asub Program.cs failis

            List <Country> country = new List <Country>();

            country = CountryDB.GetAllCountries();

            DataTable table = new DataTable();

            DataColumn idColumn = table.Columns.Add("Name", typeof(string));

            table.Columns.Add("Code", typeof(string));
            table.Columns.Add("Continent", typeof(string));
            table.Columns.Add("Year", typeof(int));

            table.PrimaryKey = new DataColumn[] { idColumn };

            foreach (Country c in country)
            {
                table.Rows.Add(new object[] { c.Name, c.Code, c.Continent, c.InderYear });
            }
            table.AcceptChanges();
            dataGridViewCountry.DataSource = table;
        }
Ejemplo n.º 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            Country country = new Country();

            country.Code           = textBoxCode.Text;
            country.Name           = textBoxName.Text;
            country.Continent      = textBoxContinent.Text;
            country.Region         = textBoxRegion.Text;
            country.SurfaceArea    = Convert.ToDouble(textBoxSurface.Text);
            country.InderYear      = Convert.ToDouble(textBoxIndep.Text);
            country.Population     = Convert.ToDouble(textBoxPopulation.Text);
            country.GovernmentForm = textBoxGov.Text;
            country.HeadOfState    = textBoxHead.Text;


            int arv = CountryDB.InsertNewCountry(country);

            if (arv != 0)
            {
                MessageBox.Show("Oli lisatud " + arv + " rida", "Valmis", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
                Form1 form = new Form1();
                form.Refresh();
            }
            else
            {
                MessageBox.Show("Lisamine ebaõnnestus", "Viga", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 8
0
        public static int RegisterUser(string username, string password, string email, string countryName)
        {
            int       flag      = 0;
            UserDB    userDB    = new UserDB();
            CountryDB countryDB = new CountryDB();
            Country   country   = countryDB.SelectByName(countryName);

            if (country != null)
            {
                User newUser = new User();
                newUser.Username    = username;
                newUser.Password    = password;
                newUser.Email       = email;
                newUser.CountryName = countryName;

                bool s = userDB.InsertUser(newUser);
                if (s)
                {
                    flag = 1;
                }
                else
                {
                    flag = 0;
                }
            }
            return(flag);
        }
Ejemplo n.º 9
0
 public static List <Country> ListOfCountry(int page, int pageSize, string searchValue, out int rowCount)
 {
     if (page < 1)
     {
         page = 1;
     }
     rowCount = CountryDB.Count(searchValue);
     return(CountryDB.List(page, pageSize, searchValue));
 }
Ejemplo n.º 10
0
        private void Form3_Load(object sender, EventArgs e)
        {
            List <Country> country = new List <Country>();

            country = CountryDB.GetAllCountries();
            foreach (Country c in country)
            {
                comboBox1.Items.Add(c.Code);
            }
        }
Ejemplo n.º 11
0
 //for update only
 public void UpdateInCountry(Countrydata objCountryData)
 {
     try
     {
         objCountryData.Validate();
         CountryDB.UpdateCountry(objCountryData);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 12
0
 public static List <Country> ListOfCountries(int page, int pagaSize, string searchValue)
 {
     if (page < 1)
     {
         page = 1;
     }
     if (pagaSize < 0)
     {
         pagaSize = 2000;
     }
     return(CountryDB.List(page, pagaSize, searchValue));
 }
Ejemplo n.º 13
0
 public void RemoveCountry(int countryId)
 {
     try
     {
         CountryDB countryDB = context.Countries.Find(countryId);
         context.Countries.Remove(countryDB);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 14
0
        // Countries:
        public static string[] GetCountries()
        {
            CountryDB countryDB = new CountryDB();
            Countries countries = countryDB.SelectCountries();

            string[] countryNames = new string[countries.Count];
            for (int i = 0; i < countries.Count; i++)
            {
                countryNames[i] = countries[i].Name;
            }
            return(countryNames);
        }
Ejemplo n.º 15
0
 //for new insert only
 public void InsertInCountry(string countryName, long zipCodeStart, long zipCodeEnd, bool isActive)
 {
     try
     {
         Countrydata objCountry = new Countrydata(countryName, zipCodeStart, zipCodeEnd, isActive);
         objCountry.Validate();
         CountryDB.InsertNewCountry(objCountry);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public IHttpActionResult Delete(int id)
        {
            int val = CountryDB.DeleteCountry(id);

            if (val > 0)
            {
                return(Ok($"Country with id {id} Successfully deleted!"));
            }
            else
            {
                return(Content(HttpStatusCode.NotFound, $"Country with id {id}  was not found to delete!!!"));
            }
        }
 public IHttpActionResult Post([FromBody] Country country)
 {
     try
     {
         int newCode = CountryDB.InsertNewCountry(country.Description);
         country.CountryId = newCode;
         return(Created(new Uri(Request.RequestUri.AbsoluteUri + $"/GetCountryById/{ country.CountryId }"), country));
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex));
     }
 }
Ejemplo n.º 18
0
        private void Form2_Load(object sender, EventArgs e)
        {
            //  ConnectionDatabase.connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=world.mdb;Persist Security Info=True";
            //  asub Program.cs failis

            List <Country> country = new List <Country>();

            country = CountryDB.GetAllCountries();
            foreach (Country c in country)
            {
                comboBox1.Items.Add(c.Name);
            }
        }
Ejemplo n.º 19
0
        private void button2_Click(object sender, EventArgs e)
        {
            int arv = CountryDB.DeleteCountry(((ComboBoxItem)comboBox2.SelectedItem).HiddenValue);

            if (arv != 0)
            {
                MessageBox.Show("Oli delete " + arv + " rida", "Valmis", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
            {
                MessageBox.Show("Delete ebaõnnestus", "Viga", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 20
0
 public Country AddCountry(Country country)
 {
     try
     {
         CountryDB countryDB = CountryMapper.CountryToDBModel(country);
         context.Countries.Add(countryDB);
         context.SaveChanges();
         Country newCountry = CountryMapper.CountryDBToBusinessModel(countryDB, country.Continent);
         return(newCountry);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 21
0
 public void UpdateCountry(int id, Country countryUpdated, int newContinentId)
 {
     try
     {
         CountryDB countryDB        = context.Countries.Find(id);
         CountryDB countryDBUpdated = CountryMapper.CountryToDBModel(countryUpdated);
         countryDB.ContinentId = newContinentId;
         countryDB.Name        = countryDBUpdated.Name;
         countryDB.Population  = countryDBUpdated.Population;
         countryDB.Surface     = countryDBUpdated.Surface;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 22
0
        //for filtering
        public List <Country> FilteredCountry(int a)
        {
            List <Country> qry;

            qry       = countryDB.Getcountry();
            countryDB = new CountryDB();
            if (a == 1)
            {
                qry = qry.Where(e1 => e1.IsActive == true).ToList();
            }
            else
            {
                qry = qry.Where(e1 => e1.IsActive == false).ToList();
            }
            return(qry);
        }
Ejemplo n.º 23
0
 public Country Find(string countryName)
 {
     try
     {
         CountryDB countryDB = context.Countries.Where(x => x.Name == countryName).FirstOrDefault();
         if (countryDB != null)
         {
             return(CountryMapper.CountryDBToBusinessModel(countryDB));
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 24
0
 internal static Country CountryDBToBusinessModel(CountryDB countryDB, Continent continent)
 {
     try
     {
         Country country = new Country();
         country.Id         = countryDB.Id;
         country.Name       = countryDB.Name;
         country.Population = countryDB.Population;
         country.Surface    = countryDB.Surface;
         country.Continent  = continent;
         return(country);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 25
0
 internal static CountryDB CountryToDBModel(Country country)
 {
     try
     {
         CountryDB countryDB = new CountryDB();
         countryDB.Id          = country.Id;
         countryDB.Name        = country.Name;
         countryDB.Population  = country.Population;
         countryDB.Surface     = country.Surface;
         countryDB.ContinentId = country.Continent.Id;
         return(countryDB);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public IHttpActionResult Get()
 {
     try
     {
         Country[] temp = CountryDB.GetAllCountries().ToArray();
         if (temp != null)
         {
             return(Ok(temp));
         }
         else
         {
             return(Content(HttpStatusCode.NotFound, "Countries cannot be found!"));
         }
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex));
     }
 }
Ejemplo n.º 27
0
        private void Form4_Load(object sender, EventArgs e)
        {
            List <City> city = new List <City>();

            city = CountryDB.GetAllCities();
            foreach (City r in city)
            {
                comboBox1.Items.Add(new ComboBoxItem(r.Name, Convert.ToString(r.ID)));
            }


            List <Country> country = new List <Country>();

            country = CountryDB.GetAllCountries();
            foreach (Country r in country)
            {
                comboBox2.Items.Add(new ComboBoxItem(r.Name, r.Code));
            }
        }
 public IHttpActionResult Get(int id)
 {
     try
     {
         Country c = CountryDB.GetCountryById(id);
         if (c != null)
         {
             return(Ok(c));
         }
         else
         {
             return(Content(HttpStatusCode.NotFound, "Country dont found!"));
         }
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.BadRequest, ex));
     }
 }
        public IHttpActionResult Put([FromBody] Country country)
        {
            try
            {
                int val = CountryDB.UpdateCountry(country.CountryId, country.Description);

                if (val > 0)
                {
                    return(Content(HttpStatusCode.OK, country));
                }
                else
                {
                    return(Content(HttpStatusCode.NotFound, $"{country.Description} was not found to update!"));
                }
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.BadRequest, ex));
            }
        }
Ejemplo n.º 30
0
 public Country Find(int continentId, int countryId)
 {
     try
     {
         CountryDB   countryDB   = context.Countries.Find(countryId);
         ContinentDB continentDB = context.Continents.Find(continentId);
         if (continentDB != null && countryDB != null)
         {
             countryDB.ContinentId = continentId;
             countryDB.Continent   = continentDB;
             Country country = CountryMapper.CountryDBToBusinessModel(countryDB);
             return(country);
         }
         return(null);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }