public void CreatePedido() { if (Id != 0) { throw new MercurioCoreException("Objeto já criado no Banco de Dados"); } if (Rota == null || Items.Count == 0) { throw new MercurioCoreException("Falta dados para a criação"); } if (Rota.Id == 0) { Rota.CreateRota(); } foreach (Item i in Items) { if (i.Id == 0) { i.CreateItem(); } } if (Usuario.Id == 0) { Usuario.CreateUsuario(); } PedidoManipulation item = new PedidoManipulation(); Pedido novo = item.Create(this); Id = novo.Id; }
public void UpdatePedido() { foreach (Item i in Items) { if (i.Id == 0) { i.CreateItem(); } } if (Rota.Id == 0) { Rota.CreateRota(); } PedidoManipulation item = new PedidoManipulation(); item.Update(this); foreach (Item i in Items) { if (i.RemoveItem) { Items.Remove(i); } } }
internal Pedido(Usuario usuario, DateTime dataCriacao, Rota rota, List <Item> items, bool pedidoEntregue) : base("pedido", "IdPedido") { Usuario = usuario; DataCriacao = dataCriacao; Rota = rota; Items = items; PedidoEntregue = pedidoEntregue; }
public void ChangeItem(int id) { RotaManipulation item = new RotaManipulation(); Rota i = item.FindByID(id); Id = id; SensorFinal = i.SensorFinal; SensorInicial = i.SensorInicial; Tracado = i.Tracado; }
internal Rota(int id) : base("rota", "IdRota") { if (base.Exists(id)) { RotaManipulation item = new RotaManipulation(); Rota i = item.FindByID(id); Id = id; SensorFinal = i.SensorFinal; SensorInicial = i.SensorInicial; Tracado = i.Tracado; } }
public void UpdateTodasRotas() { var rotas = Rota.FindAll(); string tracado = string.Empty; foreach (Rota r in rotas) { tracado = r.Tracado; if (tracado != r.GerarRota()) { r.UpdateItem(); } } }
internal void GenerateHash() { HashRota = ""; Rota rota = Pedido.Rota; string[] tracado = rota.Tracado.Split(';'); foreach (string s in tracado) { if (!string.IsNullOrWhiteSpace(s)) { Sensor sensor = Sensor.FindById(Convert.ToInt32(s.Split('-')[0])); HashRota += sensor.Hash + ";"; } } }
public Pedido FindByID(long id) { List <Item> itens = new List <Item>(); Usuario pedinte = null; Rota rota = null; bool pedidoEntregue = false; DateTime dataPedido = new DateTime(); string sql = string.Format(@"SELECT IdUsuario, DataCriacao, IdRota, PedidoEntregue FROM projetomercurio.pedido p WHERE p.IdPedido={0} ", id); MySqlDataReader result = connection.SendQuery(sql); if (result.HasRows) { result.Read(); pedinte = new Usuario((int)result["IdUsuario"]); dataPedido = (DateTime)result["DataCriacao"]; rota = new Rota((int)result["IdRota"]); pedidoEntregue = (bool)result["PedidoEntregue"]; result.Close(); } else { throw new DBConnectionException("Nenhum Pedido encontrado"); } sql = string.Format("SELECT IdItem, IdPedidoxItem, Quantidade FROM projetomercurio.PedidoXItem WHERE IdPedido = {0}", id); MySqlDataReader result2 = connection.SendQuery(sql); if (result2.HasRows) { while (result2.Read()) { Item item2 = new Item((int)result2["IdItem"]); item2.IdPedidoxItem = (int)result2["IdPedidoxItem"]; item2.Quantidade = (int)result2["Quantidade"]; itens.Add(item2); } } result2.Close(); Pedido pedido = new Pedido(Convert.ToInt32(id), pedinte, dataPedido, rota, itens, pedidoEntregue); return(pedido); }
public void CreateRota() { if (Id != 0) { throw new MercurioCoreException("Objeto já criado no Banco de Dados"); } int idRetornado = Exist(); if (idRetornado != 0) { Id = idRetornado; Console.WriteLine("Já existe"); } else { RotaManipulation item = new RotaManipulation(); Rota novo = item.Create(this); Id = novo.Id; Console.WriteLine("Novo Id"); } }
public void SetRota(Rota rota) { Rota = rota; }
public void SetRota(Sensor inicial, Sensor final) { Rota rota = new Rota(inicial, final); Rota = rota; }