Ejemplo n.º 1
0
        bool isWalkable(int x, int y)
        {
            listitem tempItem = new listitem();
            Point    Loc      = new Point(x, y);

            if (colMap[x, y].tileType == TileInfo.TileType.Wall)
            {
                tempItem.closed = true;
                if (!list.ContainsKey(Loc))
                {
                    list.Add(Loc, tempItem);
                }
                list[new Point(x, y)] = tempItem;
                return(false);
            }
            else if (colMap[x, y].unitOnTile != null && colMap[x, y].unitOnTile.isPlayer && x != goalX && y != goalY)
            {
                tempItem.closed = true;
                if (!list.ContainsKey(Loc))
                {
                    list.Add(Loc, tempItem);
                }
                list[new Point(x, y)] = tempItem;
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public IHttpActionResult Putlistitem(int id, listitem listitem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != listitem.ID)
            {
                return(BadRequest());
            }

            db.Entry(listitem).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!listitemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int ListItemID)
        {
            listitem listitem = ListItemRepository.GetListItemByID(ListItemID);

            ListItemRepository.DeleteRecord(listitem);
            return(RedirectToAction("Create", new { ListTableID = listitem.listTableID }));
        }
Ejemplo n.º 4
0
        //
        // GET: /ListItem/Delete/5

        public ActionResult Delete(int ListItemID)
        {
            ViewBag.ListItemID = ListItemID;
            listitem listitem = ListItemRepository.GetListItemByID(ListItemID);

            return(PartialView(listitem));
        }
Ejemplo n.º 5
0
        private void listview1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            listitem t = listview1.SelectedItem as listitem;

            if (t != null)
            {
                buyprice.Text = t.Price;
            }
        }
Ejemplo n.º 6
0
        public IHttpActionResult Getlistitem(int id)
        {
            listitem listitem = db.listitems.Find(id);

            if (listitem == null)
            {
                return(NotFound());
            }

            return(Ok(listitem));
        }
Ejemplo n.º 7
0
        public IHttpActionResult Postlistitem(listitem listitem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.listitems.Add(listitem);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = listitem.ID }, listitem));
        }
Ejemplo n.º 8
0
        public ActionResult Edit(listitem listitem)
        {
            string ReturnUrl = Request.UrlReferrer.ToString();

            try
            {
                if (listitem.Comment == null)
                {
                    listitem.Comment = "";
                }
                if (listitem.Value1 == null)
                {
                    listitem.Value1 = "";
                }
                if (listitem.Value2 == null)
                {
                    listitem.Value2 = "";
                }
                if (listitem.Value3 == null)
                {
                    listitem.Value3 = "";
                }
                if (listitem.Value4 == null)
                {
                    listitem.Value4 = "";
                }
                if (listitem.Value5 == null)
                {
                    listitem.Value5 = "";
                }
                if (listitem.Value6 == null)
                {
                    listitem.Value6 = "";
                }
                // if (listitem.Value7 == null) { listitem.Value7 = ""; }

                if (ModelState.IsValid)
                {
                    db.Entry(listitem).State = EntityState.Modified;
                    db.SaveChanges();
                    TempData["Message2"] = string.Format("Table data update successfully.");
                    GetData();
                    //return RedirectToAction("Create", new { ListTableID = listitem.listTableID });
                    return(Redirect(ReturnUrl));
                }
            }
            catch (Exception ex)
            {
                TempData["Message2"] = string.Format("Error editing table data.");
            }
            GetData();
            return(PartialView(listitem));
        }
Ejemplo n.º 9
0
        public ActionResult Create(listitem listitem)
        {
            try
            {
                if (listitem.Comment == null)
                {
                    listitem.Comment = "";
                }
                if (listitem.Value1 == null)
                {
                    listitem.Value1 = "";
                }
                if (listitem.Value2 == null)
                {
                    listitem.Value2 = "";
                }
                if (listitem.Value3 == null)
                {
                    listitem.Value3 = "";
                }
                if (listitem.Value4 == null)
                {
                    listitem.Value4 = "";
                }
                if (listitem.Value5 == null)
                {
                    listitem.Value5 = "";
                }
                if (listitem.Value6 == null)
                {
                    listitem.Value6 = "";
                }
                // if (listitem.Value7 == null) { listitem.Value7 = ""; }


                if (ModelState.IsValid)
                {
                    db.listitems.Add(listitem);
                    db.SaveChanges();
                    ListItemRepository.AddRecord(listitem);
                    TempData["Message2"] = "Table record added successfully.";
                    GetData();
                    return(RedirectToAction("Create", new { ListTableID = listitem.listTableID }));
                }
            }
            catch (Exception ex)
            {
                TempData["Message2"] = "Error adding table record";
            }
            GetData();
            return(PartialView(listitem));
        }
Ejemplo n.º 10
0
        public IHttpActionResult Deletelistitem(int id)
        {
            listitem listitem = db.listitems.Find(id);

            if (listitem == null)
            {
                return(NotFound());
            }

            db.listitems.Remove(listitem);
            db.SaveChanges();

            return(Ok(listitem));
        }
Ejemplo n.º 11
0
        public ActionResult Edit(int ListItemID)
        {
            listitem listitem = ListItemRepository.GetListItemByID(ListItemID);

            GetData();
            listtable table = ListTableRepository.GetListByID(listitem.listTableID);

            ViewBag.TableName = string.Format("Add new record to the{0}", table.Title);
            listheader header = ListHeaderRepository.GetByListTableID(listitem.listTableID);

            ViewBag.Type1  = header.Type1;
            ViewBag.Type2  = header.Type2;
            ViewBag.Type3  = header.Type3;
            ViewBag.Type4  = header.Type4;
            ViewBag.Type5  = header.Type5;
            ViewBag.Type6  = header.Type6;
            ViewBag.Type7  = header.Type7;
            ViewBag.Type8  = header.Type8;
            ViewBag.Type9  = header.Type9;
            ViewBag.Type10 = header.Type10;

            return(PartialView(listitem));
        }
Ejemplo n.º 12
0
        bool isWalkable(int x, int y)
        {
            listitem tempItem = new listitem();
            Point Loc = new Point(x, y);

            if (_colMap[x, y].tileType == TileInfo.TileType.Wall)
            {
                tempItem.closed = true;
                if (!list.ContainsKey(Loc))
                    list.Add(Loc, tempItem);
                list[new Point(x, y)] = tempItem;
                return false;
            }
            else if (_colMap[x, y].unitOnTile != null && _colMap[x, y].unitOnTile.isPlayer && x != goalX && y != goalY)
            {
                tempItem.closed = true;
                if (!list.ContainsKey(Loc))
                    list.Add(Loc, tempItem);
                list[new Point(x, y)] = tempItem;
                return false;
            }

            return true;
        }
Ejemplo n.º 13
0
 public void DeleteRecord(listitem record)
 {
     myRecords.Remove(record);
     context.listitems.Remove(record);
     context.SaveChanges();
 }
Ejemplo n.º 14
0
 public listitem GetListItemByID(int itemID)
 {
     record = myRecords.FirstOrDefault(e => e.listItemID == itemID);
     return(record);
 }
Ejemplo n.º 15
0
 public void AddRecord(listitem Record)
 {
     myRecords.Add(record);
 }
Ejemplo n.º 16
0
        void setOpenOnLowestF(int Sx, int Sy, int Gx, int Gy)
        {
            int test        = 0;
            int loops       = 0;
            int removeIndex = 0;

            do
            {
                Point    startLoc = new Point(Sx, Sy);
                listitem ListItem = list[startLoc];
                loops++;
                ListItem.opened = false;
                openList.RemoveAt(removeIndex);
                ListItem.closed = true;
                list[startLoc]  = ListItem;
                int YFin = Sy + 1;
                int XFin = Sx + 1;
                for (int y = Sy - 1; y <= YFin; ++y)
                {
                    if (y < 0 || y > Height - 1)
                    {
                        continue;
                    }
                    for (int x = Sx - 1; x <= XFin; ++x)
                    {
                        Point Location = new Point(x, y);
                        if (!list.ContainsKey(Location))
                        {
                            list.Add(new Point(x, y), new listitem(x, y));
                        }
                        if ((x == Sx && y == Sy) || (x < 0 || x > Width - 1) ||
                            (!isWalkable(x, y)) || (list[Location].closed))        // || npcthere(x, y))
                        {
                            continue;
                        }
                        TileInfo ColNode      = colMap[x, y];
                        listitem tempListItem = list[Location];
                        if (tempListItem.opened)
                        {
                            int tempG = 0;
                            if (x == Sx || y == Sy)
                            {
                                if (ColNode.unitOnTile == null)
                                {
                                    tempG = 10 + list[Location].G;
                                }
                                else
                                {
                                    tempListItem.G = 45 + tempListItem.G;
                                }
                            }
                            else
                            {
                                if (ColNode.unitOnTile == null)
                                {
                                    tempG = 14 + tempListItem.G;
                                }
                                else
                                {
                                    tempListItem.G = 62 + tempListItem.G;
                                }
                            }
                            if (tempG < list[Location].G)
                            {
                                tempListItem.G       = tempG;
                                tempListItem.parentX = Sx;
                                tempListItem.parentY = Sy;
                                tempListItem.F       = tempListItem.G + tempListItem.H;
                            }
                            list[Location] = tempListItem;
                            continue;
                        }
                        if (x == Sx || y == Sy)
                        {
                            if (ColNode.unitOnTile == null)
                            {
                                tempListItem.G = 10 + list[new Point(Sx, Sy)].G;
                            }
                            else
                            {
                                tempListItem.G = 45 + list[new Point(Sx, Sy)].G;
                            }
                            tempListItem.opened  = true;
                            tempListItem.x       = x;
                            tempListItem.y       = y;
                            tempListItem.parentX = Sx;
                            tempListItem.parentY = Sy;
                            tempListItem.H       = calculateH(goalX, x) + calculateH(goalY, y);
                            tempListItem.F       = tempListItem.G + tempListItem.H;
                            openList.Add(tempListItem);
                            list[Location] = tempListItem;
                        }
                        else
                        {
                            if ((x + 1 < Width && !isWalkable(x + 1, y)) ||
                                (x - 1 >= 0 && !isWalkable(x - 1, y)) ||
                                (y - 1 >= 0 && !isWalkable(x, y - 1)) ||
                                (y + 1 < Height && !isWalkable(x, y + 1)))
                            {
                                tempListItem.opened = false;
                                list[Location]      = tempListItem;
                                continue;
                            }
                            if (ColNode.unitOnTile == null)
                            {
                                tempListItem.G = 14 + list[new Point(Sx, Sy)].G;
                            }
                            else
                            {
                                tempListItem.G = 62 + list[new Point(Sx, Sy)].G;
                            }
                            tempListItem.opened  = true;
                            tempListItem.x       = x;
                            tempListItem.y       = y;
                            tempListItem.parentX = Sx;
                            tempListItem.parentY = Sy;
                            tempListItem.H       = calculateH(goalX, x) + calculateH(goalY, y);
                            tempListItem.F       = tempListItem.G + tempListItem.H;
                            openList.Add(tempListItem);
                            list[Location] = tempListItem;
                        }
                    }
                }
                if (!(list[new Point(Gx, Gy)].opened))
                {
                    int lowestF = 10000;
                    test = 0;
                    int ITEMS = openList.Count;
                    for (int index = 0; index < ITEMS; ++index)
                    {
                        test++;
                        if (openList[index].F < lowestF)
                        {
                            lowestF     = openList[index].F;
                            Sx          = openList[index].x;
                            Sy          = openList[index].y;
                            removeIndex = index;
                        }
                    }
                }
                //diplayCurrent(new Point(Sx, Sy));
            } while (test != 0 && !list[new Point(Gx, Gy)].opened && loops < 300);
            //diplayCurrent(new Point(Sx, Sy));
            if (test == 0 || loops > 249)
            {
                pathAvailable = false;
            }
            else
            {
                pathAvailable = true;
            }
        }