public void ObnovitMassuVMarshrutah(Poligon poligon) { //обновляем суммарную массу на авто в активных маршрутах List <MarshrutsALL> MA = new List <MarshrutsALL>(); try { //берем только активные маршруты на сегодня MA = db.MarshrutsAlls.Where(x => x.Date.Year == poligon.Date.Year && x.Date.Month == poligon.Date.Month && x.Date.Day == poligon.Date.Day && x.Type.Equals("A")).ToList(); foreach (MarshrutsALL M in MA) { string[] S = M.Avtomobils.Split(';'); decimal MassMusor = 0; foreach (string s in S) { try { int Id = Convert.ToInt32(s); MassMusor += db.Poligons.Where(x => x.Date.Year == poligon.Date.Year && x.Date.Month == poligon.Date.Month && x.Date.Day == poligon.Date.Day && x.AvtomobilId == Id).Sum(x => x.MassMusor); } catch { } } //сохраняем суммарную массу всех автомобилей M.MassaFact = Convert.ToInt32(MassMusor); db.Entry(M).State = EntityState.Modified; db.SaveChanges(); } } catch { } }
static void Main(string[] args) { Poligon NFigure = new Poligon(); Point P1 = new Point(0, 0); Point P2 = new Point(0, 2); Point P3 = new Point(1, 2); Point P4 = new Point(1, 0); NFigure.Points.Add(P1); NFigure.Points.Add(P2); NFigure.Points.Add(P3); NFigure.Points.Add(P4); double area = NFigure.Area; NFigure.Points.Remove(P4); area = NFigure.Area; Triangle triangle = new Triangle(5, 7.071, 5); area = triangle.Area; bool IsReg = triangle.IsTriangleRectan(); Triangle triangle_1 = new Triangle(); triangle_1.Points.Add(new Point(0, 0)); triangle_1.Points.Add(new Point(0, 4)); triangle_1.Points.Add(new Point(5, 0)); area = triangle_1.Area; IsReg = triangle_1.IsTriangleRectan(); }
static void Main(string[] args) { Console.Write("Введите количество точек: "); var poligon = new Poligon(Enumerable .Range(1, Int32.Parse(Console.ReadLine())) .Select(i => { Console.Write($"{i}. x и y: "); return(new Point(Console.ReadLine())); }).ToList()); var products = Enumerable .Range(0, Math.DivRem(poligon.Length, 3, out int rest) + rest) .Select(i => { var a = poligon.Next(); var b = poligon.Next(); var c = poligon.Next(); var ab = (x: b.X - a.X, y: b.Y - a.Y); var bc = (x: c.X - b.X, y: c.Y - b.Y); return(ab.x * bc.y - ab.y * bc.x); }); Console.WriteLine(products.All(i => i == products.First()) ? "Выпуклый" : "Невыпуклый"); Console.ReadKey(); }
public ActionResult DeleteConfirmed(int id) { Poligon poligon = db.Poligons.Find(id); db.Poligons.Remove(poligon); db.SaveChanges(); return(RedirectToAction("Index")); }
public void TestPoligon(int x1, int y1, int x2, int y2, int n, int[] ExPoints) { Poligon Actual = new Poligon(); bool ActualPoint = Actual.CheckForMatches(x1, y1, x2, y2, n, ExPoints); bool Expected = true; Assert.AreEqual(Expected, ActualPoint); }
public ActionResult Edit([Bind(Include = "Id,Number,Date,MassIn,MassOut,Description,AvtomobilId")] Poligon poligon) { if (ModelState.IsValid) { db.Entry(poligon).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(poligon)); }
static void Main(string[] args) { Tacka[] ulaz = new Tacka[3]; /* Primer prostog poligona */ /* * ulaz[0] = new Tacka(2, 2); * ulaz[1] = new Tacka(2, 1); * ulaz[2] = new Tacka(1, 1); * ulaz[3] = new Tacka(1, 2); */ ulaz[0] = new Tacka(1, 2); ulaz[1] = new Tacka(1, 1); ulaz[2] = new Tacka(2, 1); // ulaz[3] = new Tacka(2, 2); /* prost * ulaz[0] = new Tacka(-5.5, 0.5); * ulaz[1] = new Tacka(-3.5, -1.5); * ulaz[2] = new Tacka(-2, 0.0); * ulaz[3] = new Tacka(-0.2, -1.4); * ulaz[4] = new Tacka(0.5, 3.9); * ulaz[5] = new Tacka(-3.0, 4.2); * ulaz[6] = new Tacka(-3.3, 2.0); */ /* nije prost * ulaz[0] = new Tacka(-5.5, 0.5); * ulaz[1] = new Tacka(-3.5, -1.5); * ulaz[2] = new Tacka(1, 0.0); * ulaz[3] = new Tacka(-0.2, -1.4); * ulaz[4] = new Tacka(0.5, 3.9); * ulaz[5] = new Tacka(-3.0, 4.2); * ulaz[6] = new Tacka(-3.3, 2.0); */ Poligon poli = new Poligon(ulaz); poli.Stampaj(); if (poli.Prost()) { Console.WriteLine("Prost"); } else { Console.WriteLine("Nije"); } Poligon dva = poli.Omotac(); dva.Stampaj(); Console.WriteLine("Poligon"); }
public void SetOnMap(List <Line> lines, Poligon poligon) { foreach (var line in lines) { DrawGuidLine(line.StartPoint.X, line.StartPoint.Y, line.EndPoint.X, line.EndPoint.Y, line.Width, line.Guid); } }
public void Poligon_Area_Calc() //Проверка площади произвольного полигона { Poligon poligon = new Poligon(); poligon.Points.Add(new Point(1, 2)); poligon.Points.Add(new Point(3, 4)); poligon.Points.Add(new Point(6, 6)); poligon.Points.Add(new Point(5, 1)); poligon.Points.Add(new Point(4, 2)); double expected = 10; double result = poligon.Area; Assert.AreEqual(expected, result); }
private void StartDrawingPolygon() { if (Clicks.Count == 1) { Poligon poligon = new Poligon(Drawing, GuidMapLogic); CurrentPolygon = poligon; GraphicObjects.Add(poligon.Guid, poligon); return; } var line = new Line(Clicks[Clicks.Count - 2], Clicks.Last(), Width, Drawing, GuidMapLogic, CurrentPolygon); CurrentPolygon.AddLine(line); line.DrawItself(); }
// GET: Poligons/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Poligon poligon = db.Poligons.Find(id); if (poligon == null) { return(HttpNotFound()); } return(View(poligon)); }
public void SetOnMap(Poligon poligon) { foreach (var line in poligon.Lines) { DrawGuidLine(line.StartPoint.X, line.StartPoint.Y, line.EndPoint.X, line.EndPoint.Y, line.Width, line.Guid); } foreach (var verticle in poligon.Verticies) { SetGuid(verticle.Point.X, verticle.Point.Y, verticle.Guid, Consts.MediumWidth); } }
public ActionResult Resultat(string Date) { DateTime D = DateTime.Now; if (Date != null) { ViewBag.Date = Date; } else { ViewBag.Date = D; } List <Avtomobil> A = new List <Avtomobil>(); List <Poligon> Result = new List <Poligon>(); try { List <Poligon> dbPoligons = db.Poligons.Where(x => x.Date.Year == D.Year && x.Date.Month == D.Month && x.Date.Day == D.Day).Include(x => x.Avtomobil).Include(x => x.Avtomobil.Marka).Include(x => x.Avtomobil.Type).ToList(); A = dbPoligons.Where(x => x.Date.Year == D.Year && x.Date.Month == D.Month && x.Date.Day == D.Day).Select(x => x.Avtomobil).Distinct().ToList(); foreach (Avtomobil Avto in A) { List <Poligon> TekPol = dbPoligons.Where(x => x.AvtomobilId == Avto.Id).ToList(); Poligon P = new Poligon(); P.MassIn = TekPol.Where(x => x.AvtomobilId == Avto.Id).Sum(x => x.MassIn); P.MassOut = TekPol.Sum(x => x.MassOut); P.MassMusor = TekPol.Sum(x => x.MassMusor); P.AvtomobilId = Avto.Id; P.Avtomobil = Avto; P.Date = DateTime.Now; P.Description = TekPol.Count().ToString(); P.TypeId = Avto.TypeId; P.MarkaId = Avto.MarkaId; P.Number = Avto.Number; Result.Add(P); } } catch (Exception e) { } return(View(Result)); }
private void DeleteObject() { if (SelectedObject.GraphicObjectType == GraphicObjectType.Verticle) { Verticle verticle = (SelectedObject as Verticle); Line line = (verticle.ParentGraphicObject as Line); Poligon poligon = line.ParentGraphicObject != null ? line.ParentGraphicObject as Poligon : null; if (poligon == null) { return; } else { var lineToDelete = poligon.DeleteVerticle(verticle); GraphicObjects.Remove(lineToDelete.Guid); GraphicObjects.Remove(verticle.Guid); } } else if (SelectedObject.GraphicObjectType == GraphicObjectType.Line) { Line line = (SelectedObject as Line); if (line.ParentGraphicObject == null) { GraphicObjects.Remove(line.StartVerticle.Guid); GraphicObjects.Remove(line.EndVerticle.Guid); GraphicObjects.Remove(line.Guid); } else { Poligon poligon = line.ParentGraphicObject as Poligon; poligon.Lines.ForEach(x => GraphicObjects.Remove(x.Guid)); poligon.Verticies.ForEach(x => GraphicObjects.Remove(x.Guid)); GraphicObjects.Remove(poligon.Guid); } } else if (SelectedObject.GraphicObjectType == GraphicObjectType.Circle) { GraphicObjects.Remove(SelectedObject.Guid); } SelectedObject = null; Redraw(); }
public JsonResult MassOutEdit(decimal massOut, int id) { Poligon P = new Poligon(); try { P = db.Poligons.Where(x => x.Id == id).First(); P.MassOut = massOut; P.MassMusor = P.MassIn - P.MassOut; db.Entry(P).State = EntityState.Modified; db.SaveChanges(); ObnovitMassuVMarshrutah(P); return(Json("Ok")); } catch { return(Json("Error")); } }
public ActionResult DeleteZaezd(int id) { Poligon P = new Poligon(); Poligon PTF = new Poligon(); try { P = db.Poligons.Where(x => x.Id == id).First(); PTF = P; db.Poligons.Remove(P); db.SaveChanges(); ObnovitMassuVMarshrutah(PTF); } catch { } ViewBag.TypeAvtos = new SelectList(db.TypeAvtos, "Id", "Type"); ViewBag.MarkaAvtomobils = new SelectList(db.MarkaAvtomobils.OrderBy(x => x.Name), "Id", "Name"); ViewBag.AvtoType = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Type).First(); ViewBag.AvtoImage = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Ico).First(); return(RedirectToAction("Index")); }
public Poligon Omotac() { // Domaci 5 - formiraj konveksni omotac List <Tacka> Omotac_lista = new List <Tacka>(); List <Tacka> Kandidati = new List <Tacka>(); for (int i = 0; i < Temena.Length; i++) { Kandidati.Add(Temena[i]); } //trazimo ekstremnu tacku double minx = Kandidati[0].x; double miny = Kandidati[0].y; int MinTackaIndeks = 0; for (int i = 1; i < Kandidati.Count; i++) { if (Kandidati[i].x <= minx) { if (Kandidati[i].y <= miny) { minx = Kandidati[i].x; miny = Kandidati[i].y; MinTackaIndeks = i; } } } // nasli smo ekstremnu tacku Console.WriteLine("ekstremna tacka" + MinTackaIndeks + ":" + Kandidati[MinTackaIndeks].x + " " + Kandidati[MinTackaIndeks].y); Omotac_lista.Add(Kandidati[MinTackaIndeks]); Tacka pocetna = Kandidati[MinTackaIndeks]; Kandidati.Remove(Kandidati[MinTackaIndeks]); Console.WriteLine("Kandidati pre:"); for (int i = 0; i < Kandidati.Count; i++) { Console.WriteLine(Kandidati[i].x + " - " + Kandidati[i].y); } // od preostalih tacaka nadji onu sa najmanjim uglom sa x osom => A1 double Min_ugao = 200; int ind_Min_ugao = 0; Vektor prvi = Vektor.jedinicni_i(); Vektor drugi; for (int i = 0; i < Kandidati.Count; i++) { Tacka polazna = Omotac_lista[Omotac_lista.Count - 1]; Tacka krajnja = new Tacka(Kandidati[i]); drugi = new Vektor(polazna, krajnja); double Ugao = Vektor.Ugao(prvi, drugi); if (Ugao < Min_ugao) { Min_ugao = Ugao; ind_Min_ugao = i; } } // Dodaj Temena[i] u Omotac Tacka dodajem = Kandidati[ind_Min_ugao]; Kandidati.RemoveAt(ind_Min_ugao); Kandidati.Add(pocetna); Console.WriteLine("Kandidati posle:"); for (int i = 0; i < Kandidati.Count; i++) { Console.WriteLine(Kandidati[i].x + " - " + Kandidati[i].y); } Console.WriteLine("ind min ugao = " + ind_Min_ugao); // U odnosu na poslednje dve dodate tacke while (dodajem != pocetna) { Console.WriteLine("Dodajem:" + dodajem.x + " " + dodajem.y); Omotac_lista.Add(dodajem); // uzmi poslednje dve tacke u omotacu i napravi vektor v_1 Tacka Poslednja_u_Om = (Tacka)Omotac_lista[Omotac_lista.Count - 1]; Tacka Pretposlednja_u_Om = (Tacka)Omotac_lista[Omotac_lista.Count - 2]; Vektor v_1 = new Vektor(Pretposlednja_u_Om, Poslednja_u_Om); // napravi vektor iz poslednje tacke omotaca sa preostalim tackama Min_ugao = 200; for (int i = 0; i < Kandidati.Count; i++) { Console.WriteLine(Poslednja_u_Om.x + "/" + Poslednja_u_Om.y + " K:" + Kandidati[i].x + " " + Kandidati[i].y); Vektor v_2 = new Vektor(Poslednja_u_Om, Kandidati[i]); double Ugao = Vektor.Ugao(v_1, v_2); Console.WriteLine(" Ostali " + Ugao); if (Ugao < Min_ugao) { Min_ugao = Ugao; ind_Min_ugao = i; } } Console.WriteLine("Pobedio " + ind_Min_ugao); dodajem = Kandidati[ind_Min_ugao]; Kandidati.RemoveAt(ind_Min_ugao); } Tacka[] Omotac_niz = new Tacka[Omotac_lista.Count]; for (int i = 0; i < Omotac_lista.Count; i++) { Omotac_niz[i] = new Tacka((Tacka)Omotac_lista[i]); } Poligon Omotac = new Poligon(Omotac_niz); return(Omotac); }
private void createCurrentShape() { switch (drawing) { case CurrentDrawing.Ellipse: Ellipse ellipse = new Ellipse(); ellipse.setFillColor(this.currentFillColor); ellipse.setBorderColor(this.currentBorderColor); this.shape = ellipse; break; case CurrentDrawing.Circle: Circle circle = new Circle(); circle.setFillColor(this.currentFillColor); circle.setBorderColor(this.currentBorderColor); this.shape = circle; break; case CurrentDrawing.Line: Shape line = new Line(); line.setBorderColor(this.currentBorderColor); this.shape = line; break; case CurrentDrawing.Ray: Shape ray = new Ray(); ray.setBorderColor(this.currentBorderColor); this.shape = ray; break; case CurrentDrawing.LineSegment: Shape lineSegment = new LineSegment(); lineSegment.setBorderColor(this.currentBorderColor); this.shape = lineSegment; break; case CurrentDrawing.Poligon: Poligon poligon = new Poligon(); poligon.setFillColor(this.currentFillColor); poligon.setBorderColor(this.currentBorderColor); this.shape = poligon; break; case CurrentDrawing.RegularPolygon: RegularPolygon regularPoligon = new RegularPolygon((int)this.numericUpDown1.Value); regularPoligon.setFillColor(this.currentFillColor); regularPoligon.setBorderColor(this.currentBorderColor); this.shape = regularPoligon; break; case CurrentDrawing.RightTriangle: RightTriangle rightTriangle = new RightTriangle(); rightTriangle.setFillColor(this.currentFillColor); rightTriangle.setBorderColor(this.currentBorderColor); this.shape = rightTriangle; break; case CurrentDrawing.IsoscelesTriangle: IsoscelesTriangle isoscelesTriangle = new IsoscelesTriangle(); isoscelesTriangle.setFillColor(this.currentFillColor); isoscelesTriangle.setBorderColor(this.currentBorderColor); this.shape = isoscelesTriangle; break; case CurrentDrawing.Parallelogram: Parallelogram parallelogram = new Parallelogram(); parallelogram.setFillColor(this.currentFillColor); parallelogram.setBorderColor(this.currentBorderColor); this.shape = parallelogram; break; case CurrentDrawing.Rectangle: Rectangle rectangle = new Rectangle(); rectangle.setFillColor(this.currentFillColor); rectangle.setBorderColor(this.currentBorderColor); this.shape = rectangle; break; case CurrentDrawing.Rhomb: Rhomb rhomb = new Rhomb(); rhomb.setFillColor(this.currentFillColor); rhomb.setBorderColor(this.currentBorderColor); this.shape = rhomb; break; } }
public ActionResult Create([Bind(Include = "Number,MassIn,MassOut,Description,Marka,TypeId,KontrAgentId,VibralRab")] Poligon poligon) { poligon.Date = DateTime.Now; poligon.AvtomobilId = 0; poligon.Number = poligon.Number.Replace(" ", "").ToUpper(); poligon.User = User.Identity.Name; HttpCookie cookieReq = Request.Cookies["Poligon"]; if (cookieReq != null) { poligon.Date = Convert.ToDateTime(cookieReq["Date"]); } if (poligon.Date.Day == DateTime.Now.Day && poligon.Date.Month == DateTime.Now.Month && poligon.Date.Year == DateTime.Now.Year) { poligon.Date = DateTime.Now; } Avtomobil A = new Avtomobil(); try { A = db.Avtomobils.Where(x => x.Number.Replace(" ", "").Equals(poligon.Number)).Include(x => x.Marka).Include(x => x.Type).Include(x => x.KontrAgent).First(); poligon.AvtomobilId = A.Id; poligon.MarkaId = A.Marka.Id; poligon.TypeId = A.Type.Id; if (poligon.VibralRab == false) { if (A.KontrAgent.Id != poligon.KontrAgentId) { poligon.KontrAgentId = A.KontrAgent.Id; } } poligon.KontrAgentName = db.KontrAgents.Where(x => x.Id == poligon.KontrAgentId).Select(x => x.Name).First(); } catch (Exception e) { A.Number = poligon.Number; A.Glonass = false; A.Garage = 0; A.GKHNNC = false; A.KoefficientSgatiya = 1; A.ObiemBunkera = 0; A.TypeId = poligon.TypeId; return(RedirectToAction("Index", new { Number = poligon.Number })); //если не нашли по номеру в бд то отправляем создать новый } if (poligon.Description == null) { poligon.Description = "В пределах нормы."; if (poligon.MassIn == 0) { poligon.MassIn = Math.Round(A.ObiemBunkera * A.KoefficientSgatiya * 165.1M, 2); poligon.MassOut = 0; } } else { poligon.MassIn = 0; poligon.MassOut = 0; } try { //сохраняем изменения poligon.MassMusor = poligon.MassIn - poligon.MassOut; db.Poligons.Add(poligon); db.SaveChanges(); //обновляем суммарную массу на авто в активных маршрутах ObnovitMassuVMarshrutah(poligon); } catch (Exception e) { } ViewBag.Number = poligon.Number; ViewBag.TypeAvtos = new SelectList(db.TypeAvtos, "Id", "Type"); ViewBag.MarkaAvtomobils = new SelectList(db.MarkaAvtomobils.OrderBy(x => x.Name), "Id", "Name"); ViewBag.Numbers = A; ViewBag.AvtoType = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Type).First(); ViewBag.AvtoImage = db.TypeAvtos.Where(x => x.Id == 16).Select(x => x.Ico).First(); return(RedirectToAction("Index", new { number = poligon.Number })); }