Пример #1
0
        /// <summary>Gets diferrences between two verifications</summary>
        /// <param name="item1">Verification base</param>
        /// <param name="item2">Verification to caompare</param>
        /// <returns>String with differences</returns>
        public static string Differences(EquipmentVerificationAct item1, EquipmentVerificationAct item2)
        {
            if (item1 == null || item2 == null)
            {
                return(string.Empty);
            }

            var res = new StringBuilder();

            if (item1.Result != item2.Result)
            {
                res.Append("Result:").Append(item2.Result).Append("; ");
            }

            if (item1.MaxResult != item2.MaxResult)
            {
                res.Append("MaxResult:").Append(item2.MaxResult).Append("; ");
            }

            if (item1.Date != item2.Date)
            {
                res.Append("Date:").Append(item2.Date).Append("; ");
            }

            if (item1.Cost != item2.Cost)
            {
                res.Append("Cost:").Append(item2.Cost).Append("; ");
            }

            if (item1.Responsible.Id != item2.Responsible.Id)
            {
                res.Append("Responsible:").Append(item2.Responsible.Id).Append("; ");
            }

            return(res.ToString());
        }
Пример #2
0
        /// <summary>Gets verifications of an equipment from database</summary>
        /// <param name="equipmentId">Equipment identififer</param>
        /// <param name="companyId">Company identifier</param>
        /// <returns>List of verifications of an equipment from database</returns>
        public static ReadOnlyCollection <EquipmentVerificationAct> GetByCompany(long equipmentId, int companyId)
        {
            /* CREATE PROCEDURE EquipmentVerificationAct_GetByEquipmentId
             *   @EquipmentId bigint,
             *   @CompanyId int */
            var res = new List <EquipmentVerificationAct>();

            using (var cmd = new SqlCommand("EquipmentVerificationAct_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())
                            {
                                EquipmentVerificationAct newEquipmentVerificationAct = new EquipmentVerificationAct()
                                {
                                    Id          = rdr.GetInt64(ColumnsEquipmentVerificationActGet.Id),
                                    CompanyId   = rdr.GetInt32(ColumnsEquipmentVerificationActGet.CompanyId),
                                    EquipmentId = rdr.GetInt64(ColumnsEquipmentVerificationActGet.EquipmentId),
                                    Result      = rdr.GetDecimal(ColumnsEquipmentVerificationActGet.Result),
                                    MaxResult   = rdr.GetDecimal(ColumnsEquipmentVerificationActGet.MaxResult),
                                    Date        = rdr.GetDateTime(ColumnsEquipmentVerificationActGet.Date),
                                    Expiration  = rdr.GetDateTime(ColumnsEquipmentVerificationActGet.Expiration),
                                    EquipmentVerificationType = rdr.GetInt32(ColumnsEquipmentVerificationActGet.EquipmentVerificationType),
                                    Active   = rdr.GetBoolean(ColumnsEquipmentVerificationActGet.Active),
                                    Provider = new Provider()
                                    {
                                        Id          = rdr.GetInt64(ColumnsEquipmentVerificationActGet.ProviderId),
                                        Description = rdr.GetString(ColumnsEquipmentVerificationActGet.ProviderDescription)
                                    },
                                    Responsible = new Employee()
                                    {
                                        Id       = rdr.GetInt32(ColumnsEquipmentVerificationActGet.ResponsibleId),
                                        Name     = rdr.GetString(ColumnsEquipmentVerificationActGet.ResponsibleName),
                                        LastName = rdr.GetString(ColumnsEquipmentVerificationActGet.ResponsibleLastName)
                                    },
                                    ModifiedBy = new ApplicationUser()
                                    {
                                        Id       = rdr.GetInt32(ColumnsEquipmentVerificationActGet.ModifiedByUserId),
                                        UserName = rdr.GetString(ColumnsEquipmentVerificationActGet.ModifiedByUserName)
                                    },
                                    ModifiedOn = rdr.GetDateTime(ColumnsEquipmentVerificationActGet.ModifiedOn)
                                };

                                if (!rdr.IsDBNull(ColumnsEquipmentVerificationActGet.Cost))
                                {
                                    newEquipmentVerificationAct.Cost = rdr.GetDecimal(ColumnsEquipmentVerificationActGet.Cost);
                                }

                                res.Add(newEquipmentVerificationAct);
                            }
                        }
                    }
                    finally
                    {
                        if (cmd.Connection.State != ConnectionState.Closed)
                        {
                            cmd.Connection.Close();
                        }
                    }
                }
            }

            return(new ReadOnlyCollection <EquipmentVerificationAct>(res));
        }