internal static ProductionOrder GetById(int id) { var productionOrder = new ProductionOrder(); try { using (var connection = SqlServer.OpenConnection()) { var strSql = "SELECT Id, PalletId, MoldId, PartId, Status FROM ProductionOrders WHERE Id=@Id"; using (var command = new SqlCommand(strSql, connection)) { command.Parameters.AddWithValue("@Id", id); using (var reader = command.ExecuteReader()) { if (reader.Read()) { productionOrder.Id = int.Parse(reader["Id"].ToString()); productionOrder.Pallet = PalletRepository.GetById(int.Parse(reader["PalletId"].ToString())); productionOrder.Mold = MoldRepository.GetById(int.Parse(reader["MoldId"].ToString())); productionOrder.ActivePart = PartRepository.GetById(int.Parse(reader["PartId"].ToString())); productionOrder.Status = (ProductionOrderStatus)int.Parse(reader["Status"].ToString()); } } } } } catch (Exception ex) { //Introducir en el futuro codigo para NLog. } return(productionOrder); }
public static List <OperationRegister> GetLastOperations() { var operationRegisters = new List <OperationRegister>(); try { using (var connection = SqlServer.OpenConnection()) { const string strSql = "SELECT TOP 10 Id, OperationInId, OperationOutId, PalletId, MoldId, PartId, InitDateTime, EndDateTime FROM OperationRegisters WHERE EndDateTime IS NOT NULL ORDER BY EndDateTime DESC"; using (var command = new SqlCommand(strSql, connection)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { var operationRegister = new OperationRegister { Id = int.Parse(reader["Id"].ToString()), OperationIn = OperationRepository.GetById(int.Parse(reader["OperationInId"].ToString())), OperationOut = OperationRepository.GetById(int.Parse(reader["OperationOutId"].ToString())), Mold = MoldRepository.GetById(int.Parse(reader["MoldId"].ToString())), Pallet = PalletRepository.GetById(int.Parse(reader["PalletId"].ToString())) }; if (reader["PartId"] != DBNull.Value) { operationRegister.Part = PartRepository.GetById(int.Parse(reader["PartId"].ToString())); } operationRegister.InitDateTime = (DateTime)reader["InitDateTime"]; operationRegister.EndDateTime = (DateTime)reader["EndDateTime"]; operationRegisters.Add(operationRegister); } } } } return(operationRegisters); } catch (Exception ex) { // ReSharper disable once PossibleIntendedRethrow throw ex; } }
public static OperationRegister GetActiveByPallet(Pallet pallet) { var operationRegister = new OperationRegister(); try { using (var connection = SqlServer.OpenConnection()) { var strSql = "SELECT Id, OperationInId, PalletId, MoldId, PartId, InitDateTime FROM OperationRegisters WHERE PalletId=@PalletId AND EndDateTime IS NULL"; using (var command = new SqlCommand(strSql, connection)) { command.Parameters.AddWithValue("@PalletId", pallet.Id); using (var reader = command.ExecuteReader()) { if (reader.Read()) { operationRegister.Id = int.Parse(reader["Id"].ToString()); operationRegister.OperationIn = OperationRepository.GetById(int.Parse(reader["OperationInId"].ToString())); operationRegister.Mold = MoldRepository.GetById(int.Parse(reader["MoldId"].ToString())); operationRegister.Pallet = PalletRepository.GetById(int.Parse(reader["PalletId"].ToString())); if (reader["PartId"] != DBNull.Value) { operationRegister.Part = PartRepository.GetById(int.Parse(reader["PartId"].ToString())); } operationRegister.InitDateTime = (DateTime)reader["InitDateTime"]; } } } } } catch (Exception ex) { //Introducir en el futuro codigo para NLog. } return(operationRegister); }
internal static ProductionOrder GetActiveByPallet(Pallet pallet) { var productionOrder = new ProductionOrder(); try { using (var connection = SqlServer.OpenConnection()) { var strSql = "SELECT Id, PalletId, MoldId, PartId, Status FROM ProductionOrders WHERE Status = 1 AND PalletId=@PalletId"; using (var command = new SqlCommand(strSql, connection)) { command.Parameters.AddWithValue("@PalletId", pallet.Id); using (var reader = command.ExecuteReader()) { if (reader.Read()) { productionOrder.Id = int.Parse(reader["Id"].ToString()); productionOrder.Pallet = pallet; productionOrder.Mold = MoldRepository.GetById(int.Parse(reader["MoldId"].ToString())); if (reader["PartId"] != DBNull.Value) { productionOrder.ActivePart = PartRepository.GetById(int.Parse(reader["PartId"].ToString())); } productionOrder.Status = (ProductionOrderStatus)int.Parse(reader["Status"].ToString()); } } } } } catch (Exception ex) { throw ex; } return(productionOrder); }