Ejemplo n.º 1
0
        public void AddProvince()
        {
            LocationsManager _locationManager = (LocationsManager)container["LocationsManager"];
            Province province = new Province("France");

            province.Id = _locationManager.AddProvince(province.Name);

            Assert.AreNotEqual(0, province.Id);
        }
Ejemplo n.º 2
0
        public void AddDistrict()
        {
            LocationsManager _locationManager = (LocationsManager)container["LocationsManager"];

            Province province = new Province("France");
            province.Id = _locationManager.AddProvince(province.Name);
            Assert.AreNotEqual(0, province.Id);

            District district = new District("Ile de France",province);
            district.Id = _locationManager.AddDistrict(district);

            Assert.AreNotEqual(0, district.Id);
        }
Ejemplo n.º 3
0
 private void InitializeCities(Province province, District district)
 {
     var cities = new List<City>();
     if (district != null)
         cities = ServicesProvider.GetInstance()
                                             .GetLocationServices()
                                             .FindCityByDistrictId(district.Id);
     else if (province != null)
     {
         var districts = ServicesProvider.GetInstance().GetLocationServices().FindDistrict(province);
         foreach (District dist in districts)
             cities.AddRange(ServicesProvider.GetInstance().GetLocationServices().FindCityByDistrictId(dist.Id));
     }
     else
         cities = ServicesProvider.GetInstance().GetLocationServices().GetCities();
     listViewCity.Items.Clear();
     foreach (City cityObject in cities)
     {
         ListViewItem listViewItem = new ListViewItem(cityObject.Name);
         listViewCity.Items.Add(listViewItem);
     }
 }
Ejemplo n.º 4
0
        public void SelectProvincesOnly()
        {
            LocationsManager _locationManager = (LocationsManager)container["LocationsManager"];
            Province provinceA = new Province("France");
            Province provinceB = new Province("Tadjikistan");
            Province provinceC = new Province("Russian");

            provinceA.Id = _locationManager.AddProvince(provinceA.Name);
            provinceB.Id = _locationManager.AddProvince(provinceB.Name);
            provinceC.Id = _locationManager.AddProvince(provinceC.Name);

            List<Province> provinceList = _locationManager.GetProvinces();
            Assert.AreEqual(4, provinceList.Count); //provinceA, provinceB, provinceC + BaseManagerTest

            _Contains(provinceA, provinceList);
            _Contains(provinceB, provinceList);
            _Contains(provinceC, provinceList);
        }
Ejemplo n.º 5
0
        public void TestUpdateDistrict()
        {
            LocationsManager _locationManager = (LocationsManager)container["LocationsManager"];

            Province province = new Province("France");
            province.Id = _locationManager.AddProvince(province.Name);
            Assert.AreNotEqual(0, province.Id);

            List<District> districts = _locationManager.GetDistricts();
            Assert.AreEqual(2, districts.Count);
            Assert.AreEqual("NANCY", districts[0].Name);
            Assert.AreEqual(2, districts[0].Id);
            Assert.AreEqual("PARIS", districts[1].Name);
            Assert.AreEqual(1, districts[1].Id);

            districts[0].Name = "china";
            _locationManager.UpdateDistrict(districts[0]);
            districts = _locationManager.GetDistricts();

            districts.Sort(new DistrictComparer());
            Assert.AreEqual(2, districts.Count);
            Assert.AreEqual("china", districts[0].Name);
            Assert.AreEqual(2, districts[0].Id);
            Assert.AreEqual("PARIS", districts[1].Name);
            Assert.AreEqual(1, districts[1].Id);
        }
Ejemplo n.º 6
0
        public void TestDeleteProvince()
        {
            LocationsManager _locationManager = (LocationsManager)container["LocationsManager"];
            Province province = new Province("France");

            province.Id = _locationManager.AddProvince(province.Name);

            Assert.AreNotEqual(0, province.Id);

            List<Province> provinces = _locationManager.GetProvinces();
            Assert.AreEqual(2, provinces.Count);
            _locationManager.DeleteProvinceById(province.Id);
            provinces = _locationManager.GetProvinces();
            Assert.AreEqual(1, provinces.Count);
        }
Ejemplo n.º 7
0
        public void TestDeleteCity()
        {
            LocationsManager _locationManager = (LocationsManager)container["LocationsManager"];

            Province province = new Province("France");
            province.Id = _locationManager.AddProvince(province.Name);
            Assert.AreNotEqual(0, province.Id);

            District district = new District("Ile de France", province);
            district.Id = _locationManager.AddDistrict(district);
            Assert.AreNotEqual(0, district.Id);

            City city = new City { Name = "Paris", DistrictId = district.Id };
            city.Id=_locationManager.AddCity(city);
            Assert.IsTrue(city.Id > 0);

            List<City> cities = _locationManager.GetCities();
            Assert.AreEqual(1, cities.Count);

               _locationManager.DeleteCityById(city.Id);
               cities = _locationManager.GetCities();
               Assert.AreEqual(0, cities.Count);
        }
Ejemplo n.º 8
0
 public List<District> FindDistrict(Province province)
 {
     return province.Id == 0 ? _locationsManager.GetDistricts() : _locationsManager.SelectDistrictsByProvinceId(province.Id);
 }
Ejemplo n.º 9
0
        public void TestUpdateProvince()
        {
            Province provinceOne = new Province(2, "Pekin");
            List<Province> provinces = new List<Province> {provinceOne};

            DynamicMock mockLocationsManager = new DynamicMock(typeof(LocationsManager));
            mockLocationsManager.SetReturnValue("GetProvinces", provinces);
            mockLocationsManager.ExpectAndReturn("UpdateProvince", true, provinceOne);

            LocationsManager mocklocationManager = (LocationsManager)mockLocationsManager.MockInstance;
            LocationServices locationService = new LocationServices(mocklocationManager);

            Assert.AreEqual("Pekin", locationService.GetProvinces()[0].Name);
            Assert.AreEqual(true, locationService.UpdateProvince(provinceOne));
        }
Ejemplo n.º 10
0
        public void TestUpdateDistrict()
        {
            Province provinceOne = new Province(2, "Pekin");
            District district = new District("Pekin", provinceOne);
            List<District> districts = new List<District> {district};

            DynamicMock mockLocationsManager = new DynamicMock(typeof (LocationsManager));
            mockLocationsManager.SetReturnValue("GetDistricts", districts);
            mockLocationsManager.ExpectAndReturn("UpdateDistrict", true, district);

            LocationsManager mocklocationManager = (LocationsManager) mockLocationsManager.MockInstance;
            LocationServices locationService = new LocationServices(mocklocationManager);

            Assert.AreEqual("Pekin", locationService.GetDistricts()[0].Name);
            Assert.AreEqual(true, locationService.UpdateDistrict(district));
        }
Ejemplo n.º 11
0
        public void TestDeleteProvinceWithoutDistrictIn()
        {
            Province provinceOne = new Province(2, "Pekin");
            Province provinceTwo = new Province(8, "Qhinghua");

            List<District> districts = new List<District>
                                           {
                                               new District("Paris",provinceOne),
                                               new District("Pekin",provinceOne),
                                               new District("Pau",provinceOne)
                                           };

            DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager));
            dynamicMock.SetReturnValue("GetDistricts", districts);
            dynamicMock.Expect("DeleteProvinceById", 8);

            LocationsManager mocklocationManager = (LocationsManager)dynamicMock.MockInstance;
            LocationServices locationService = new LocationServices(mocklocationManager);
            Assert.AreEqual(true, locationService.DeleteProvince(provinceTwo));
        }
Ejemplo n.º 12
0
 public bool UpdateProvince(Province pProvince)
 {
     bool updateOk = false;
     try
     {
         const string q = "UPDATE [Provinces] SET [name]=@name WHERE id=@id";
         using (SqlConnection conn = GetConnection())
         using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
         {
             c.AddParam("@id", pProvince.Id);
             c.AddParam("@name", pProvince.Name);
             c.ExecuteNonQuery();
             updateOk = true;
         }
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
     return updateOk;
 }
Ejemplo n.º 13
0
 public Province SelectProvinceByName(string name)
 {
     const string q = "SELECT id,name FROM Provinces WHERE name = @name";
     using (SqlConnection conn = GetConnection())
     using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
     {
         c.AddParam("@name", name);
         using (OpenCbsReader r = c.ExecuteReader())
         {
             if (null == r || r.Empty) return null;
             r.Read();
             Province retval = new Province
                                   {
                                       Id = r.GetInt("id"),
                                       Name = r.GetString("name")
                                   };
             return retval;
         }
     }
 }
Ejemplo n.º 14
0
        public List<Province> SelectAllProvinces()
        {
            List<Province> provinces = new List<Province>();

            const string q = "SELECT id,name FROM Provinces ORDER BY name";
            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
            using (OpenCbsReader r = c.ExecuteReader())
            {
                if (r != null)
                {
                    while (r.Read())
                    {
                        Province province = new Province
                                                {
                                                    Id = r.GetInt("id"),
                                                    Name = r.GetString("name")
                                                };
                        provinces.Add(province);
                    }
                }
            }

            return provinces;
        }
Ejemplo n.º 15
0
        public List<Province> GetProvinces()
        {
            List<Province> provinces = new List<Province>();
            const string q = "SELECT [id],[name] FROM [Provinces]  WHERE [deleted] = 0 ORDER BY name";

            using (SqlConnection conn = GetConnection())
            using (OpenCbsCommand c = new OpenCbsCommand(q, conn))
            {
                using (OpenCbsReader r = c.ExecuteReader())
                {
                    if (r != null)
                    {
                        while (r.Read())
                        {
                            Province province = new Province();
                            province.Id = r.GetInt("id");
                            province.Name = r.GetString("name");
                            provinces.Add(province);
                        }
                    }
                }
            }
            return provinces;
        }
Ejemplo n.º 16
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (buttonUpdate.Text.Equals(GetString("buttonEdit")))
                {
                    try
                    {
                        node = treeViewLocations.SelectedNode;
                        if (node == null) return;

                        if ((node.Tag is Province))
                        {
                            province = (Province) node.Tag;
                            tbName.Text = province.Name;
                        }
                        else if ((node.Tag is District))
                        {
                            district = (District) node.Tag;
                            tbName.Text = district.Name;
                        }
                        else if ((node.Tag is City))
                        {
                            city = (City) node.Tag;
                            tbName.Text = city.Name;
                        }
                    } catch (Exception exception)
                    {
                        var exceptionStatus = CustomExceptionHandler.ShowExceptionText(exception);
                        new frmShowError(exceptionStatus).ShowDialog();
                        return;
                    }

                    treeViewLocations.Enabled = false;
                    buttonAdd.Enabled = false;
                    buttonDelete.Enabled = false;
                    buttonExit.Enabled = false;
                    buttonUpdate.Text = GetString("buttonSave");
                }
                else
                {
                    try
                    {
                        if ((node.Tag is Province))
                        {
                            province.Name = tbName.Text;
                            ServicesProvider.GetInstance().GetLocationServices().UpdateProvince(province);
                        }
                        else if ((node.Tag is District))
                        {
                            district.Name = tbName.Text;
                            ServicesProvider.GetInstance().GetLocationServices().UpdateDistrict(district);
                        }
                        else if ((node.Tag is City))
                        {
                            city.Name = tbName.Text;
                            ServicesProvider.GetInstance().GetLocationServices().UpdateCity(city);
                        }
                    } catch (Exception exception)
                    {
                        var exceptionStatus = CustomExceptionHandler.ShowExceptionText(exception);
                        new frmShowError(exceptionStatus).ShowDialog();
                        return;
                    }

                    node.Text = tbName.Text;
                    buttonExit.Enabled = true;
                    buttonAdd.Enabled = true;
                    buttonDelete.Enabled = true;
                    treeViewLocations.Enabled = true;
                    buttonUpdate.Text = GetString("buttonEdit");
                }
            } catch (Exception exception)
            {
                var exceptionStatus = CustomExceptionHandler.ShowExceptionText(exception);
                new frmShowError(exceptionStatus).ShowDialog();
                return;
            }

            treeViewLocations.Sort();
        }
Ejemplo n.º 17
0
 public bool DeleteProvince(Province pProvince)
 {
     bool deleteProvincePossible = true;
     List<District> districts = new List<District>();
     districts = _locationsManager.GetDistricts();
     for (int i = 0; i < districts.Count; i++)
     {
         if (districts[i].Province.Id != pProvince.Id)
             continue;
         deleteProvincePossible = false;
         break;
     }
     if (deleteProvincePossible)
         _locationsManager.DeleteProvinceById(pProvince.Id);
     return deleteProvincePossible;
 }
Ejemplo n.º 18
0
 public District(int id, string name, Province province)
 {
     _id       = id;
     _name     = name;
     _province = province;
 }
Ejemplo n.º 19
0
 public bool UpdateProvince(Province province)
 {
     CheckLocation(province.Name);
     return _locationsManager.UpdateProvince(province);
 }
Ejemplo n.º 20
0
 public District(string name, Province province)
 {
     _name     = name;
     _province = province;
 }
Ejemplo n.º 21
0
        public void TestDeleteDistrict()
        {
            LocationsManager _locationManager = (LocationsManager)container["LocationsManager"];

            Province province = new Province("France");
            province.Id = _locationManager.AddProvince(province.Name);
            Assert.AreNotEqual(0, province.Id);

            District district = new District("Ile de France", province);
            district.Id = _locationManager.AddDistrict(district);

            Assert.AreNotEqual(0, district.Id);

            List<District> districts = _locationManager.GetDistricts();
            Assert.AreEqual(3, districts.Count);

            _locationManager.DeleteDistrictById(district.Id);
            districts = _locationManager.GetDistricts();
            Assert.AreEqual(2, districts.Count);
        }
Ejemplo n.º 22
0
 private void comboBoxProvince_SelectionChangeCommitted(object sender, System.EventArgs e)
 {
     _province = (Province)comboBoxProvince.SelectedItem;
     _InitializeDistricts();
     textBoxCity.Text = String.Empty;
 }
Ejemplo n.º 23
0
        public void TestUpdateCity()
        {
            LocationsManager _locationManager = (LocationsManager)container["LocationsManager"];

            Province province = new Province("France");
            province.Id = _locationManager.AddProvince(province.Name);
            Assert.AreNotEqual(0, province.Id);

            District district = new District("Ile de France", province);
            district.Id = _locationManager.AddDistrict(district);
            Assert.AreNotEqual(0, district.Id);

            City city = new City {Name = "Paris", DistrictId = district.Id};
            city.Id=_locationManager.AddCity(city);

            city.Name = "qsd";
            _locationManager.UpdateCity(city);
            List<City> cities = _locationManager.GetCities();
            Assert.AreEqual("qsd", cities[0].Name);
        }
Ejemplo n.º 24
0
 private void _Initialization()
 {
     InitializeComponent();
     _province = new Province();
     _district = null;
     _city = null;
     _comments = null;
     _homePhone = string.Empty;
     _personalPhone = string.Empty;
     _email = string.Empty;
     _zipCode = string.Empty;
     _homeType = string.Empty;
     _InitializeProvince();
     _InitializeDistricts();
     _InitializeCity();
     _InitializeHomeType();
 }
Ejemplo n.º 25
0
 private static void _Contains(Province pProvince, IEnumerable<Province> pProvincesList)
 {
     Province selectedProvince = null;
     foreach (Province province in pProvincesList)
     {
         if (province.Name != pProvince.Name)
         {
             continue;
         }
         selectedProvince = province;
         break;
     }
     if (selectedProvince == null) Assert.Fail();
     else
         Assert.AreEqual(selectedProvince.Name, pProvince.Name);
 }
Ejemplo n.º 26
0
        private void _InitializeProvince()
        {
            comboBoxProvince.Items.Clear();
            var selectProvince = new Province { Name = MultiLanguageStrings.GetString(Ressource.AddressUserControl, "all.Text") };
            comboBoxProvince.Items.Add(selectProvince);

            var provinceList = ServicesProvider.GetInstance().GetLocationServices().GetProvinces();
            foreach (var pro in provinceList)
            {
                comboBoxProvince.Items.Add(pro);
            }
            comboBoxProvince.SelectedItem = selectProvince;
        }
Ejemplo n.º 27
0
 private void _SelectProvince()
 {
     if (_district.Id == 0)
     {
         return;
     }
     foreach (Province selectedProvince in comboBoxProvince.Items)
     {
         if (selectedProvince.Name != _district.Province.Name)
         {
             continue;
         }
         comboBoxProvince.SelectedItem = selectedProvince;
         _province = selectedProvince;
         break;
     }
 }
Ejemplo n.º 28
0
		public District(int id,string name,Province province)
		{
			_id = id;
			_name = name;
			_province = province;
		}
Ejemplo n.º 29
0
 public CityForm(Province province, District district)
 {
     InitializeComponent();
     InitializeCities(province, district);
 }
Ejemplo n.º 30
0
		public District(string name,Province province)
		{
			_name = name;
			_province = province;
		}
Ejemplo n.º 31
0
 public Province AddProvinceIntoDatabase()
 {
     SqlCommand command = new SqlCommand("INSERT INTO Provinces (name,deleted) VALUES ('Sugh',0) SELECT SCOPE_IDENTITY()", _connection);
     Province province = new Province();
     province.Name = "Sugh";
     province.Id = int.Parse(command.ExecuteScalar().ToString());
     return province;
 }
Ejemplo n.º 32
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            TreeNode node = treeViewLocations.SelectedNode;
            try
            {
                if (node == null)
                {
                    buttonAdd.Enabled = false;
                    buttonDelete.Enabled = false;
                    buttonUpdate.Enabled = false;
                    return;
                }
                if (!string.IsNullOrEmpty(tbName.Text))
                {
                    var locationServices = ServicesProvider.GetInstance().GetLocationServices();
                    if (node.Tag == null)
                    {
                        // Add province
                        int newId = locationServices.AddProvince(tbName.Text);
                        Province p = new Province(newId, tbName.Text);
                        TreeNode pnode = new TreeNode(tbName.Text) {Tag = p};
                        node.Nodes.Add(pnode);
                    }
                    else if ((node.Tag is Province))
                    {
                        // Add district
                        Province province = (Province) node.Tag;
                        int newId = locationServices.AddDistrict(tbName.Text, province.Id);
                        District d = new District(newId, tbName.Text, province);
                        TreeNode dnode = new TreeNode(tbName.Text) {Tag = d};
                        node.Nodes.Add(dnode);
                    }
                    else if ((node.Tag is District))
                    {
                        // Add city
                        District district = (District) node.Tag;
                        City city = new City {Name = tbName.Text, DistrictId = district.Id};
                        city.Id = locationServices.AddCity(city);
                        TreeNode cnode = new TreeNode(tbName.Text) {Tag = city};
                        node.Nodes.Add(cnode);
                        buttonAdd.Enabled = false;
                    }
                    tbName.Clear();
                }
            } catch(Exception exception)
            {
                var exceptionStatus = CustomExceptionHandler.ShowExceptionText(exception);
                new frmShowError(exceptionStatus).ShowDialog();
                return;
            }

            node.Expand();
            treeViewLocations.Sort();

        }