Exemplo n.º 1
0
        private void removeOrderBtn_Click(object sender, EventArgs e)
        {
            Order ord = (Order)ordersListBox.SelectedItem;

            using (var db = new ProgramContext())
            {
                Order to_del = db.Orders.Where(o => o.OrderId == ord.OrderId).First();
                db.Orders.Remove(to_del);
                db.SaveChanges();
            }
            ReloadOrdersList();
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Sector obj = (Sector)listBox1.SelectedItem;

            using (var db = new ProgramContext())
            {
                Sector sec = (from s in db.Sectors
                              where s.SectorId == obj.SectorId
                              select s).FirstOrDefault();
                db.Sectors.Remove(sec);
                db.SaveChanges();
            }
            ReloadSectorsList();
        }
Exemplo n.º 3
0
        private void generateOrderBtn_Click(object sender, EventArgs e)
        {
            Order  ord  = new Order();
            Random rand = new Random();

            using (var db = new ProgramContext())
            {
                List <Medicine> medicines = db.Medicines.OrderBy(r => Guid.NewGuid()).Take(rand.Next(20)).ToList();
                ord.Medicines = medicines;
                db.Orders.Add(ord);
                db.SaveChanges();
            }
            ReloadOrdersList();
        }
Exemplo n.º 4
0
        private void remove_dist_to_Click(object sender, EventArgs e)
        {
            Distance obj = (Distance)list_to_distances.SelectedItem;

            using (var db = new ProgramContext())
            {
                Distance dist = (from d in db.Distances
                                 where d.DistanceId == obj.DistanceId
                                 select d).FirstOrDefault();
                db.Distances.Remove(dist);
                db.SaveChanges();
            }
            ReloadSectorsList();
            ReloadDistancesList();
        }
Exemplo n.º 5
0
        private void btn_add_sector_Click(object sender, EventArgs e)
        {
            string name = tb_new_sector_name.Text;
            Sector s    = new Sector {
                Name = name
            };

            using (var db = new ProgramContext())
            {
                db.Sectors.Add(s);
                db.SaveChanges();
            }
            ReloadSectorsList();
            ReloadSectorsFormsLists();
        }
Exemplo n.º 6
0
 public static void AddDistance(Sector from, Sector to, int val)
 {
     using (var db = new ProgramContext())
     {
         Sector   from_s = db.Sectors.Find(from.SectorId);
         Sector   to_s   = db.Sectors.Find(to.SectorId);
         Distance dist   = new Distance
         {
             SectorFrom   = from_s,
             SectorFromId = from_s.SectorId,
             SectorTo     = to_s,
             SectorToId   = to_s.SectorId,
             Value        = val
         };
         from_s.DistancesFrom.Add(dist);
         to_s.DistancesTo.Add(dist);
         db.Distances.Add(dist);
         db.SaveChanges();
     }
 }