コード例 #1
0
        public void InsertOrUpdate(string tablename, Guid storeId, IRawSqlSearchService service, DataTable table, List <string> primaryKey)
        {
            string chargeIdList = GetChargeNoList(table);
            var    whereClause  = string.Format(" WHERE ChargeNo IN({0})  and StoreId='{1}'", chargeIdList, storeId);
            var    existsData   = service.GetListWithSingleValue(tablename, whereClause, "ChargeNo", string.Empty, short.MaxValue)
                                  .Select(x => Convert.ToString(x).ToLower()).ToList();

            if (!table.Columns.Contains("ChargeNo"))
            {
                return;
            }
            List <DataRow> willRemoveIndexs = new List <DataRow>();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                var item     = table.Rows[i];
                var chargeNo = item["ChargeNo"].ToString().ToLower();
                if (existsData.Contains(chargeNo))
                {
                    willRemoveIndexs.Add(item);
                    continue;
                }
            }
            foreach (var row in willRemoveIndexs)
            {
                table.Rows.Remove(row);
            }
            if (table.Rows.Count > 0)
            {
                SyncBigDataServiceHelper.BatchInsert(service.DbProviderConfig.DbConnectionString, tablename, table, table.Rows.Count);
            }
        }
コード例 #2
0
        public void InsertOrUpdate(string tablename, Guid storeId, IRawSqlSearchService service, DataTable table, List <string> primaryKey)
        {
            primaryKey = primaryKey.Where(x => table.Columns.Contains(x)).ToList();
            if (primaryKey.Count == 0)
            {
                return;
            }

            List <DataRow> willRemoveIndexs = new List <DataRow>();

            if (primaryKey.Count == 1)
            {
                string currentPrimaryKey = primaryKey[0];
                if (string.IsNullOrEmpty(currentPrimaryKey))
                {
                    return;
                }
                var whereClause = BuildWhereCluase(table, storeId, currentPrimaryKey);
                if (string.IsNullOrEmpty(whereClause))
                {
                    return;
                }
                var existsData = service.GetListWithSingleValue(tablename, whereClause, currentPrimaryKey, string.Empty, short.MaxValue)
                                 .Select(x => Convert.ToString(x).ToLower()).ToList();
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    var item = table.Rows[i];
                    var currentPrimaryKeyValue = Convert.ToString(item[currentPrimaryKey]) ?? string.Empty;
                    if (existsData.Contains(currentPrimaryKeyValue.ToLower()))
                    {
                        willRemoveIndexs.Add(item);
                        whereClause = BuildWhereCluase(item, storeId, primaryKey);
                        if (string.IsNullOrEmpty(whereClause))
                        {
                            continue;
                        }
                        Update(service, tablename, item, primaryKey, whereClause);
                    }
                    continue;
                }
            }
            else
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    var item        = table.Rows[i];
                    var whereClause = BuildWhereCluase(item, storeId, primaryKey);
                    if (service.Exists(tablename, whereClause))
                    {
                        willRemoveIndexs.Add(item);
                        if (string.IsNullOrEmpty(whereClause))
                        {
                            continue;
                        }
                        Update(service, tablename, item, primaryKey, whereClause);
                    }
                }
            }
            foreach (var row in willRemoveIndexs)
            {
                table.Rows.Remove(row);
            }
            if (table.Rows.Count > 0)
            {
                SyncBigDataServiceHelper.BatchInsert(service.DbProviderConfig.DbConnectionString, tablename, table, table.Rows.Count);
            }
        }