public static string Differences(EquipmentMaintenanceAct item1, EquipmentMaintenanceAct item2) { if (item1 == null || item2 == null) { return(string.Empty); } var res = new StringBuilder(); if (item1.Description != item2.Description) { res.Append("Operation:").Append(item2.Description).Append("; "); } if (item1.Observations != item2.Observations) { res.Append("Observations:").Append(item2.Observations).Append("; "); } if (item1.Date != item2.Date) { res.Append("Date:").Append(item2.Date).Append("; "); } if (item1.Expiration != item2.Expiration) { res.Append("Vto:").Append(item2.Expiration).Append("; "); } if (item1.Cost != item2.Cost) { res.Append("Cost:").Append(item2.Cost).Append("; "); } if (item1.Provider != null) { if (item2.Provider == null) { res.Append("Provider:null; "); } else if (item1.Provider.Id != item2.Provider.Id) { res.Append("Provider:").Append(item2.Provider.Id).Append("; "); } } else { if (item2.Provider != null) { res.Append("Provider:").Append(item2.Provider.Id).Append("; "); } } if (item1.Responsible.Id != item2.Responsible.Id) { res.Append("Responsible:").Append(item2.Responsible.Id).Append("; "); } return(res.ToString()); }
public static ReadOnlyCollection <EquipmentMaintenanceAct> GetByCompany(long equipmentId, int companyId) { /* CREATE PROCEDURE EquipmentMaintenanceAct_GetByEquipmentId * @EquipmentId bigint, * @CompanyId int */ var res = new List <EquipmentMaintenanceAct>(); using (var cmd = new SqlCommand("EquipmentMaintenanceAct_GetByEquipmentId")) { using (var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString)) { cmd.Connection = cnn; try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(DataParameter.Input("@EquipmentId", equipmentId)); cmd.Parameters.Add(DataParameter.Input("@CompanyId", companyId)); cmd.Connection.Open(); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { var newMaintenanceAct = new EquipmentMaintenanceAct { Id = rdr.GetInt64(ColumnsEquipmentMaintenanceActGet.Id), CompanyId = rdr.GetInt32(ColumnsEquipmentMaintenanceActGet.CompanyId), EquipmentId = rdr.GetInt64(ColumnsEquipmentMaintenanceActGet.EquipmentId), Description = rdr.GetString(ColumnsEquipmentMaintenanceActGet.Operation), Observations = rdr.GetString(ColumnsEquipmentMaintenanceActGet.Observations), Date = rdr.GetDateTime(ColumnsEquipmentMaintenanceActGet.Date), EquipmentMaintenanceDefinitionId = rdr.GetInt64(ColumnsEquipmentMaintenanceActGet.EquipmentMaintenanceDefinitionId), Expiration = rdr.GetDateTime(ColumnsEquipmentMaintenanceActGet.Expiration), Active = rdr.GetBoolean(ColumnsEquipmentMaintenanceActGet.Active), Provider = new Provider { Id = rdr.GetInt64(ColumnsEquipmentMaintenanceActGet.ProviderId), Description = rdr.GetString(ColumnsEquipmentMaintenanceActGet.ProviderDescription) }, Responsible = new Employee { Id = rdr.GetInt32(ColumnsEquipmentMaintenanceActGet.ResponsibleId), Name = rdr.GetString(ColumnsEquipmentMaintenanceActGet.ResponsibleName), LastName = rdr.GetString(ColumnsEquipmentMaintenanceActGet.ResponsibleLastName) }, ModifiedBy = new ApplicationUser { Id = rdr.GetInt32(ColumnsEquipmentMaintenanceActGet.ModifiedByUserId), UserName = rdr.GetString(ColumnsEquipmentMaintenanceActGet.ModifiedByUserName) }, ModifiedOn = rdr.GetDateTime(ColumnsEquipmentMaintenanceActGet.ModifiedOn) }; if (!rdr.IsDBNull(ColumnsEquipmentMaintenanceActGet.Cost)) { newMaintenanceAct.Cost = rdr.GetDecimal(ColumnsEquipmentMaintenanceActGet.Cost); } res.Add(newMaintenanceAct); } } } finally { if (cmd.Connection.State != ConnectionState.Closed) { cmd.Connection.Close(); } } } } return(new ReadOnlyCollection <EquipmentMaintenanceAct>(res)); }