예제 #1
0
        public static int Update(this SqlConnection connection, string table, KeyValuePairs kvs, int[] ids)
        {
            if (string.IsNullOrWhiteSpace(table))
            {
                throw new ArgumentNullException(nameof(table), "数据表不能为空");
            }
            if (kvs == null || kvs.Any(kv => kv.Key == "Id"))
            {
                throw new ArgumentNullException(nameof(kvs), "要更新的列不能为空,并且不能包含Id列");
            }
            if (ids == null || !ids.Any())
            {
                throw new ArgumentNullException(nameof(ids), "ID数组不能为空");
            }

            var columns = new List <string>();
            var param   = new DynamicParameters();

            param.Add("Ids", ids);
            foreach (var kv in kvs.Where(kv => kv.Key != "Id"))
            {
                columns.Add($"{kv.Key}=@{kv.Key}");
                param.Add(kv.Key, kv.Value);
            }
            var sql = $"UPDATE [{table}] SET {string.Join(",", columns)} WHERE Id in @Ids";

            return(connection.Execute(sql, param));
        }
예제 #2
0
        /// <summary>
        /// Find if any of the URI values has been set in the connection string
        /// </summary>
        /// <returns>First non empty URI value</returns>
        private string FirstNonNullUriInConnectionString()
        {
            string nonEmptyUriKeyName = string.Empty;
            var    nonEmptyUriList    = KeyValuePairs.Where(item =>
            {
                return((item.Key.Contains("uri") ||
                        (item.Key.Equals(ConnectionStringKeys.AADAuthUriKey))) && (!string.IsNullOrEmpty(item.Value)));
            });

            if (nonEmptyUriList.IsAny <KeyValuePair <string, string> >())
            {
                nonEmptyUriKeyName = nonEmptyUriList.FirstOrDefault().Key;
            }

            return(nonEmptyUriKeyName);
        }
예제 #3
0
 public List <int> getNewCollections(bool betterThanAvg)
 {
     if (betterThanAvg)
     {
         return(KeyValuePairs.Where(x => x.Value.Worth >= AverageCollectionWorth &&
                                    x.Value.Photographs.Count == 0)
                .OrderByDescending(x => x.Value.Worth)
                .ToDictionary(z => z.Key, y => y.Value).Keys.ToList());
     }
     else
     {
         return(KeyValuePairs.Where(x => x.Value.Worth < AverageCollectionWorth &&
                                    x.Value.Photographs.Count == 0)
                .OrderByDescending(x => x.Value.Worth)
                .ToDictionary(z => z.Key, y => y.Value).Keys.ToList());
     }
 }
예제 #4
0
        //// Test test
        //public void SortGenes(int satelliteId)
        //{
        //    Chromosome[satelliteId] = Chromosome[satelliteId].OrderBy(o => o.Turn).ToList();
        //}



        #region Filter_CollectionsList

        public List <int> getBestIncompleteCollections(bool nearlyFilled)
        {
            if (nearlyFilled)
            {
                return(KeyValuePairs.Where(x => x.Value.Worth >= AverageCollectionWorth &&
                                           (double)x.Value.L / 2 < x.Value.Photographs.Count() &&
                                           x.Value.L > x.Value.Photographs.Count())
                       .OrderByDescending(x => x.Value.Worth)
                       .ToDictionary(z => z.Key, y => y.Value).Keys.ToList());
            }
            else
            {
                return(KeyValuePairs.Where(x => x.Value.Worth >= AverageCollectionWorth &&
                                           (double)x.Value.L / 2 > x.Value.Photographs.Count() &&
                                           x.Value.L > x.Value.Photographs.Count())
                       .OrderByDescending(x => x.Value.Worth)
                       .ToDictionary(z => z.Key, y => y.Value).Keys.ToList());
            }
        }
예제 #5
0
        public static int Update(this SqlConnection connection, string table, KeyValuePairs kvs, MySearchUtil util = null, SqlTransaction trans = null)
        {
            if (string.IsNullOrWhiteSpace(table))
            {
                throw new ArgumentNullException(nameof(table), "数据表不能为空");
            }
            if (kvs == null || kvs.Any(kv => kv.Key == "Id"))
            {
                throw new ArgumentNullException(nameof(kvs), "要更新的列不能为空,并且不能包含Id列");
            }

            util = util ?? new MySearchUtil();

            var cols = string.Join(",", kvs.Where(kv => kv.Key != "Id").Select(kv => $"{kv.Key}=@{kv.Key}"));

            var where = util.GetWhere();
            var param = util.GetParam();

            var sql = $"UPDATE {table} SET {cols} WHERE {where}";

            return(connection.Execute(sql, param, trans));
        }
예제 #6
0
 public static string GetUpdateColumns(KeyValuePairs kvs)
 {
     return(string.Join(",", kvs.Where(kv => kv.Key != "Id").Select(kv => $"{kv.Key}=@{kv.Key}")));
 }