private void btnObrisi_Click_1(object sender, EventArgs e) { if (selektovana == null || selektovana2 != null) { MessageBox.Show("Morate selektovati tacno jedan grad za brisanje!"); } else { Brisanje b = new Brisanje("Da li želite da obrišete grad?"); DialogResult dr = b.ShowDialog(); if (dr == DialogResult.OK) { if (selektovana != null) { foreach (PictureBox p in gradoviPanel1.Controls) { if (p.Tag.Equals(selektovana.Tag)) { gradoviPanel1.SuspendLayout(); int n = Lista.Instanca().listaRastojanja.Count; for (int k = 0; k < n; k++) { if (Lista.Instanca().listaRastojanja[k].g1.Tag.Equals(selektovana.Tag) || Lista.Instanca().listaRastojanja[k].g2.Tag.Equals(selektovana.Tag)) { Lista.Instanca().listaRastojanja.Remove(Lista.Instanca().listaRastojanja[k]); n--; k--; } } gradoviPanel1.resenje = null; tekuci = null; gradoviPanel1.Controls.Remove(p); // x -= 50; obrisana.Add(p); brisiKlik++; m++; i--; selektovana = null; gradoviPanel1.ResumeLayout(false); gradoviPanel1.Refresh(); break; } } } } } gradoviPanel1.Refresh(); }
public List <State> mogucaSledecaStanja() { bool nemojDodati = false; List <State> rezultat = new List <State>(); /* for (int i = 1; i < Gradovi.cBrojGradova; i++) * { * nemojDodati = false; * for (int j = 0; j < gradovi.Count; j++) * if (gradovi[j] == Gradovi.gradovi[i]) * nemojDodati = true; * * if (!nemojDodati) * rezultat.Add(sledeceStanje(Gradovi.gradovi[i])); * * }*/ for (int i = 0; i < Lista.Instanca().listaRastojanja.Count; i++) { PictureBox a = null; nemojDodati = false; if (grad.Tag.Equals(Lista.Instanca().listaRastojanja[i].g1.Tag)) { a = Lista.Instanca().listaRastojanja[i].g2; } if (grad.Tag.Equals(Lista.Instanca().listaRastojanja[i].g2.Tag)) { a = Lista.Instanca().listaRastojanja[i].g1; } if (a != null) { for (int j = 0; j < gradovi.Count; j++) { if (gradovi[j].Tag.Equals(a.Tag)) { nemojDodati = true; } } if (!nemojDodati) { rezultat.Add(sledeceStanje(a, Lista.Instanca().listaRastojanja[i].razd)); } } } return(rezultat); }
// int kk = 0; /* if (kk == 1) * { * MessageBox.Show("Ne postoji veza"); * return; * }*/ private void btnBrisivezu_Click(object sender, EventArgs e) { if (selektovana != null && selektovana2 != null) { Brisanje b = new Brisanje("Da li želite da obrišete vezu?"); DialogResult dr = b.ShowDialog(); if (dr == DialogResult.OK) { foreach (PictureBox p in gradoviPanel1.Controls) { if (p.Tag.Equals(selektovana.Tag)) { gradoviPanel1.SuspendLayout(); int n = Lista.Instanca().listaRastojanja.Count; for (int k = 0; k < n; k++) { if (Lista.Instanca().listaRastojanja[k].g1.Tag.Equals(selektovana.Tag) || Lista.Instanca().listaRastojanja[k].g2.Tag.Equals(selektovana2.Tag)) { Lista.Instanca().listaRastojanja.Remove(Lista.Instanca().listaRastojanja[k]); n--; k--; // kk = 1; break; } } gradoviPanel1.resenje = null; tekuci = null; gradoviPanel1.ResumeLayout(false); gradoviPanel1.Refresh(); break; } } } } else { MessageBox.Show("Morate selektovati dva grada za brisanje veze!"); } gradoviPanel1.Refresh(); }
private void pbPovezivanje_Click(object sender, EventArgs e) { if (selektovana != null && selektovana2 != null) { UnosRazdaljine udaljenost = new UnosRazdaljine(); if (udaljenost.ShowDialog() == DialogResult.OK) { Rastojanje r = new Rastojanje(); r.razd = udaljenost.razdaljina; r.g1 = selektovana; r.g2 = selektovana2; Lista.Instanca().listaRastojanja.Add(r); // Model.MemorisiDatoteku(); gradoviPanel1.Refresh(); } } else { MessageBox.Show("Dva grada moraju biti selektovana da bi se mogla povezati!"); } }
/* protected Lista(SerializationInfo info, StreamingContext context) * { * if (info == null) * throw new System.ArgumentNullException("info"); * listaa = (Lista)info.GetValue("AltName", typeof(Lista)); * * } * * * [SecurityPermission(SecurityAction.LinkDemand, * Flags = SecurityPermissionFlag.SerializationFormatter)] * public virtual void GetObjectData( * SerializationInfo info, StreamingContext context) * { * if (info == null) * throw new System.ArgumentNullException("info"); * info.AddValue("AltName", lista); * }*/ public void SAVE() { String fajl; SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Čuvanje fajla"; sfd.DefaultExt = "bin"; sfd.AddExtension = true; sfd.Filter = "Bin files(*.bin)|*.bin|All files(*.*)|*.*"; if (sfd.ShowDialog() == DialogResult.OK) { Lista lista = Lista.Instanca(); for (int i = 0; i < lista.listaRastojanja.Count; i++) { Image im1 = lista.listaRastojanja[i].g1.Image; String tag1 = lista.listaRastojanja[i].g1.Tag.ToString(); Point lok1 = lista.listaRastojanja[i].g1.Location; Size size1 = lista.listaRastojanja[i].g1.Size; Image im2 = lista.listaRastojanja[i].g2.Image; String tag2 = lista.listaRastojanja[i].g2.Tag.ToString(); Point lok2 = lista.listaRastojanja[i].g2.Location; Size size2 = lista.listaRastojanja[i].g2.Size; rastojanje = lista.listaRastojanja[i].razd; Dat dat = new Dat(im1, lok1, size1, tag1, im2, lok2, size2, tag2, rastojanje); listaDat.Add(dat); } IFormatter form = new BinaryFormatter(); fajl = sfd.FileName; Stream str = new FileStream(fajl, FileMode.Create, FileAccess.Write, FileShare.None); form.Serialize(str, listaDat); str.Close(); } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics gr = e.Graphics; gr.FillRectangle(Brushes.White, this.ClientRectangle); Rectangle rec = this.ClientRectangle; int width = rec.Width; int height = rec.Height; Font f = new Font(FontFamily.GenericSerif, 8); foreach (Rastojanje m in Lista.Instanca().listaRastojanja) { PictureBox g1 = m.g1; PictureBox g2 = m.g2; String razdaljina = m.razd.ToString(); float xx1 = (float)g1.Location.X; float yy1 = (float)g1.Location.Y; float xx2 = (float)g2.Location.X; float yy2 = (float)g2.Location.Y; gr.DrawLine(Pens.Green, xx1 + 10, yy1 + 10, xx2 + 10, yy2 + 10); gr.DrawString(razdaljina, f, Brushes.Black, (xx1 + xx2) / 2, (yy1 + yy2) / 2 - 2); } if (Main.tekuci != null) { State stanje = Main.tekuci[Main.tekuci.Count - 1]; int x = 140; int y = 30; int ss = 1; for (int i = 1; i < stanje.gradovi.Count; i++) { PictureBox g1 = stanje.gradovi[i - 1]; PictureBox g2 = stanje.gradovi[i]; Font fr = new Font(FontFamily.GenericSansSerif, 12); Font ff = new Font(FontFamily.GenericSansSerif, 10); gr.DrawString("Lista gradova: ", fr, Brushes.Gray, width - 140, 0); gr.DrawLine(Pens.Gray, width - 137, 20, width - 40, 20); gr.DrawLine(Pens.Gray, width - 142, 0, width - 142, height); if (i == 1) { // String tag = g1.Tag.ToString(); //Label l1 = new Label(); gr.DrawString(ss + "." + g1.Name, ff, Brushes.RosyBrown, width - x, y); ss++; //l1.Location= new Point(100,100); // l1.Visible = true; y += 20; } //String tag2 = g2.Tag.ToString(); //Label l2 = new Label(); // l2.Text = "wfwe"; gr.DrawString(ss + "." + g2.Name, ff, Brushes.RosyBrown, width - x, y); ss++; //l2.Visible = true; y += 20; float xx1 = (float)g1.Location.X; float yy1 = (float)g1.Location.Y; float xx2 = (float)g2.Location.X; float yy2 = (float)g2.Location.Y; gr.DrawLine(Pens.Red, xx1 + 10, yy1 + 10, xx2 + 10, yy2 + 10); } } }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { Lista.Instanca().SAVE(); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { Lista.Instanca().LOAD(); gradoviPanel1.SuspendLayout(); for (int i = 0; i < Lista.listaDat.Count; i++) { Dat d1 = Lista.listaDat[i]; PictureBox pb = new PictureBox(); pb.AllowDrop = false; pb.Location = d1.lokacija; pb.Size = d1.velicina; pb.Image = d1.slk; pb.Tag = d1.tag; // pb.Name = "grad " + chA.ToString(); //MessageBox.Show(pb.Name); pb.SizeMode = PictureBoxSizeMode.AutoSize; pb.MouseClick += new MouseEventHandler(gradoviPanel1_MouseClick); pb.MouseDown += new MouseEventHandler(pb_MouseDown); pb.MouseMove += new MouseEventHandler(pb_MouseMove); // a++; //i++; //MessageBox.Show(pb.Name); // listaGradova.Add(pb); PictureBox pb2 = new PictureBox(); pb2.AllowDrop = false; pb2.Location = d1.lokacija2; pb2.Size = d1.velicina2; pb2.Image = d1.slk2; pb2.Tag = d1.tag2; // pb.Name = "grad " + chA.ToString(); //MessageBox.Show(pb.Name); pb2.SizeMode = PictureBoxSizeMode.AutoSize; pb2.MouseClick += new MouseEventHandler(gradoviPanel1_MouseClick); pb2.MouseDown += new MouseEventHandler(pb_MouseDown); pb2.MouseMove += new MouseEventHandler(pb_MouseMove); // a++; //i++; //MessageBox.Show(pb.Name); gradoviPanel1.Controls.Add(pb); gradoviPanel1.Controls.Add(pb2); // listaGradova.Add(pb); Rastojanje r = new Rastojanje(); r.razd = d1.razdaljina; r.g1 = pb; r.g2 = pb2; // Model.MemorisiDatoteku(); // gradoviPanel1.Refresh(); Lista.Instanca().listaRastojanja.Add(r); } gradoviPanel1.ResumeLayout(false); gradoviPanel1.Refresh(); }