private void UpdateCommandHandler(object sender, ExecutedRoutedEventArgs e)
 {
     if (newCityGrid.IsVisible)
     {
         newCity = new Model.City();
         Model.City ncity = myCityViewSource.View.CurrentItem as Model.City;
         if (ncity != null && ncity?.CountryID != null)
         {
             newCity.CityName  = ncity?.CityName;
             newCity.CountryID = ncity?.CountryID ?? context.Countries.FirstOrDefault().CountryID;
             if (!string.IsNullOrWhiteSpace(newCity?.CityName))
             {
                 myCityViewSource.View.Refresh();
                 myCityViewSource.View.MoveCurrentTo(newCity);
                 context.SaveChanges();
                 Messenger.Default.Send <string>(Utils.CityAddedMessage);
             }
             else
             {
                 MessageBox.Show("City Is Empty.");
             }
         }
         else
         {
             MessageBox.Show("City or selected Country Is Empty.");
         }
         newCityGrid.Visibility      = Visibility.Collapsed;
         existingCityGrid.Visibility = Visibility.Visible;
     }
 }
Beispiel #2
0
        public ReturnInfo Create(SmartDB dbInstance, ref Model.City info)
        {
            IInfo info2 = _dal.Insert(dbInstance, info);

            info.IsNew   = false;
            info.IsDirty = true;
            return(new ReturnInfo(info2.Code, info2.Message));
        }
 public CitiesView()
 {
     InitializeComponent();
     newCity               = new City();
     myCityViewSource      = (CollectionViewSource)this.Resources["cityViewSource"];
     myCountriesViewSource = (CollectionViewSource)this.Resources["countryViewSource"];
     DataContext           = this;
 }
Beispiel #4
0
 public void DrawCentralNodel(Model.City centralNode)
 {
     graph.DrawEllipse(pen, centralNode.Latitude, centralNode.Longitude, 20, 20);
     graph.FillEllipse(Brushes.GreenYellow, new Rectangle(new Point(centralNode.Latitude, centralNode.Longitude), new Size(20, 20)));
     using (Font myFont = new Font("Arial", 10, FontStyle.Bold))
     {
         graph.DrawString("Central Node", myFont, Brushes.Orange, new Point(centralNode.Latitude + 15, centralNode.Longitude + 15));
     }
 }
Beispiel #5
0
 /// <summary>
 /// (X, Y)
 /// </summary>
 /// <param name="latitude"></param>
 /// <param name="longitud"></param>
 public void DrawCity(Model.City city)
 {
     graph.DrawEllipse(pen, city.Latitude, city.Longitude, 20, 20);
     graph.FillEllipse(Brushes.Red, new Rectangle(new Point(city.Latitude, city.Longitude), new Size(20, 20)));
     using (Font myFont = new Font("Arial", 9, FontStyle.Bold))
     {
         graph.DrawString(city.Name, myFont, Brushes.Yellow, new Point(city.Latitude - 15, city.Longitude - 15));
     }
 }
Beispiel #6
0
        public override IInfo GetRecord(SmartDB dbInstance, object Id)
        {
            string sQL_GET = this.SQL_GET;

            SqlParameter[] array = new SqlParameter[]
            {
                new SqlParameter(this.PARM_ID, SqlDbType.NVarChar)
            };
            array[0].Value = Id;
            Model.City bizObject = null;
            IInfo      result;

            try
            {
                bool          transactionControl = dbInstance.TransactionControl;
                SqlDataReader sqlDataReader;
                if (transactionControl)
                {
                    sqlDataReader = SqlHelper.ExecuteReader(dbInstance.Transaction, CommandType.StoredProcedure, sQL_GET, array);
                }
                else
                {
                    sqlDataReader = SqlHelper.ExecuteReader(SqlHelper.MyConnectionString, CommandType.StoredProcedure, sQL_GET, array);
                }
                bool hasRows = sqlDataReader.HasRows;
                if (hasRows)
                {
                    sqlDataReader.Read();
                    this.SetInfo(out bizObject, sqlDataReader);
                    result = new ReturnInfo
                    {
                        BizObject = bizObject,
                        Code      = ErrorEnum.NoError
                    };
                }
                else
                {
                    result = new ReturnInfo(ErrorEnum.NoRecord, string.Format("No record found for ID: {0}", Id));
                }
            }
            catch (Exception ex)
            {
                result = new ReturnInfo(ErrorEnum.DataException, ex.Message);
            }
            return(result);
        }
Beispiel #7
0
        public ReturnInfo Update(SmartDB dbInstance, Model.City info)
        {
            IInfo      info2 = _dal.GetRecord(dbInstance, info.Id);
            bool       flag  = info2.Code == ErrorEnum.NoError;
            ReturnInfo result;

            if (flag)
            {
                bool flag2 = (info2.BizObject as Model.City).LockCount == info.LockCount;
                if (!flag2)
                {
                    result = new ReturnInfo(ErrorEnum.ColumnReference, "Record has been changed.");
                    return(result);
                }
                info.LockCount++;
                info2 = _dal.Update(dbInstance, info);
            }
            result = new ReturnInfo(info2.Code, info2.Message, info2.RowsAffected);
            return(result);
        }
Beispiel #8
0
        public ReturnInfo IsValid(Model.City info)
        {
            bool       flag = string.IsNullOrEmpty(info.Id);
            ReturnInfo result;

            if (flag)
            {
                result = new ReturnInfo
                {
                    Code      = ErrorEnum.InvalidInput,
                    Message   = "Name cannot be blank.",
                    BizObject = "Name"
                };
            }
            else
            {
                result = new ReturnInfo(ErrorEnum.NoError, "");
            }
            return(result);
        }
Beispiel #9
0
 protected void SetInfo(out Model.City info, SqlDataReader reader)
 {
     try
     {
         info                     = new Model.City();
         info.Id                  = CastDBNull.To <string>(reader["Id"], "");
         info.Description         = CastDBNull.To <string>(reader["Description"], "");
         info.TotalNumberOfMeters = CastDBNull.To <int>(reader["TotalNumberOfMeters"], 0);
         info.CreatedBy           = CastDBNull.To <string>(reader["Createdby"], "");
         info.EditedBy            = CastDBNull.To <string>(reader["Editedby"], "");
         info.DocDate             = CastDBNull.To <DateTime>(reader["DocDate"], DateTime.Now);
         info.Show                = CastDBNull.To <int>(reader["Show"], 1);
         info.LockCount           = CastDBNull.To <int>(reader["LockCount"], 1);
         info.IsNew               = false;
         info.IsDirty             = true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #10
0
        public void DrawRoute(Model.City city1, Model.City city2, string route = "")
        {
            graph.DrawLine(pen, city1.Latitude + 10, city1.Longitude + 10, city2.Latitude + 10, city2.Longitude + 10);
            if (string.IsNullOrWhiteSpace(route))
            {
                return;
            }

            using (Font myFont = new Font("Arial", 16, FontStyle.Bold))
            {
                var x = (city1.Latitude + city2.Latitude) / 2;
                var y = (city1.Longitude + city2.Longitude) / 2;
                graph.DrawString(route, myFont, Brushes.Yellow, new Point(x + 10, y + 10));
            }

            using (Font myFont = new Font("Arial", 8, FontStyle.Italic))
            {
                var distance = city1.GetDistanceTo(city2);
                var x        = (city1.Latitude + city2.Latitude) / 2;
                var y        = (city1.Longitude + city2.Longitude) / 2;
                graph.DrawString(distance.ToString("#.#") + "kms", myFont, Brushes.Yellow, new Point(x + 25, y + 25));
            }
        }
Beispiel #11
0
        public void Init(DBContext context)
        {
            var Movie1 = new Model.Movie
            {
                Title        = "Solo: A Star War Story",
                Genre        = "Action",
                Actor        = "Emila Clarke",
                Director     = "Ron Haward",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img.jpg"
            };

            var Movie2 = new Model.Movie
            {
                Title        = "The Meg",
                Genre        = "Action",
                Actor        = "Ruby Rose",
                Director     = "Jon Turteltaub",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img1.jpg"
            };

            var Movie3 = new Model.Movie
            {
                Title        = "Venom",
                Genre        = "Action",
                Actor        = "Tom Hardy",
                Director     = "Ruben Fleisher",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img2.jpg",
            };

            var Movie4 = new Model.Movie
            {
                Title        = "Misson Impossible: Fallout",
                Genre        = "Action",
                Actor        = "Tom Cruise",
                Director     = "Christopher McQuarrie",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img3.jpg"
            };

            var Movie5 = new Model.Movie
            {
                Title        = "Black Panther",
                Genre        = "Adventure",
                Actor        = "Chadwic Boseman",
                Director     = "Ryan Coogler",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img4.jpg"
            };

            var Movie6 = new Model.Movie
            {
                Title        = "Alpha",
                Genre        = "Action",
                Actor        = "Kodi Smit-McPhee",
                Director     = "Albert Hughes",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img5.jpg"
            };

            var Movie7 = new Model.Movie
            {
                Title        = "Jonny English Strikes Again",
                Genre        = "Comedy",
                Actor        = "Rowan Atkinson",
                Director     = "David Kerr",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img6.jpg"
            };

            var Movie8 = new Model.Movie
            {
                Title        = "The Equalize 2",
                Genre        = "Action",
                Actor        = "Denzel Washington",
                Director     = "Antonie Fuqua",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img7.jpg"
            };

            var Movie9 = new Model.Movie
            {
                Title        = "Tag",
                Genre        = "Comedy",
                Actor        = "Jenny Renner",
                Director     = "Jeff Tosmic",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img8.jpg"
            };

            var Movie10 = new Model.Movie
            {
                Title        = "Uncle Drew",
                Genre        = "Comedy",
                Actor        = "Kyrie Irving",
                Director     = "Charles Stone lll",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img9.jpg"
            };

            var Movie11 = new Model.Movie
            {
                Title        = "Night School",
                Genre        = "Comedy",
                Actor        = "Kevin Hart",
                Director     = "Malcom D.Lee",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img10.jpg"
            };

            var Movie12 = new Model.Movie
            {
                Title        = "Game Night",
                Genre        = "Comedy",
                Actor        = "Jason Batman",
                Director     = "John Francis Daley",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img11.jpg"
            };

            var Movie13 = new Model.Movie
            {
                Title        = "Life Of The Party",
                Genre        = "Comedy",
                Actor        = "Melissa McCarthy",
                Director     = "Melissa McCarthy",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img12.jpg"
            };

            var Movie14 = new Model.Movie
            {
                Title        = "Jurrasic World",
                Genre        = "Adventure",
                Actor        = "Chris Pratt",
                Director     = "J.A. Bayona",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img13.jpg"
            };

            var Movie15 = new Model.Movie
            {
                Title        = "Avvengers: Infinity War",
                Genre        = "Adventure",
                Actor        = "Robert D.Jr.",
                Director     = "Joe Russo",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img14.jpg"
            };
            var Movie16 = new Model.Movie
            {
                Title        = "Ant-Man and The Wasp",
                Genre        = "Adventure",
                Actor        = "Paul Rudd",
                Director     = "Peython Reed",
                ReleasedYear = 2018,
                Price        = 199,
                Image        = "jpg/img15.jpg"
            };

            /*
             * var Movie17 = new Model.Movie
             * {
             *  Title = "Next Gen",
             *  Genre = "Adventure",
             *  Actor = "JAson Sudeikis",
             *  Director = "Kevin R.Adams.",
             *  ReleasedYear = 2018,
             *  Price = 199,
             *  Image = "jpg/img16.jpg"
             * };
             *
             * var Movie18 = new Model.Movie
             * {
             *  Title = "Spiderman: Into the spider-verse",
             *  Genre = "Adventure",
             *  Actor = "Nicholas Cage",
             *  Director = "Bob Persichetti",
             *  ReleasedYear = 2018,
             *  Price = 199,
             *  Image = "jpg/img17.jpg"
             * };
             */

            context.MovieTable.Add(Movie1);
            context.MovieTable.Add(Movie2);
            context.MovieTable.Add(Movie3);
            context.MovieTable.Add(Movie4);
            context.MovieTable.Add(Movie5);
            context.MovieTable.Add(Movie6);
            context.MovieTable.Add(Movie7);
            context.MovieTable.Add(Movie8);
            context.MovieTable.Add(Movie9);
            context.MovieTable.Add(Movie10);
            context.MovieTable.Add(Movie11);
            context.MovieTable.Add(Movie12);
            context.MovieTable.Add(Movie13);
            context.MovieTable.Add(Movie14);
            context.MovieTable.Add(Movie15);
            context.MovieTable.Add(Movie16);
            // context.MovieTable.Add(Movie17);
            // context.MovieTable.Add(Movie18);


            string path = HttpContext.Current.Server.MapPath(@"~\Content\Postnummerregister-ansi.txt");

            string[] lines = System.IO.File.ReadAllLines(path);



            foreach (var line in lines)
            {
                string[] words      = line.Split('\t');
                var      postedsRad = new Model.City()
                {
                    Postnummer = words[0],
                    Poststed   = words[1]
                };

                context.CityTable.Add(postedsRad);
                context.SaveChanges();
            }

            var defaultAdmin = new Model.Users
            {
                Fornavn     = "Administrator",
                Etternavn   = "",
                Adresse     = "",
                Epost       = "Admin",
                AccessLevel = "Admin"
            };

            byte[] salt = UserDAL.LagSalt();
            byte[] hash = UserDAL.LagHash("admin", salt);
            defaultAdmin.Passord = hash;
            defaultAdmin.Salt    = salt;

            context.UserTable.Add(defaultAdmin);
            context.SaveChanges();
        }
Beispiel #12
0
 public void EditCity(Model.City city)
 {
     throw new NotImplementedException();
 }