Exemplo n.º 1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            d = GetDijkstra();
            var db = new ProgramContext();

            sec_0_id = db.Sectors.Where(sec => sec.Name == "0").First().SectorId;
            Application.Run(new Form1());
        }
Exemplo n.º 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            ReloadSectorsList();
            ReloadDistancesList();
            ReloadSectorsFormsLists();
            ReloadOrdersList();
            var db = new ProgramContext();

            db.Medicines.Load();
            medicineBindingSource.DataSource = db.Medicines.Local.ToList();
        }
Exemplo n.º 3
0
 internal static void LoadMedicines()
 {
     using (var db = new ProgramContext())
     {
         var medicines = db.Medicines.ToList();
         if (medicines.Count == 0)
         {
             LoadMedicines_();
         }
     }
 }
Exemplo n.º 4
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.º 5
0
        public override string ToString()
        {
            Sector sec;
            string str;

            using (var db = new ProgramContext())
            {
                sec = db.Sectors.Where(s => s.SectorId == SectorID).First();
                str = string.Format("{0}, {1}, {2}", Name, Price, sec.SectorId);
            }
            return(str);
        }
Exemplo n.º 6
0
        private void ReloadSectorsList()
        {
            BindingList <Sector> sectors = new BindingList <Sector>();

            using (var db = new ProgramContext())
            {
                foreach (var s in db.Sectors)
                {
                    sectors.Add(s);
                }
                listBox1.DataSource = sectors;
            }
        }
Exemplo n.º 7
0
        private void ReloadOrdersList()
        {
            BindingList <Order> orders = new BindingList <Order>();

            using (var db = new ProgramContext())
            {
                foreach (var o in db.Orders)
                {
                    orders.Add(o);
                }
                ordersListBox.DataSource = orders;
            }
        }
Exemplo n.º 8
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.º 9
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.º 10
0
        private void ordersListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindingList <Medicine> medicines = new BindingList <Medicine>();
            Order ord = (Order)ordersListBox.SelectedItem;

            using (var db = new ProgramContext())
            {
                foreach (var med in db.Orders.Where(o => o.OrderId == ord.OrderId).First().Medicines.ToList())
                {
                    medicines.Add(med);
                }
            }
            medicinesListBox.DataSource = medicines;
        }
Exemplo n.º 11
0
        public static Dijkstra GetDijkstra()
        {
            List <Sector>   sectors;
            List <Distance> distances;

            using (var db = new ProgramContext())
            {
                sectors   = db.Sectors.ToList();
                distances = db.Distances.ToList();
            }
            Dijkstra d = new Dijkstra(sectors, distances);

            return(d);
        }
Exemplo n.º 12
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.º 13
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.º 14
0
        private void ReloadSectorsFormsLists()
        {
            BindingList <Sector> from_sectors = new BindingList <Sector>();
            BindingList <Sector> to_sectors   = new BindingList <Sector>();

            using (var db = new ProgramContext())
            {
                foreach (var s in db.Sectors)
                {
                    from_sectors.Add(s);
                    to_sectors.Add(s);
                }
            }
            comboBox_from.DataSource = from_sectors;
            comboBox_to.DataSource   = to_sectors;
        }
Exemplo n.º 15
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();
     }
 }
Exemplo n.º 16
0
        private void RunAlgo()
        {
            var             db        = new ProgramContext();
            List <Medicine> medicines = new List <Medicine>();

            foreach (Order ord in db.Orders.ToList())
            {
                medicines.AddRange(ord.Medicines);
            }
            int   numWorkers     = (int)nWorkers.Value;
            int   limitMedicines = (int)limit.Value;
            float T0             = (float)t0.Value;
            float Tk             = (float)tk.Value;
            float Lambda         = (float)lambd.Value;

            if (numWorkers * limitMedicines < medicines.Count)
            {
                return;
            }
            algo = new SA(numWorkers, limitMedicines, medicines, T0, Tk, Lambda);
            algo.Run();
        }