Example #1
0
        //public static IEnumerable<string[,]> GetDataTables(params IEnumerable[] collections)
        //{
        //    if (collections == null) return null;

        //    List<string[,]> array = new List<string[,]>();

        //    foreach (IEnumerable collection in collections)
        //        array.Add(GetDataTable(collection));

        //    return array;
        //}

        public static string[,] GetDataTable <T>(IEnumerable <T> collection)
        {
            if (collection == null || !collection.Any())
            {
                return(new string[0, 0]);
            }

            var first = collection.First();

            return
                (first is Meter
                    ? Meter.GetDataTableOfMeters(collection.Cast <Meter>())
                    : first is Document
                        ? Document.GetDataTableOfDocuments(collection.Cast <Document>())
                        : first is Parametr
                            ? Parametr.GetDataTableOfParametrs(collection.Cast <Parametr>())
                            : first is Reading
                                ? Reading.GetDataTableOfReadings(collection.Cast <Reading>())
                                : first is Tariff
                                    ? Tariff.GetDataTableOfTariffs(collection.Cast <Tariff>())
                                    : first is TimeSpan
                                        ? TimeSpan.GetDataTableOfTimeSpans(collection.Cast <TimeSpan>())
                                        : first is Type
                                            ? Type.GetDataTableOfTypes(collection.Cast <Type>())
                                            : first is User
                                                ? User.GetDataTableOfUsers(collection.Cast <User>())
                                                : new string[0, 0]);
        }
        public void Add(string name, string description, double capacity, long productionId, DateTime productionDate, DateTime expirationDate, ICollection <Parametr> parameters, Tariff tariff, Type type, ICollection <Document> documents, User user, ICollection <Reading> readings)
        {
            InstalledMeter met = new InstalledMeter();

            met.Name           = name;
            met.Discription    = description;
            met.Capacity       = capacity;
            met.ProductionId   = productionId;
            met.ProductionDate = productionDate;
            met.InstallDate    = DateTime.Now;
            met.ExpirationDate = expirationDate;

            foreach (var parameter in parameters)
            {
                parameter.Meters.Add(met);
            }

            met.Parametrs = parameters;

            tariff.Meters.Add(met);
            met.Tariff = tariff;

            type.Meters.Add(met);
            met.Type = type;

            foreach (var document in documents)
            {
                document.Meter = met;
            }
            met.Documents = documents;

            user.Meters.Add(met);
            met.User = user;

            met.SumReadings = 0;
            foreach (var reading in readings)
            {
                reading.Meter    = met;
                met.SumReadings += reading.Value;
            }
            met.Readings = readings;

            cont.SaveChanges();
        }